Merged barry-b1-socket-arch-branch into MAIN.
[barry.git] / src / strnlen.h
blob94267acf0768b6a7889b2e0522b490e0f6922f88
1 ///
2 /// \file strnlen.h
3 /// Header for strnlen() call, for systems that don't have GNU.
4 ///
6 /*
7 Copyright (C) 2007-2008, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRY_STRNLEN_H__
23 #define __BARRY_STRNLEN_H__
25 #include "config.h"
26 #include <string.h>
28 // this is always defined by configure, if not, then the autoconf
29 // sources changed (likely in /usr/share/autoconf/autoconf/functions.m4)
30 // and configure.ac is no longer accurate
31 #ifndef HAVE_WORKING_STRNLEN
32 #error Configure.ac is not accurate. Read comments in strnlen.h.
33 #endif
35 // now, if defined and set to 0, then strnlen() either does not exist at all,
36 // or is broken (on AIX)
37 #if !HAVE_WORKING_STRNLEN
39 // so define our own version...
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
44 size_t barry_strnlen(const char *s, size_t maxlen);
46 #ifdef __cplusplus
48 #endif
50 // and override the system's name so we call our own
51 #define strnlen(s,l) barry_strnlen(s,l)
53 #endif // !HAVE_WORKING_STRNLEN
55 #endif // __BARRY_STRNLEN_H__