Skip to content

Commit a0683b8

Browse files
committedFeb 9, 2014
Define strlcpy on platforms that do not have it
1 parent 2a01050 commit a0683b8

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed
 

‎src/porting.h

+18-5
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
8888
#define strtoull(x, y, z) _strtoui64(x, y, z)
8989
#define strcasecmp(x, y) stricmp(x, y)
9090
#define strncasecmp(x, y, n) strnicmp(x, y, n)
91-
92-
// We can't simply alias strlcpy() to MSVC's strcpy_s(), since strcpy_s
93-
// by default raises an assertion error and aborts the program if the
94-
// buffer is too small. So we need to define our own.
95-
#define strlcpy(x, y, n) mystrlcpy(x, y, n)
9691
#else
9792
#define ALIGNOF(x) __alignof__(x)
9893
#endif
@@ -101,6 +96,24 @@ with this program; if not, write to the Free Software Foundation, Inc.,
10196
#define strtok_r(x, y, z) mystrtok_r(x, y, z)
10297
#endif
10398

99+
// strlcpy is missing from glibc. thanks a lot, drepper.
100+
// strlcpy is also missing from AIX and HP-UX because they aim to be weird.
101+
// We can't simply alias strlcpy to MSVC's strcpy_s, since strcpy_s by
102+
// default raises an assertion error and aborts the program if the buffer is
103+
// too small.
104+
#if defined(__FreeBSD__) || defined(__NetBSD__) || \
105+
defined(__OpenBSD__) || defined(__DragonFly__) || \
106+
defined(__APPLE__) || \
107+
defined(__sun) || defined(sun) || \
108+
defined(__QNX__) || defined(__QNXNTO__)
109+
#define HAVE_STRLCPY
110+
#endif
111+
112+
// So we need to define our own.
113+
#ifndef HAVE_STRLCPY
114+
#define strlcpy(d, s, n) mystrlcpy(d, s, n)
115+
#endif
116+
104117
#define PADDING(x, y) ((ALIGNOF(y) - ((uintptr_t)(x) & (ALIGNOF(y) - 1))) & (ALIGNOF(y) - 1))
105118

106119
namespace porting

‎src/script/common/c_content.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3030
#include "log.h"
3131
#include "tool.h"
3232
#include "serverobject.h"
33+
#include "porting.h"
3334
#include "mapgen.h"
3435
#include "json/json.h"
3536

0 commit comments

Comments
 (0)
Please sign in to comment.