Split pstring definitions into their own header.
[samba.git] / source3 / include / pstring.h
1 /* 
2    samba -- Unix SMB/Netbios implementation.
3    Safe standardized string types
4    
5    Copyright (C) Andrew Tridgell              1992-2000
6    Copyright (C) John H Terpstra              1996-2000
7    Copyright (C) Luke Kenneth Casson Leighton 1996-2000
8    Copyright (C) Paul Ashton                  1998-2000
9    Copyright (C) Martin Pool                  2002
10    
11    This program is free software; you can redistribute it and/or modify
12    it under the terms of the GNU General Public License as published by
13    the Free Software Foundation; either version 2 of the License, or
14    (at your option) any later version.
15    
16    This program is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19    GNU General Public License for more details.
20    
21    You should have received a copy of the GNU General Public License
22    along with this program; if not, write to the Free Software
23    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26 #ifndef _PSTRING
27
28 #define PSTRING_LEN 1024
29 #define FSTRING_LEN 256
30
31 #ifdef PSTRING_SANCTIFY
32
33 /* If you define this, pstring and fstring become distinguished types,
34  * so that it's harder to accidentally overflow them by for example
35  * passing an fstring on the lhs of pstrcpy.
36  *
37  * To pass them to non-pstring-aware functions, use PSTR and check
38  * that the function takes a const.  They should almost never be
39  * modified except by special calls.  In those unusual cases, use
40  * PSTR_MUTABLE.
41  *
42  * This is off by default so as not to produce too many warnings.  As
43  * the code is vetted it can become the default. */
44
45 typedef union { char pstring_contents[PSTRING_LEN]; } pstring[1];
46 typedef union { char fstring_contents[FSTRING_LEN]; } fstring[1];
47
48 #  define PSTR(p) ((const char *) ((p)->pstring_contents))
49 #  define FSTR(f) ((const char *) ((f)->fstring_contents))
50
51 /* Please use the const functions instead if possible. */
52 #  define PSTR_MUTABLE(p) (((p)->pstring_contents))
53 #  define FSTR_MUTABLE(f) (((f)->fstring_contents))
54
55 #else /* ndef PSTRING_SANCTIFY */
56
57 /* Old interface. */
58
59 typedef char pstring[PSTRING_LEN];
60 typedef char fstring[FSTRING_LEN];
61
62 #define PSTR(p) ((const char *) p)
63 #define FSTR(f) ((const char *) f)
64 #define PSTR_MUTABLE(p) (p)
65 #define FSTR_MUTABLE(f) (f)
66
67 #endif /* ndef PSTRING_SANCTIFY */
68
69 #define _PSTRING
70
71 #endif /* ndef _PSTRING */