ubase

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

commit 7f42fe77c38b4a4b3bf3aed810f51d0bd23f52dd
parent 06e895a67d6bf8ded3c084a6b26856cd856d8d3d
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun, 10 May 2015 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:
Mlibutil/eprintf.c | 10++++------
Mlibutil/strlcat.c | 11+++++++++++
Mlibutil/strlcpy.c | 11+++++++++++
Mutil.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 *);