strlcpy, strlcat: print program name, use for usage

... same as sbase libutil/strl{cat,cpy}.c. Fix comment in util.h
This commit is contained in:
Hiltjo Posthuma 2015-05-10 13:49:15 +02:00 committed by sin
parent 06e895a67d
commit 7f42fe77c3
4 changed files with 30 additions and 8 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}

6
util.h
View File

@ -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 *);