QDP++
qdp_strnlen.cc
Go to the documentation of this file.
1#include "qdp_config.h"
2
3#ifndef HAVE_STRNLEN
4#include "qdp_strnlen.h"
5#include <stdlib.h>
6
7extern "C" {
8
9 /* Drop in replacement for strnlen */
10 size_t strnlen(const char *s, size_t maxlen)
11 {
12 size_t pos;
13
14 /* What to do if s is NULL? Not defined in man page */
15 if (s == NULL) {
16 return 0;
17 }
18 else {
19
20 /* Scan through looking for a terminator */
21 for(pos=0; pos < maxlen; pos++) {
22 if( s[pos] == '\0' ) {
23
24 /* The length of the string including the terminator
25 is pos+1, but I am not supposed to count the terminator
26 according to the man page */
27
28 return pos;
29 }
30 }
31 /* I did not find a terminator so return maxlen */
32 return maxlen;
33 }
34 }
35};
36
37#endif
size_t strnlen(const char *s, size_t maxlen)