2 samba -- Unix SMB/Netbios implementation.
3 Safe standardized string types
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
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.
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.
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.
28 #define PSTRING_LEN 1024
29 #define FSTRING_LEN 256
31 #ifdef PSTRING_SANCTIFY
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.
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
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. */
45 typedef union { char pstring_contents[PSTRING_LEN]; } pstring[1];
46 typedef union { char fstring_contents[FSTRING_LEN]; } fstring[1];
48 # define PSTR(p) ((const char *) ((p)->pstring_contents))
49 # define FSTR(f) ((const char *) ((f)->fstring_contents))
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))
55 #else /* ndef PSTRING_SANCTIFY */
59 typedef char pstring[PSTRING_LEN];
60 typedef char fstring[FSTRING_LEN];
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)
67 #endif /* ndef PSTRING_SANCTIFY */
71 #endif /* ndef _PSTRING */