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:
parent
06e895a67d
commit
7f42fe77c3
@ -33,9 +33,8 @@ enprintf(int status, const char *fmt, ...)
|
||||
void
|
||||
venprintf(int status, const char *fmt, va_list ap)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
if (strncmp(fmt, "usage", strlen("usage")))
|
||||
fprintf(stderr, "%s: ", argv0);
|
||||
#endif
|
||||
|
||||
vfprintf(stderr, fmt, ap);
|
||||
|
||||
@ -52,9 +51,8 @@ weprintf(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
#ifdef DEBUG
|
||||
if (strncmp(fmt, "usage", strlen("usage")))
|
||||
fprintf(stderr, "%s: ", argv0);
|
||||
#endif
|
||||
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
6
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 *);
|
||||
|
Loading…
Reference in New Issue
Block a user