Introduction
Introduction Statistics Contact Development Disclaimer Help
strlcpy, strlcat: print program name, use for usage - ubase - suckless linux ba…
git clone git://git.suckless.org/ubase
Log
Files
Refs
README
LICENSE
---
commit 7f42fe77c38b4a4b3bf3aed810f51d0bd23f52dd
parent 06e895a67d6bf8ded3c084a6b26856cd856d8d3d
Author: Hiltjo Posthuma <[email protected]>
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:
M libutil/eprintf.c | 10 ++++------
M libutil/strlcat.c | 11 +++++++++++
M libutil/strlcpy.c | 11 +++++++++++
M 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 *);
You are viewing proxied material from suckless.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.