00001 /* 00002 * $Id: str.h 4993 2008-09-25 12:12:28Z henningw $ 00003 * 00004 * Copyright (C) 2001-2003 FhG Fokus 00005 * 00006 * This file is part of Kamailio, a free SIP server. 00007 * 00008 * Kamailio is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version 00012 * 00013 * Kamailio is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 */ 00022 00023 #ifndef str_h 00024 #define str_h 00025 00026 /** 00027 * \file 00028 * \brief Common data type for text variables. 00029 * - \ref DataTypeText 00030 */ 00031 00032 /*! 00033 * \page DataTypeText Common data type for text variables. 00034 * 00035 * This data type encapsulate a standard C char array. Its recommended to use 00036 * this type if you need variables holding text. Its caches the length of the 00037 * C string to avoid repetive calls to strlen, thus improving performance. 00038 * Its also safer to explicitly give the length to string operations of the core 00039 * or C libraries to prevent problems because of buffer overflows and missing 00040 * null-termination. 00041 * Important: The char array inside this type is not null-terminated. So if you 00042 * need to work with external functions that rely on this termination you must 00043 * add a zero at the end by yourself. Keep in mind that the length of the char 00044 * array is normally not large enough to store this additional null-termination. 00045 * So you must copy the char array to a new buffer that is (len + 1) big, 00046 * otherwise memory corruption and undefinied behavour will occur. 00047 * Most libraries provides also functions that can work with an explicit given 00048 * length, thus avoiding the need for this copy operation. 00049 */ 00050 00051 00052 struct _str{ 00053 char* s; /**< string as char array */ 00054 int len; /**< string length, not including null-termination */ 00055 }; 00056 00057 typedef struct _str str; 00058 00059 00060 #endif
1.5.6