diff options
Diffstat (limited to 'bin/pax/gen_subs.c')
-rw-r--r-- | bin/pax/gen_subs.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/bin/pax/gen_subs.c b/bin/pax/gen_subs.c index 00ae4b674af..4acd1b28b7a 100644 --- a/bin/pax/gen_subs.c +++ b/bin/pax/gen_subs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gen_subs.c,v 1.17 2003/06/13 17:51:14 millert Exp $ */ +/* $OpenBSD: gen_subs.c,v 1.18 2005/04/28 06:58:07 otto Exp $ */ /* $NetBSD: gen_subs.c,v 1.5 1995/03/21 09:07:26 cgd Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static const char sccsid[] = "@(#)gen_subs.c 8.1 (Berkeley) 5/31/93"; #else -static const char rcsid[] = "$OpenBSD: gen_subs.c,v 1.17 2003/06/13 17:51:14 millert Exp $"; +static const char rcsid[] = "$OpenBSD: gen_subs.c,v 1.18 2005/04/28 06:58:07 otto Exp $"; #endif #endif /* not lint */ @@ -408,3 +408,25 @@ uqd_asc(u_quad_t val, char *str, int len, int base) return(0); } #endif + +/* + * Copy at max min(bufz, fieldsz) chars from field to buf, stopping + * at the first NUL char. NUL terminate buf if there is room left. + */ +size_t +fieldcpy(char *buf, size_t bufsz, const char *field, size_t fieldsz) +{ + char *p = buf; + const char *q = field; + size_t i = 0; + + if (fieldsz > bufsz) + fieldsz = bufsz; + while (i < fieldsz && *q != '\0') { + *p++ = *q++; + i++; + } + if (i < bufsz) + *p = '\0'; + return(i); +} |