Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Define strlcpy on platforms that do not have it
  • Loading branch information
kwolekr committed Feb 9, 2014
1 parent 2a01050 commit a0683b8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/porting.h
Expand Up @@ -88,11 +88,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define strtoull(x, y, z) _strtoui64(x, y, z)
#define strcasecmp(x, y) stricmp(x, y)
#define strncasecmp(x, y, n) strnicmp(x, y, n)

// We can't simply alias strlcpy() to MSVC's strcpy_s(), since strcpy_s
// by default raises an assertion error and aborts the program if the
// buffer is too small. So we need to define our own.
#define strlcpy(x, y, n) mystrlcpy(x, y, n)
#else
#define ALIGNOF(x) __alignof__(x)
#endif
Expand All @@ -101,6 +96,24 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define strtok_r(x, y, z) mystrtok_r(x, y, z)
#endif

// strlcpy is missing from glibc. thanks a lot, drepper.
// strlcpy is also missing from AIX and HP-UX because they aim to be weird.
// We can't simply alias strlcpy to MSVC's strcpy_s, since strcpy_s by
// default raises an assertion error and aborts the program if the buffer is
// too small.
#if defined(__FreeBSD__) || defined(__NetBSD__) || \
defined(__OpenBSD__) || defined(__DragonFly__) || \
defined(__APPLE__) || \
defined(__sun) || defined(sun) || \
defined(__QNX__) || defined(__QNXNTO__)
#define HAVE_STRLCPY
#endif

// So we need to define our own.
#ifndef HAVE_STRLCPY
#define strlcpy(d, s, n) mystrlcpy(d, s, n)
#endif

#define PADDING(x, y) ((ALIGNOF(y) - ((uintptr_t)(x) & (ALIGNOF(y) - 1))) & (ALIGNOF(y) - 1))

namespace porting
Expand Down
1 change: 1 addition & 0 deletions src/script/common/c_content.cpp
Expand Up @@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "log.h"
#include "tool.h"
#include "serverobject.h"
#include "porting.h"
#include "mapgen.h"
#include "json/json.h"

Expand Down

0 comments on commit a0683b8

Please sign in to comment.