forked from github/server
new all-in-one strlcpy and wrptr function
This commit is contained in:
parent
dcececf4fa
commit
1806030baa
|
@ -6,6 +6,7 @@
|
|||
#include <stdarg.h>
|
||||
|
||||
#include "bsdstring.h"
|
||||
#include "log.h"
|
||||
|
||||
int wrptr(char **ptr, size_t * size, int result)
|
||||
{
|
||||
|
@ -61,6 +62,17 @@ 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)
|
||||
{
|
||||
size_t bytes = strlcpy(dst, src, *siz);
|
||||
char * buf = dst;
|
||||
if (wrptr(&buf, siz, bytes) != 0)
|
||||
log_warning("%s: static buffer too small in %s:%d\n", err, file, line);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifndef HAVE_STRLCAT
|
||||
#define HAVE_STRLCAT
|
||||
size_t strlcat(char *dst, const char *src, size_t siz)
|
||||
|
|
|
@ -2,22 +2,24 @@
|
|||
#define UTIL_BSDSTRING_H
|
||||
|
||||
#include <stddef.h>
|
||||
extern int wrptr(char **ptr, size_t * size, int bytes);
|
||||
int wrptr(char **ptr, size_t * size, int bytes);
|
||||
|
||||
#ifndef HAVE_STRLCPY
|
||||
extern size_t strlcpy(char *dst, const char *src, size_t siz);
|
||||
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);
|
||||
|
||||
#ifndef HAVE_STRLCAT
|
||||
extern size_t strlcat(char *dst, const char *src, size_t siz);
|
||||
size_t strlcat(char *dst, const char *src, size_t siz);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SLPRINTF
|
||||
extern size_t slprintf(char * dst, size_t size, const char * format, ...);
|
||||
size_t slprintf(char * dst, size_t size, const char * format, ...);
|
||||
#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() 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 STRLCPY(dst, src, siz, err) strlcpy_w((dst), (src), (siz), (err), __FILE__, __LINE__)
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue