strnlen.h

Go to the documentation of this file.
00001 ///
00002 /// \file       strnlen.h
00003 ///             Header for strnlen() call, for systems that don't have GNU.
00004 ///
00005 
00006 /*
00007     Copyright (C) 2007-2012, Net Direct Inc. (http://www.netdirect.ca/)
00008 
00009     This program is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     This program is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00017 
00018     See the GNU General Public License in the COPYING file at the
00019     root directory of this project for more details.
00020 */
00021 
00022 #ifndef __BARRY_STRNLEN_H__
00023 #define __BARRY_STRNLEN_H__
00024 
00025 #include "config.h"             // strnlen.h is not installed, so this is safe
00026 #include <string.h>
00027 
00028 #ifdef WIN32
00029 #define HAVE_WORKING_STRNLEN 1
00030 #endif
00031 
00032 // this is always defined by configure, if not, then the autoconf
00033 // sources changed (likely in /usr/share/autoconf/autoconf/functions.m4)
00034 // and configure.ac is no longer accurate
00035 #ifndef HAVE_WORKING_STRNLEN
00036 #error Configure.ac is not accurate. Read comments in strnlen.h.
00037 #endif
00038 
00039 // now, if defined and set to 0, then strnlen() either does not exist at all,
00040 // or is broken (on AIX)
00041 #if !HAVE_WORKING_STRNLEN
00042 
00043 // so define our own version...
00044 #ifdef __cplusplus
00045 extern "C" {
00046 #endif
00047 
00048 size_t barry_strnlen(const char *s, size_t maxlen);
00049 
00050 #ifdef __cplusplus
00051 }
00052 #endif
00053 
00054 // and override the system's name so we call our own
00055 #define strnlen(s,l) barry_strnlen(s,l)
00056 
00057 #endif  // !HAVE_WORKING_STRNLEN
00058 
00059 #endif  // __BARRY_STRNLEN_H__
00060