ubase

suckless linux base utils
git clone git://git.2f30.org/ubase.git
Log | Files | Refs | README | LICENSE

commit 3ffc354099eccfede1ef7b5371a61fe0c1ce51e1
parent 9a126ec1f3f445e93ac0810272f869dae0dfeeaf
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun May 10 13:49:15 +0200

strlcpy, strlcat: print program name, use for usage

... same as sbase libutil/strl{cat,cpy}.c. Fix comment in util.h

Diffstat:
libutil/eprintf.c | 10++++------
libutil/strlcat.c | 11+++++++++++
libutil/strlcpy.c | 11+++++++++++
util.h | 6++++--
4 files changed, 30 insertions(+), 8 deletions(-)
diff --git a/libutil/eprintf.c b/libutil/eprintf.c @@ -33,9 +33,8 @@ enprintf(int status, const char *fmt, ...) void venprintf(int status, const char *fmt, va_list ap) { -#ifdef DEBUG - fprintf(stderr, "%s: ", argv0); -#endif + if (strncmp(fmt, "usage", strlen("usage"))) + fprintf(stderr, "%s: ", argv0); vfprintf(stderr, fmt, ap); @@ -52,9 +51,8 @@ weprintf(const char *fmt, ...) { va_list ap; -#ifdef DEBUG - fprintf(stderr, "%s: ", argv0); -#endif + if (strncmp(fmt, "usage", strlen("usage"))) + fprintf(stderr, "%s: ", argv0); va_start(ap, fmt); vfprintf(stderr, fmt, ap); diff --git a/libutil/strlcat.c b/libutil/strlcat.c @@ -50,3 +50,14 @@ strlcat(char *dst, const char *src, size_t siz) *d = '\0'; return(dlen + (s - src)); /* count does not include NUL */ } + +size_t +estrlcat(char *dst, const char *src, size_t siz) +{ + size_t ret; + + if ((ret = strlcat(dst, src, siz)) >= siz) + eprintf("strlcat: input string too long\n"); + + return ret; +} diff --git a/libutil/strlcpy.c b/libutil/strlcpy.c @@ -46,3 +46,14 @@ strlcpy(char *dst, const char *src, size_t siz) } return(s - src - 1); /* count does not include NUL */ } + +size_t +estrlcpy(char *dst, const char *src, size_t siz) +{ + size_t ret; + + if ((ret = strlcpy(dst, src, siz)) >= siz) + eprintf("strlcpy: input string too long\n"); + + return ret; +} diff --git a/util.h b/util.h @@ -40,13 +40,15 @@ void putword(const char *); /* recurse.c */ void recurse(const char *, void (*)(const char *)); -/* strlcpy.c */ +/* strlcat.c */ #undef strlcat size_t strlcat(char *, const char *, size_t); +size_t estrlcat(char *, const char *, size_t); -/* strlcat.c */ +/* strlcpy.c */ #undef strlcpy size_t strlcpy(char *, const char *, size_t); +size_t estrlcpy(char *, const char *, size_t); /* tty.c */ void devtotty(int, int *, int *);