[hackers] [ubase] strlcpy, strlcat: print program name, use for usage || Hiltjo Posthuma
commit 7f42fe77c38b4a4b3bf3aed810f51d0bd23f52dd
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Sun May 10 13:49:15 2015 +0200
strlcpy, strlcat: print program name, use for usage
... same as sbase libutil/strl{cat,cpy}.c. Fix comment in util.h
diff --git a/libutil/eprintf.c b/libutil/eprintf.c
index 407c502..4d8f726 100644
--- a/libutil/eprintf.c
+++ b/libutil/eprintf.c
_AT_@ -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);
_AT_@ -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
index 9e2d251..bf263b8 100644
--- a/libutil/strlcat.c
+++ b/libutil/strlcat.c
_AT_@ -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
index 388b426..44b618a 100644
--- a/libutil/strlcpy.c
+++ b/libutil/strlcpy.c
_AT_@ -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
index d9b5f1a..7b832e7 100644
--- a/util.h
+++ b/util.h
_AT_@ -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 *);
Received on Sun May 10 2015 - 14:41:29 CEST
This archive was generated by hypermail 2.3.0
: Sun May 10 2015 - 14:48:10 CEST