forked from github/server
fix mac build
This commit is contained in:
parent
93613b99af
commit
a74daa2474
|
@ -3,6 +3,7 @@ project(util C)
|
||||||
SET(_TEST_FILES
|
SET(_TEST_FILES
|
||||||
attrib.test.c
|
attrib.test.c
|
||||||
base36.test.c
|
base36.test.c
|
||||||
|
bsdstring.test.c
|
||||||
# crmessage.test.c
|
# crmessage.test.c
|
||||||
# dice.test.c
|
# dice.test.c
|
||||||
# event.test.c
|
# event.test.c
|
||||||
|
@ -21,7 +22,6 @@ password.test.c
|
||||||
# resolve.test.c
|
# resolve.test.c
|
||||||
rng.test.c
|
rng.test.c
|
||||||
strings.test.c
|
strings.test.c
|
||||||
bsdstring.test.c
|
|
||||||
functions.test.c
|
functions.test.c
|
||||||
log.test.c
|
log.test.c
|
||||||
# translation.test.c
|
# translation.test.c
|
||||||
|
@ -60,11 +60,6 @@ variant.c
|
||||||
xml.c
|
xml.c
|
||||||
)
|
)
|
||||||
|
|
||||||
IF(HAVE_BSDSTRING)
|
|
||||||
SET (_TEST_FILES ${_TEST_FILES} bsdstring.test.c)
|
|
||||||
SET (_FILES ${_FILES} bsdstring.c)
|
|
||||||
ENDIF(HAVE_BSDSTRING)
|
|
||||||
|
|
||||||
FOREACH(_FILE ${_FILES})
|
FOREACH(_FILE ${_FILES})
|
||||||
LIST(APPEND _SOURCES ${PROJECT_NAME}/${_FILE})
|
LIST(APPEND _SOURCES ${PROJECT_NAME}/${_FILE})
|
||||||
ENDFOREACH(_FILE)
|
ENDFOREACH(_FILE)
|
||||||
|
|
|
@ -33,6 +33,7 @@ int wrptr(char **ptr, size_t * size, int result)
|
||||||
return ERANGE;
|
return ERANGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef HAVE_BSDSTRING
|
||||||
size_t strlcpy(char *dst, const char *src, size_t siz)
|
size_t strlcpy(char *dst, const char *src, size_t siz)
|
||||||
{ /* copied from OpenBSD source code */
|
{ /* copied from OpenBSD source code */
|
||||||
register char *d = dst;
|
register char *d = dst;
|
||||||
|
@ -58,21 +59,6 @@ size_t strlcpy(char *dst, const char *src, size_t siz)
|
||||||
return (s - src - 1); /* count does not include NUL */
|
return (s - src - 1); /* count does not include NUL */
|
||||||
}
|
}
|
||||||
|
|
||||||
char * strlcpy_w(char *dst, const char *src, size_t *siz, const char *err, const char *file, int line)
|
|
||||||
{
|
|
||||||
size_t bytes = strlcpy(dst, src, *siz);
|
|
||||||
char * buf = dst;
|
|
||||||
assert(bytes <= INT_MAX);
|
|
||||||
if (wrptr(&buf, siz, (int)bytes) != 0) {
|
|
||||||
if (err) {
|
|
||||||
log_warning("%s: static buffer too small in %s:%d\n", err, file, line);
|
|
||||||
} else {
|
|
||||||
log_warning("static buffer too small in %s:%d\n", file, line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t strlcat(char *dst, const char *src, size_t siz)
|
size_t strlcat(char *dst, const char *src, size_t siz)
|
||||||
{
|
{
|
||||||
register char *d = dst;
|
register char *d = dst;
|
||||||
|
@ -99,3 +85,19 @@ size_t strlcat(char *dst, const char *src, size_t siz)
|
||||||
|
|
||||||
return (dlen + (s - src)); /* count does not include NUL */
|
return (dlen + (s - src)); /* count does not include NUL */
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
char * strlcpy_w(char *dst, const char *src, size_t *siz, const char *err, const char *file, int line)
|
||||||
|
{
|
||||||
|
size_t bytes = strlcpy(dst, src, *siz);
|
||||||
|
char * buf = dst;
|
||||||
|
assert(bytes <= INT_MAX);
|
||||||
|
if (wrptr(&buf, siz, (int)bytes) != 0) {
|
||||||
|
if (err) {
|
||||||
|
log_warning("%s: static buffer too small in %s:%d\n", err, file, line);
|
||||||
|
} else {
|
||||||
|
log_warning("static buffer too small in %s:%d\n", file, line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
|
@ -2,27 +2,17 @@
|
||||||
#define UTIL_BSDSTRING_H
|
#define UTIL_BSDSTRING_H
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
int wrptr(char **ptr, size_t * size, int bytes);
|
|
||||||
|
|
||||||
#undef HAVE_STRLCAT
|
#ifndef HAVE_BSDSTRING
|
||||||
#undef HAVE_STRLCPY
|
size_t strlcpy(char *dst, const char *src, size_t siz);
|
||||||
#undef HAVE_SLPRINTF
|
size_t strlcat(char *dst, const char *src, size_t siz);
|
||||||
#ifdef HAVE_BSDSTRING
|
|
||||||
#define HAVE_STRLCAT
|
|
||||||
#define HAVE_STRLCPY
|
|
||||||
#else
|
#else
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_STRLCPY
|
int wrptr(char **ptr, size_t * size, int bytes);
|
||||||
size_t strlcpy(char *dst, const char *src, size_t siz);
|
|
||||||
#endif
|
|
||||||
char * strlcpy_w(char *dst, const char *src, size_t *siz, const char *err, const char *file, int line);
|
char * strlcpy_w(char *dst, const char *src, size_t *siz, const char *err, const char *file, int line);
|
||||||
|
|
||||||
#ifndef HAVE_STRLCAT
|
|
||||||
size_t strlcat(char *dst, const char *src, size_t siz);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define WARN_STATIC_BUFFER_EX(foo) log_warning("%s: static buffer too small in %s:%d\n", (foo), __FILE__, __LINE__)
|
#define WARN_STATIC_BUFFER_EX(foo) log_warning("%s: static buffer too small in %s:%d\n", (foo), __FILE__, __LINE__)
|
||||||
#define WARN_STATIC_BUFFER() log_warning("static buffer too small in %s:%d\n", __FILE__, __LINE__)
|
#define WARN_STATIC_BUFFER() log_warning("static buffer too small in %s:%d\n", __FILE__, __LINE__)
|
||||||
#define INFO_STATIC_BUFFER() log_info("static buffer too small in %s:%d\n", __FILE__, __LINE__)
|
#define INFO_STATIC_BUFFER() log_info("static buffer too small in %s:%d\n", __FILE__, __LINE__)
|
||||||
|
|
Loading…
Reference in New Issue