diff options
author | Elliott Hughes <enh@google.com> | 2016-01-15 16:30:18 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2016-01-15 16:30:18 -0800 |
commit | 506c6deff726c8c052ff5abb0cef57e63707bd1c (patch) | |
tree | 42a751602c065bdb8c76ef53dffaca585934614a /libc/upstream-openbsd | |
parent | 299798fe02cd43c21e62352f11d7be30d85e0f96 (diff) | |
download | android_bionic-506c6deff726c8c052ff5abb0cef57e63707bd1c.tar.gz android_bionic-506c6deff726c8c052ff5abb0cef57e63707bd1c.tar.bz2 android_bionic-506c6deff726c8c052ff5abb0cef57e63707bd1c.zip |
Sync with upstream OpenBSD.
Also some minor build cleanup.
Change-Id: Ibd20602d7ea45685f0c47fceb00ffd6c7ae35954
Diffstat (limited to 'libc/upstream-openbsd')
31 files changed, 227 insertions, 242 deletions
diff --git a/libc/upstream-openbsd/android/include/openbsd-compat.h b/libc/upstream-openbsd/android/include/openbsd-compat.h index b07f55da0..caea45a93 100644 --- a/libc/upstream-openbsd/android/include/openbsd-compat.h +++ b/libc/upstream-openbsd/android/include/openbsd-compat.h @@ -32,8 +32,9 @@ #define _warn warn #define _warnx warnx -/* Ignore all __weak_alias in OpenBSD. */ -#define __weak_alias(alias,sym) +/* Ignore all DEF_STRONG/DEF_WEAK in OpenBSD. */ +#define DEF_STRONG(sym) +#define DEF_WEAK(sym) /* Ignore all __warn_references in OpenBSD. */ #define __warn_references(sym,msg) diff --git a/libc/upstream-openbsd/lib/libc/gen/err.c b/libc/upstream-openbsd/lib/libc/gen/err.c index e7ec29de4..15e1b97c4 100644 --- a/libc/upstream-openbsd/lib/libc/gen/err.c +++ b/libc/upstream-openbsd/lib/libc/gen/err.c @@ -1,4 +1,4 @@ -/* $OpenBSD: err.c,v 1.11 2012/12/05 23:19:59 deraadt Exp $ */ +/* $OpenBSD: err.c,v 1.12 2015/08/31 02:53:57 guenther Exp $ */ /*- * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. @@ -31,17 +31,13 @@ #include <err.h> #include <stdarg.h> -/* PRINTFLIKE2 */ __dead void -_err(int eval, const char *fmt, ...) +err(int eval, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - _verr(eval, fmt, ap); + verr(eval, fmt, ap); va_end(ap); } - -/* PRINTFLIKE2 */ -__weak_alias(err, _err); - +DEF_WEAK(err); diff --git a/libc/upstream-openbsd/lib/libc/gen/errx.c b/libc/upstream-openbsd/lib/libc/gen/errx.c index d213435db..e6b5d2389 100644 --- a/libc/upstream-openbsd/lib/libc/gen/errx.c +++ b/libc/upstream-openbsd/lib/libc/gen/errx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: errx.c,v 1.10 2012/12/05 23:19:59 deraadt Exp $ */ +/* $OpenBSD: errx.c,v 1.11 2015/08/31 02:53:57 guenther Exp $ */ /*- * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. @@ -31,17 +31,13 @@ #include <err.h> #include <stdarg.h> -/* PRINTFLIKE2 */ __dead void -_errx(int eval, const char *fmt, ...) +errx(int eval, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - _verrx(eval, fmt, ap); + verrx(eval, fmt, ap); va_end(ap); } - -/* PRINTFLIKE2 */ -__weak_alias(errx, _errx); - +DEF_WEAK(errx); diff --git a/libc/upstream-openbsd/lib/libc/gen/time.c b/libc/upstream-openbsd/lib/libc/gen/time.c index 3a57500d4..6fcf1cde2 100644 --- a/libc/upstream-openbsd/lib/libc/gen/time.c +++ b/libc/upstream-openbsd/lib/libc/gen/time.c @@ -1,4 +1,4 @@ -/* $OpenBSD: time.c,v 1.5 2005/08/08 08:05:34 espie Exp $ */ +/* $OpenBSD: time.c,v 1.7 2015/10/29 03:58:55 mmcc Exp $ */ /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -28,17 +28,18 @@ * SUCH DAMAGE. */ -#include <sys/types.h> #include <sys/time.h> +#include <time.h> time_t time(time_t *t) { struct timeval tt; - if (gettimeofday(&tt, (struct timezone *)0) < 0) + if (gettimeofday(&tt, NULL) < 0) return (-1); if (t) *t = (time_t)tt.tv_sec; return (tt.tv_sec); } +DEF_STRONG(time); diff --git a/libc/upstream-openbsd/lib/libc/gen/verr.c b/libc/upstream-openbsd/lib/libc/gen/verr.c index dcd8edcd0..8f4722b9e 100644 --- a/libc/upstream-openbsd/lib/libc/gen/verr.c +++ b/libc/upstream-openbsd/lib/libc/gen/verr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: verr.c,v 1.9 2012/12/05 23:20:00 deraadt Exp $ */ +/* $OpenBSD: verr.c,v 1.10 2015/08/31 02:53:57 guenther Exp $ */ /*- * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. @@ -38,7 +38,7 @@ extern char *__progname; /* Program name, from crt0. */ __dead void -_verr(int eval, const char *fmt, va_list ap) +verr(int eval, const char *fmt, va_list ap) { int sverrno; @@ -51,6 +51,4 @@ _verr(int eval, const char *fmt, va_list ap) (void)fprintf(stderr, "%s\n", strerror(sverrno)); exit(eval); } - -__weak_alias(verr, _verr); - +DEF_WEAK(verr); diff --git a/libc/upstream-openbsd/lib/libc/gen/verrx.c b/libc/upstream-openbsd/lib/libc/gen/verrx.c index 60da062f5..f0186b607 100644 --- a/libc/upstream-openbsd/lib/libc/gen/verrx.c +++ b/libc/upstream-openbsd/lib/libc/gen/verrx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: verrx.c,v 1.9 2012/12/05 23:20:00 deraadt Exp $ */ +/* $OpenBSD: verrx.c,v 1.10 2015/08/31 02:53:57 guenther Exp $ */ /*- * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. @@ -36,7 +36,7 @@ extern char *__progname; /* Program name, from crt0. */ __dead void -_verrx(int eval, const char *fmt, va_list ap) +verrx(int eval, const char *fmt, va_list ap) { (void)fprintf(stderr, "%s: ", __progname); if (fmt != NULL) @@ -44,6 +44,4 @@ _verrx(int eval, const char *fmt, va_list ap) (void)fprintf(stderr, "\n"); exit(eval); } - -__weak_alias(verrx, _verrx); - +DEF_WEAK(verrx); diff --git a/libc/upstream-openbsd/lib/libc/gen/vwarn.c b/libc/upstream-openbsd/lib/libc/gen/vwarn.c index 26b60f336..44d8be48e 100644 --- a/libc/upstream-openbsd/lib/libc/gen/vwarn.c +++ b/libc/upstream-openbsd/lib/libc/gen/vwarn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vwarn.c,v 1.9 2012/12/05 23:20:00 deraadt Exp $ */ +/* $OpenBSD: vwarn.c,v 1.10 2015/08/31 02:53:57 guenther Exp $ */ /*- * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. @@ -37,7 +37,7 @@ extern char *__progname; /* Program name, from crt0. */ void -_vwarn(const char *fmt, va_list ap) +vwarn(const char *fmt, va_list ap) { int sverrno; @@ -49,6 +49,4 @@ _vwarn(const char *fmt, va_list ap) } (void)fprintf(stderr, "%s\n", strerror(sverrno)); } - -__weak_alias(vwarn, _vwarn); - +DEF_WEAK(vwarn); diff --git a/libc/upstream-openbsd/lib/libc/gen/vwarnx.c b/libc/upstream-openbsd/lib/libc/gen/vwarnx.c index e6b1957d4..67d8f5b57 100644 --- a/libc/upstream-openbsd/lib/libc/gen/vwarnx.c +++ b/libc/upstream-openbsd/lib/libc/gen/vwarnx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vwarnx.c,v 1.9 2012/12/05 23:20:00 deraadt Exp $ */ +/* $OpenBSD: vwarnx.c,v 1.10 2015/08/31 02:53:57 guenther Exp $ */ /*- * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. @@ -35,13 +35,11 @@ extern char *__progname; /* Program name, from crt0. */ void -_vwarnx(const char *fmt, va_list ap) +vwarnx(const char *fmt, va_list ap) { (void)fprintf(stderr, "%s: ", __progname); if (fmt != NULL) (void)vfprintf(stderr, fmt, ap); (void)fprintf(stderr, "\n"); } - -__weak_alias(vwarnx, _vwarnx); - +DEF_WEAK(vwarnx); diff --git a/libc/upstream-openbsd/lib/libc/gen/warn.c b/libc/upstream-openbsd/lib/libc/gen/warn.c index c1b47a65f..6784cf666 100644 --- a/libc/upstream-openbsd/lib/libc/gen/warn.c +++ b/libc/upstream-openbsd/lib/libc/gen/warn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: warn.c,v 1.10 2012/12/05 23:20:00 deraadt Exp $ */ +/* $OpenBSD: warn.c,v 1.11 2015/08/31 02:53:57 guenther Exp $ */ /*- * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. @@ -31,17 +31,13 @@ #include <err.h> #include <stdarg.h> -/* PRINTFLIKE1 */ void -_warn(const char *fmt, ...) +warn(const char *fmt, ...) { va_list ap; va_start(ap, fmt); - _vwarn(fmt, ap); + vwarn(fmt, ap); va_end(ap); } - -/* PRINTFLIKE1 */ -__weak_alias(warn, _warn); - +DEF_WEAK(warn); diff --git a/libc/upstream-openbsd/lib/libc/gen/warnx.c b/libc/upstream-openbsd/lib/libc/gen/warnx.c index af2ab669c..723bc0db8 100644 --- a/libc/upstream-openbsd/lib/libc/gen/warnx.c +++ b/libc/upstream-openbsd/lib/libc/gen/warnx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: warnx.c,v 1.9 2012/12/05 23:20:00 deraadt Exp $ */ +/* $OpenBSD: warnx.c,v 1.10 2015/08/31 02:53:57 guenther Exp $ */ /*- * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. @@ -31,17 +31,13 @@ #include <err.h> #include <stdarg.h> -/* PRINTFLIKE1 */ void -_warnx(const char *fmt, ...) +warnx(const char *fmt, ...) { va_list ap; va_start(ap, fmt); - _vwarnx(fmt, ap); + vwarnx(fmt, ap); va_end(ap); } - -/* PRINTFLIKE1 */ -__weak_alias(warnx, _warnx); - +DEF_WEAK(warnx); diff --git a/libc/upstream-openbsd/lib/libc/net/res_random.c b/libc/upstream-openbsd/lib/libc/net/res_random.c index f28692f7c..72b9c41a2 100644 --- a/libc/upstream-openbsd/lib/libc/net/res_random.c +++ b/libc/upstream-openbsd/lib/libc/net/res_random.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_random.c,v 1.21 2014/07/20 04:22:34 guenther Exp $ */ +/* $OpenBSD: res_random.c,v 1.23 2015/10/05 02:57:16 guenther Exp $ */ /* * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> @@ -101,6 +101,7 @@ static u_int16_t ru_counter = 0; static u_int16_t ru_msb = 0; static struct prf_ctx *ru_prf = NULL; static time_t ru_reseed; +static pid_t ru_pid; static u_int16_t pmod(u_int16_t, u_int16_t, u_int16_t); static void res_initid(void); @@ -224,18 +225,22 @@ res_initid(void) } u_int -res_randomid(void) +__res_randomid(void) { struct timespec ts; + pid_t pid; u_int r; _THREAD_PRIVATE_MUTEX(random); clock_gettime(CLOCK_MONOTONIC, &ts); + pid = getpid(); _THREAD_PRIVATE_MUTEX_LOCK(random); - if (ru_counter >= RU_MAX || ts.tv_sec > ru_reseed) + if (ru_counter >= RU_MAX || ts.tv_sec > ru_reseed || pid != ru_pid) { res_initid(); + ru_pid = pid; + } /* Linear Congruential Generator */ ru_x = (ru_a * ru_x + ru_b) % RU_M; @@ -247,6 +252,7 @@ res_randomid(void) return (r); } +DEF_STRONG(__res_randomid); #if 0 int diff --git a/libc/upstream-openbsd/lib/libc/stdio/asprintf.c b/libc/upstream-openbsd/lib/libc/stdio/asprintf.c index 5424c90dc..482367759 100644 --- a/libc/upstream-openbsd/lib/libc/stdio/asprintf.c +++ b/libc/upstream-openbsd/lib/libc/stdio/asprintf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: asprintf.c,v 1.19 2011/05/30 18:48:33 martynas Exp $ */ +/* $OpenBSD: asprintf.c,v 1.22 2015/12/28 22:08:18 mmcc Exp $ */ /* * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com> @@ -23,7 +23,6 @@ #include <stdarg.h> #include "local.h" -/* PRINTFLIKE2 */ int asprintf(char **str, const char *fmt, ...) { @@ -36,7 +35,7 @@ asprintf(char **str, const char *fmt, ...) _FILEEXT_SETUP(&f, &fext); f._file = -1; f._flags = __SWR | __SSTR | __SALC; - f._bf._base = f._p = (unsigned char *)malloc(128); + f._bf._base = f._p = malloc(128); if (f._bf._base == NULL) goto err; f._bf._size = f._w = 127; /* Leave room for the NUL */ @@ -53,11 +52,10 @@ asprintf(char **str, const char *fmt, ...) return (ret); err: - if (f._bf._base) { - free(f._bf._base); - f._bf._base = NULL; - } + free(f._bf._base); + f._bf._base = NULL; *str = NULL; errno = ENOMEM; return (-1); } +DEF_WEAK(asprintf); diff --git a/libc/upstream-openbsd/lib/libc/stdio/fgetwc.c b/libc/upstream-openbsd/lib/libc/stdio/fgetwc.c index c16ffaf29..2e69191f1 100644 --- a/libc/upstream-openbsd/lib/libc/stdio/fgetwc.c +++ b/libc/upstream-openbsd/lib/libc/stdio/fgetwc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fgetwc.c,v 1.4 2009/11/09 00:18:27 kurt Exp $ */ +/* $OpenBSD: fgetwc.c,v 1.6 2015/12/24 19:55:39 schwarze Exp $ */ /* $NetBSD: fgetwc.c,v 1.3 2003/03/07 07:11:36 tshiozak Exp $ */ /*- @@ -69,7 +69,7 @@ __fgetwc_unlock(FILE *fp) c = ch; size = mbrtowc(&wc, &c, 1, st); if (size == (size_t)-1) { - errno = EILSEQ; + fp->_flags |= __SERR; return WEOF; } } while (size == (size_t)-2); @@ -88,3 +88,4 @@ fgetwc(FILE *fp) return (r); } +DEF_STRONG(fgetwc); diff --git a/libc/upstream-openbsd/lib/libc/stdio/fgetws.c b/libc/upstream-openbsd/lib/libc/stdio/fgetws.c index e8cd24900..d02ccd58c 100644 --- a/libc/upstream-openbsd/lib/libc/stdio/fgetws.c +++ b/libc/upstream-openbsd/lib/libc/stdio/fgetws.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fgetws.c,v 1.6 2009/11/09 00:18:27 kurt Exp $ */ +/* $OpenBSD: fgetws.c,v 1.8 2016/01/04 16:14:19 schwarze Exp $ */ /* $NetBSD: fgetws.c,v 1.1 2003/03/07 07:11:37 tshiozak Exp $ */ /*- @@ -52,9 +52,9 @@ fgetws(wchar_t * __restrict ws, int n, FILE * __restrict fp) wsp = ws; while (n-- > 1) { - if ((wc = __fgetwc_unlock(fp)) == WEOF && errno == EILSEQ) { + if ((wc = __fgetwc_unlock(fp)) == WEOF && + ferror(fp) && errno == EILSEQ) goto error; - } if (wc == WEOF) { if (wsp == ws) { /* EOF/error, no characters read yet. */ @@ -77,3 +77,4 @@ error: FUNLOCKFILE(fp); return (NULL); } +DEF_STRONG(fgetws); diff --git a/libc/upstream-openbsd/lib/libc/stdio/fputwc.c b/libc/upstream-openbsd/lib/libc/stdio/fputwc.c index 9db70d061..829c22c48 100644 --- a/libc/upstream-openbsd/lib/libc/stdio/fputwc.c +++ b/libc/upstream-openbsd/lib/libc/stdio/fputwc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fputwc.c,v 1.4 2009/11/09 00:18:27 kurt Exp $ */ +/* $OpenBSD: fputwc.c,v 1.6 2015/10/01 02:32:07 guenther Exp $ */ /* $NetBSD: fputwc.c,v 1.3 2003/03/07 07:11:37 tshiozak Exp $ */ /*- @@ -46,8 +46,7 @@ __fputwc_unlock(wchar_t wc, FILE *fp) struct __suio uio; struct __siov iov; - /* LINTED we don't play with buf */ - iov.iov_base = (void *)buf; + iov.iov_base = buf; uio.uio_iov = &iov; uio.uio_iovcnt = 1; @@ -86,3 +85,4 @@ fputwc(wchar_t wc, FILE *fp) return (r); } +DEF_STRONG(fputwc); diff --git a/libc/upstream-openbsd/lib/libc/stdio/getdelim.c b/libc/upstream-openbsd/lib/libc/stdio/getdelim.c index 5e583cb55..58ff0a1be 100644 --- a/libc/upstream-openbsd/lib/libc/stdio/getdelim.c +++ b/libc/upstream-openbsd/lib/libc/stdio/getdelim.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getdelim.c,v 1.2 2014/10/16 17:31:51 millert Exp $ */ +/* $OpenBSD: getdelim.c,v 1.4 2015/08/31 02:53:57 guenther Exp $ */ /* $NetBSD: getdelim.c,v 1.13 2011/07/22 23:12:30 joerg Exp $ */ /* @@ -30,6 +30,7 @@ #include <errno.h> #include <limits.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -96,7 +97,7 @@ getdelim(char **__restrict buf, size_t *__restrict buflen, newlen |= newlen >> 4; newlen |= newlen >> 8; newlen |= newlen >> 16; -#if SIZE_T_MAX > 0xffffffffU +#if SIZE_MAX > 0xffffffffU newlen |= newlen >> 32; #endif newlen++; @@ -131,3 +132,4 @@ error: FUNLOCKFILE(fp); return -1; } +DEF_WEAK(getdelim); diff --git a/libc/upstream-openbsd/lib/libc/stdio/open_memstream.c b/libc/upstream-openbsd/lib/libc/stdio/open_memstream.c index 46105358d..f708acc50 100644 --- a/libc/upstream-openbsd/lib/libc/stdio/open_memstream.c +++ b/libc/upstream-openbsd/lib/libc/stdio/open_memstream.c @@ -1,4 +1,4 @@ -/* $OpenBSD: open_memstream.c,v 1.3 2013/04/03 03:11:53 guenther Exp $ */ +/* $OpenBSD: open_memstream.c,v 1.6 2015/08/31 02:53:57 guenther Exp $ */ /* * Copyright (c) 2011 Martin Pieuchot <mpi@openbsd.org> @@ -16,16 +16,16 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <sys/param.h> - #include <errno.h> #include <fcntl.h> -#include <limits.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "local.h" +#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) + struct state { char *string; /* actual stream */ char **pbuf; /* point to the stream */ @@ -95,7 +95,7 @@ memstream_seek(void *v, fpos_t off, int whence) } st->pos = base + off; - *st->psize = MIN(st->pos, st->len); + *st->psize = MINIMUM(st->pos, st->len); return (st->pos); } @@ -156,3 +156,4 @@ open_memstream(char **pbuf, size_t *psize) return (fp); } +DEF_WEAK(open_memstream); diff --git a/libc/upstream-openbsd/lib/libc/stdio/open_wmemstream.c b/libc/upstream-openbsd/lib/libc/stdio/open_wmemstream.c index 391a94445..aceef3515 100644 --- a/libc/upstream-openbsd/lib/libc/stdio/open_wmemstream.c +++ b/libc/upstream-openbsd/lib/libc/stdio/open_wmemstream.c @@ -1,4 +1,4 @@ -/* $OpenBSD: open_wmemstream.c,v 1.4 2014/10/08 05:28:19 deraadt Exp $ */ +/* $OpenBSD: open_wmemstream.c,v 1.8 2015/09/12 16:23:14 guenther Exp $ */ /* * Copyright (c) 2011 Martin Pieuchot <mpi@openbsd.org> @@ -16,17 +16,17 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <sys/param.h> - #include <errno.h> #include <fcntl.h> -#include <limits.h> #include <stdio.h> +#include <stdint.h> #include <stdlib.h> #include <string.h> #include <wchar.h> #include "local.h" +#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) + struct state { wchar_t *string; /* actual stream */ wchar_t **pbuf; /* point to the stream */ @@ -105,7 +105,7 @@ wmemstream_seek(void *v, fpos_t off, int whence) bzero(&st->mbs, sizeof(st->mbs)); st->pos = base + off; - *st->psize = MIN(st->pos, st->len); + *st->psize = MINIMUM(st->pos, st->len); return (st->pos); } diff --git a/libc/upstream-openbsd/lib/libc/stdio/tempnam.c b/libc/upstream-openbsd/lib/libc/stdio/tempnam.c index e3f2ab647..854b871cb 100644 --- a/libc/upstream-openbsd/lib/libc/stdio/tempnam.c +++ b/libc/upstream-openbsd/lib/libc/stdio/tempnam.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tempnam.c,v 1.17 2013/09/30 12:02:35 millert Exp $ */ +/* $OpenBSD: tempnam.c,v 1.19 2015/08/31 02:53:57 guenther Exp $ */ /* * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. @@ -39,8 +39,6 @@ __warn_references(tempnam, "warning: tempnam() possibly used unsafely; consider using mkstemp()"); -extern char *_mktemp(char *); - char * tempnam(const char *dir, const char *pfx) { @@ -58,7 +56,7 @@ tempnam(const char *dir, const char *pfx) f[strlen(f) - 1] == '/' ? "" : "/", pfx); if (len < 0 || len >= PATH_MAX) { errno = ENAMETOOLONG; - return(NULL); + goto fail; } if ((f = _mktemp(name))) return(f); @@ -70,7 +68,7 @@ tempnam(const char *dir, const char *pfx) f[strlen(f) - 1] == '/' ? "" : "/", pfx); if (len < 0 || len >= PATH_MAX) { errno = ENAMETOOLONG; - return(NULL); + goto fail; } if ((f = _mktemp(name))) return(f); @@ -80,7 +78,7 @@ tempnam(const char *dir, const char *pfx) len = snprintf(name, PATH_MAX, "%s%sXXXXXXXXX", f, pfx); if (len < 0 || len >= PATH_MAX) { errno = ENAMETOOLONG; - return(NULL); + goto fail; } if ((f = _mktemp(name))) return(f); @@ -89,11 +87,12 @@ tempnam(const char *dir, const char *pfx) len = snprintf(name, PATH_MAX, "%s%sXXXXXXXXX", f, pfx); if (len < 0 || len >= PATH_MAX) { errno = ENAMETOOLONG; - return(NULL); + goto fail; } if ((f = _mktemp(name))) return(f); +fail: sverrno = errno; free(name); errno = sverrno; diff --git a/libc/upstream-openbsd/lib/libc/stdio/vasprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vasprintf.c index 8fe7c5bb5..98cdb4554 100644 --- a/libc/upstream-openbsd/lib/libc/stdio/vasprintf.c +++ b/libc/upstream-openbsd/lib/libc/stdio/vasprintf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vasprintf.c,v 1.16 2009/11/09 00:18:27 kurt Exp $ */ +/* $OpenBSD: vasprintf.c,v 1.19 2015/12/28 22:08:18 mmcc Exp $ */ /* * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com> @@ -33,7 +33,7 @@ vasprintf(char **str, const char *fmt, __va_list ap) _FILEEXT_SETUP(&f, &fext); f._file = -1; f._flags = __SWR | __SSTR | __SALC; - f._bf._base = f._p = (unsigned char *)malloc(128); + f._bf._base = f._p = malloc(128); if (f._bf._base == NULL) goto err; f._bf._size = f._w = 127; /* Leave room for the NUL */ @@ -48,11 +48,10 @@ vasprintf(char **str, const char *fmt, __va_list ap) return (ret); err: - if (f._bf._base) { - free(f._bf._base); - f._bf._base = NULL; - } + free(f._bf._base); + f._bf._base = NULL; *str = NULL; errno = ENOMEM; return (-1); } +DEF_WEAK(vasprintf); diff --git a/libc/upstream-openbsd/lib/libc/stdio/vfprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vfprintf.c index 5f4fb7fa9..3d7d41e10 100644 --- a/libc/upstream-openbsd/lib/libc/stdio/vfprintf.c +++ b/libc/upstream-openbsd/lib/libc/stdio/vfprintf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfprintf.c,v 1.67 2014/12/21 00:23:30 daniel Exp $ */ +/* $OpenBSD: vfprintf.c,v 1.71 2016/01/04 15:47:47 schwarze Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. @@ -165,10 +165,8 @@ __wcsconv(wchar_t *wcsarg, int prec) memset(&mbs, 0, sizeof(mbs)); p = wcsarg; nbytes = wcsrtombs(NULL, (const wchar_t **)&p, 0, &mbs); - if (nbytes == (size_t)-1) { - errno = EILSEQ; + if (nbytes == (size_t)-1) return (NULL); - } } else { /* * Optimisation: if the output precision is small enough, @@ -188,10 +186,8 @@ __wcsconv(wchar_t *wcsarg, int prec) break; nbytes += clen; } - if (clen == (size_t)-1) { - errno = EILSEQ; + if (clen == (size_t)-1) return (NULL); - } } } if ((convbuf = malloc(nbytes + 1)) == NULL) @@ -203,7 +199,6 @@ __wcsconv(wchar_t *wcsarg, int prec) if ((nbytes = wcsrtombs(convbuf, (const wchar_t **)&p, nbytes, &mbs)) == (size_t)-1) { free(convbuf); - errno = EILSEQ; return (NULL); } convbuf[nbytes] = '\0'; @@ -268,6 +263,7 @@ vfprintf(FILE *fp, const char *fmt0, __va_list ap) FUNLOCKFILE(fp); return (ret); } +DEF_STRONG(vfprintf); int __vfprintf(FILE *fp, const char *fmt0, __va_list ap) @@ -437,7 +433,11 @@ __vfprintf(FILE *fp, const char *fmt0, __va_list ap) int hold = nextarg; \ if (argtable == NULL) { \ argtable = statargtable; \ - __find_arguments(fmt0, orgap, &argtable, &argtablesiz); \ + if (__find_arguments(fmt0, orgap, &argtable, \ + &argtablesiz) == -1) { \ + ret = -1; \ + goto error; \ + } \ } \ nextarg = n2; \ val = GETARG(int); \ @@ -493,6 +493,10 @@ __vfprintf(FILE *fp, const char *fmt0, __va_list ap) break; } } + if (n < 0) { + ret = -1; + goto error; + } if (fmt != cp) { ptrdiff_t m = fmt - cp; if (m < 0 || m > INT_MAX - ret) @@ -500,7 +504,7 @@ __vfprintf(FILE *fp, const char *fmt0, __va_list ap) PRINT(cp, m); ret += m; } - if (n <= 0) + if (n == 0) goto done; fmt++; /* skip over '%' */ @@ -563,8 +567,11 @@ reswitch: switch (ch) { nextarg = n; if (argtable == NULL) { argtable = statargtable; - __find_arguments(fmt0, orgap, - &argtable, &argtablesiz); + if (__find_arguments(fmt0, orgap, + &argtable, &argtablesiz) == -1) { + ret = -1; + goto error; + } } goto rflag; } @@ -589,8 +596,11 @@ reswitch: switch (ch) { nextarg = n; if (argtable == NULL) { argtable = statargtable; - __find_arguments(fmt0, orgap, - &argtable, &argtablesiz); + if (__find_arguments(fmt0, orgap, + &argtable, &argtablesiz) == -1) { + ret = -1; + goto error; + } } goto rflag; } @@ -639,8 +649,7 @@ reswitch: switch (ch) { mbseqlen = wcrtomb(buf, (wchar_t)GETARG(wint_t), &mbs); if (mbseqlen == (size_t)-1) { - fp->_flags |= __SERR; - errno = EILSEQ; + ret = -1; goto error; } cp = buf; @@ -835,7 +844,6 @@ fp_common: * defined manner.'' * -- ANSI X3J11 */ - /* NOSTRICT */ _umax = (u_long)GETARG(void *); base = HEX; xdigs = xdigs_lower; @@ -846,16 +854,14 @@ fp_common: if (flags & LONGINT) { wchar_t *wcp; - if (convbuf != NULL) { - free(convbuf); - convbuf = NULL; - } + free(convbuf); + convbuf = NULL; if ((wcp = GETARG(wchar_t *)) == NULL) { cp = "(null)"; } else { convbuf = __wcsconv(wcp, prec); if (convbuf == NULL) { - fp->_flags = __SERR; + ret = -1; goto error; } cp = convbuf; @@ -1075,8 +1081,7 @@ overflow: finish: #ifdef PRINTF_WIDE_CHAR - if (convbuf) - free(convbuf); + free(convbuf); #endif #ifdef FLOATING_POINT if (dtoaresult) @@ -1214,7 +1219,9 @@ __find_arguments(const char *fmt0, va_list ap, union arg **argtable, break; } } - if (n <= 0) + if (n < 0) + return (-1); + if (n == 0) goto done; fmt++; /* skip over '%' */ diff --git a/libc/upstream-openbsd/lib/libc/stdio/vfwprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vfwprintf.c index a6f41232c..520c8bc7d 100644 --- a/libc/upstream-openbsd/lib/libc/stdio/vfwprintf.c +++ b/libc/upstream-openbsd/lib/libc/stdio/vfwprintf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfwprintf.c,v 1.12 2014/12/21 00:23:30 daniel Exp $ */ +/* $OpenBSD: vfwprintf.c,v 1.15 2015/12/28 22:08:18 mmcc Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. @@ -667,10 +667,7 @@ reswitch: switch (ch) { prec = dtoaend - dtoaresult; if (expt == INT_MAX) ox[1] = '\0'; - if (convbuf) { - free(convbuf); - convbuf = NULL; - } + free(convbuf); cp = convbuf = __mbsconv(dtoaresult, -1); if (cp == NULL) goto error; @@ -719,10 +716,7 @@ fp_begin: if (expt == 9999) expt = INT_MAX; } - if (convbuf) { - free(convbuf); - convbuf = NULL; - } + free(convbuf); cp = convbuf = __mbsconv(dtoaresult, -1); if (cp == NULL) goto error; @@ -812,7 +806,6 @@ fp_common: * defined manner.'' * -- ANSI X3J11 */ - /* NOSTRICT */ _umax = (u_long)GETARG(void *); base = HEX; xdigs = xdigs_lower; @@ -829,10 +822,7 @@ fp_common: char *mbsarg; if ((mbsarg = GETARG(char *)) == NULL) mbsarg = "(null)"; - if (convbuf) { - free(convbuf); - convbuf = NULL; - } + free(convbuf); convbuf = __mbsconv(mbsarg, prec); if (convbuf == NULL) { fp->_flags |= __SERR; @@ -1048,8 +1038,7 @@ overflow: ret = -1; finish: - if (convbuf) - free(convbuf); + free(convbuf); #ifdef FLOATING_POINT if (dtoaresult) __freedtoa(dtoaresult); @@ -1072,6 +1061,7 @@ vfwprintf(FILE * __restrict fp, const wchar_t * __restrict fmt0, __va_list ap) return (r); } +DEF_STRONG(vfwprintf); /* * Type ids for argument type table. diff --git a/libc/upstream-openbsd/lib/libc/stdio/vswprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vswprintf.c index da7c4deae..641db4ae7 100644 --- a/libc/upstream-openbsd/lib/libc/stdio/vswprintf.c +++ b/libc/upstream-openbsd/lib/libc/stdio/vswprintf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vswprintf.c,v 1.4 2012/12/05 23:20:01 deraadt Exp $ */ +/* $OpenBSD: vswprintf.c,v 1.6 2015/08/31 02:53:57 guenther Exp $ */ /* $NetBSD: vswprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp $ */ /* @@ -55,7 +55,7 @@ vswprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt, _FILEEXT_SETUP(&f, &fext); f._file = -1; f._flags = __SWR | __SSTR | __SALC; - f._bf._base = f._p = (unsigned char *)malloc(128); + f._bf._base = f._p = malloc(128); if (f._bf._base == NULL) { errno = ENOMEM; return (-1); @@ -94,3 +94,4 @@ vswprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt, return (ret); } +DEF_STRONG(vswprintf); diff --git a/libc/upstream-openbsd/lib/libc/stdlib/reallocarray.c b/libc/upstream-openbsd/lib/libc/stdlib/reallocarray.c index 7accd99e0..baea252a8 100644 --- a/libc/upstream-openbsd/lib/libc/stdlib/reallocarray.c +++ b/libc/upstream-openbsd/lib/libc/stdlib/reallocarray.c @@ -1,4 +1,4 @@ -/* $OpenBSD: reallocarray.c,v 1.1 2014/05/08 21:43:49 deraadt Exp $ */ +/* $OpenBSD: reallocarray.c,v 1.3 2015/09/13 08:31:47 guenther Exp $ */ /* * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net> * @@ -24,7 +24,7 @@ * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW */ -#define MUL_NO_OVERFLOW (1UL << (sizeof(size_t) * 4)) +#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4)) void * reallocarray(void *optr, size_t nmemb, size_t size) @@ -36,3 +36,4 @@ reallocarray(void *optr, size_t nmemb, size_t size) } return realloc(optr, size * nmemb); } +DEF_WEAK(reallocarray); diff --git a/libc/upstream-openbsd/lib/libc/stdlib/setenv.c b/libc/upstream-openbsd/lib/libc/stdlib/setenv.c index 9060fdba8..e55a1feb6 100644 --- a/libc/upstream-openbsd/lib/libc/stdlib/setenv.c +++ b/libc/upstream-openbsd/lib/libc/stdlib/setenv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: setenv.c,v 1.14 2012/09/23 16:08:04 jeremy Exp $ */ +/* $OpenBSD: setenv.c,v 1.16 2015/09/13 08:31:47 guenther Exp $ */ /* * Copyright (c) 1987 Regents of the University of California. * All rights reserved. @@ -32,8 +32,6 @@ #include <stdlib.h> #include <string.h> -char *__findenv(const char *name, int len, int *offset); - extern char **environ; static char **lastenv; /* last value of environ */ @@ -71,7 +69,7 @@ putenv(char *str) for (P = environ; *P != NULL; P++) ; cnt = P - environ; - P = (char **)realloc(lastenv, sizeof(char *) * (cnt + 2)); + P = reallocarray(lastenv, cnt + 2, sizeof(char *)); if (!P) return (-1); if (lastenv != environ) @@ -81,6 +79,7 @@ putenv(char *str) environ[cnt + 1] = NULL; return (0); } +DEF_WEAK(putenv); /* * setenv -- @@ -129,7 +128,7 @@ setenv(const char *name, const char *value, int rewrite) for (P = environ; *P != NULL; P++) ; cnt = P - environ; - P = (char **)realloc(lastenv, sizeof(char *) * (cnt + 2)); + P = reallocarray(lastenv, cnt + 2, sizeof(char *)); if (!P) return (-1); if (lastenv != environ) @@ -147,6 +146,7 @@ setenv(const char *name, const char *value, int rewrite) ; return (0); } +DEF_WEAK(setenv); /* * unsetenv(name) -- @@ -178,3 +178,4 @@ unsetenv(const char *name) } return (0); } +DEF_WEAK(unsetenv); diff --git a/libc/upstream-openbsd/lib/libc/stdlib/system.c b/libc/upstream-openbsd/lib/libc/stdlib/system.c index 14ddcae8d..de32d4328 100644 --- a/libc/upstream-openbsd/lib/libc/stdlib/system.c +++ b/libc/upstream-openbsd/lib/libc/stdlib/system.c @@ -1,4 +1,4 @@ -/* $OpenBSD: system.c,v 1.8 2005/08/08 08:05:37 espie Exp $ */ +/* $OpenBSD: system.c,v 1.11 2015/10/23 04:44:41 guenther Exp $ */ /* * Copyright (c) 1988 The Regents of the University of California. * All rights reserved. @@ -30,6 +30,7 @@ #include <sys/types.h> #include <sys/wait.h> +#include <errno.h> #include <signal.h> #include <stdlib.h> #include <unistd.h> @@ -40,8 +41,8 @@ extern char **environ; int system(const char *command) { - pid_t pid; - sig_t intsave, quitsave; + pid_t pid, cpid; + struct sigaction intsave, quitsave; sigset_t mask, omask; int pstat; char *argp[] = {"sh", "-c", NULL, NULL}; @@ -54,7 +55,7 @@ system(const char *command) sigemptyset(&mask); sigaddset(&mask, SIGCHLD); sigprocmask(SIG_BLOCK, &mask, &omask); - switch (pid = vfork()) { + switch (cpid = vfork()) { case -1: /* error */ sigprocmask(SIG_SETMASK, &omask, NULL); return(-1); @@ -64,11 +65,14 @@ system(const char *command) _exit(127); } - intsave = signal(SIGINT, SIG_IGN); - quitsave = signal(SIGQUIT, SIG_IGN); - pid = waitpid(pid, (int *)&pstat, 0); + sigaction(SIGINT, NULL, &intsave); + sigaction(SIGQUIT, NULL, &quitsave); + do { + pid = waitpid(cpid, &pstat, 0); + } while (pid == -1 && errno == EINTR); sigprocmask(SIG_SETMASK, &omask, NULL); - (void)signal(SIGINT, intsave); - (void)signal(SIGQUIT, quitsave); + sigaction(SIGINT, &intsave, NULL); + sigaction(SIGQUIT, &quitsave, NULL); return (pid == -1 ? -1 : pstat); } +DEF_STRONG(system); diff --git a/libc/upstream-openbsd/lib/libc/string/strlcat.c b/libc/upstream-openbsd/lib/libc/string/strlcat.c index ceab09441..073b0d425 100644 --- a/libc/upstream-openbsd/lib/libc/string/strlcat.c +++ b/libc/upstream-openbsd/lib/libc/string/strlcat.c @@ -1,7 +1,7 @@ -/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */ +/* $OpenBSD: strlcat.c,v 1.16 2015/08/31 02:53:57 guenther Exp $ */ /* - * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> + * Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -20,36 +20,37 @@ #include <string.h> /* - * Appends src to string dst of size siz (unlike strncat, siz is the - * full size of dst, not space left). At most siz-1 characters - * will be copied. Always NUL terminates (unless siz <= strlen(dst)). - * Returns strlen(src) + MIN(siz, strlen(initial dst)). - * If retval >= siz, truncation occurred. + * Appends src to string dst of size dsize (unlike strncat, dsize is the + * full size of dst, not space left). At most dsize-1 characters + * will be copied. Always NUL terminates (unless dsize <= strlen(dst)). + * Returns strlen(src) + MIN(dsize, strlen(initial dst)). + * If retval >= dsize, truncation occurred. */ size_t -strlcat(char *dst, const char *src, size_t siz) +strlcat(char *dst, const char *src, size_t dsize) { - char *d = dst; - const char *s = src; - size_t n = siz; + const char *odst = dst; + const char *osrc = src; + size_t n = dsize; size_t dlen; - /* Find the end of dst and adjust bytes left but don't go past end */ - while (n-- != 0 && *d != '\0') - d++; - dlen = d - dst; - n = siz - dlen; + /* Find the end of dst and adjust bytes left but don't go past end. */ + while (n-- != 0 && *dst != '\0') + dst++; + dlen = dst - odst; + n = dsize - dlen; - if (n == 0) - return(dlen + strlen(s)); - while (*s != '\0') { - if (n != 1) { - *d++ = *s; + if (n-- == 0) + return(dlen + strlen(src)); + while (*src != '\0') { + if (n != 0) { + *dst++ = *src; n--; } - s++; + src++; } - *d = '\0'; + *dst = '\0'; - return(dlen + (s - src)); /* count does not include NUL */ + return(dlen + (src - osrc)); /* count does not include NUL */ } +DEF_WEAK(strlcat); diff --git a/libc/upstream-openbsd/lib/libc/string/strlcpy.c b/libc/upstream-openbsd/lib/libc/string/strlcpy.c index d32b6590f..5fcf084aa 100644 --- a/libc/upstream-openbsd/lib/libc/string/strlcpy.c +++ b/libc/upstream-openbsd/lib/libc/string/strlcpy.c @@ -1,7 +1,7 @@ -/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */ +/* $OpenBSD: strlcpy.c,v 1.13 2015/08/31 02:53:57 guenther Exp $ */ /* - * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> + * Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -20,32 +20,32 @@ #include <string.h> /* - * Copy src to string dst of size siz. At most siz-1 characters - * will be copied. Always NUL terminates (unless siz == 0). - * Returns strlen(src); if retval >= siz, truncation occurred. + * Copy string src to buffer dst of size dsize. At most dsize-1 + * chars will be copied. Always NUL terminates (unless dsize == 0). + * Returns strlen(src); if retval >= dsize, truncation occurred. */ size_t -strlcpy(char *dst, const char *src, size_t siz) +strlcpy(char *dst, const char *src, size_t dsize) { - char *d = dst; - const char *s = src; - size_t n = siz; + const char *osrc = src; + size_t nleft = dsize; - /* Copy as many bytes as will fit */ - if (n != 0) { - while (--n != 0) { - if ((*d++ = *s++) == '\0') + /* Copy as many bytes as will fit. */ + if (nleft != 0) { + while (--nleft != 0) { + if ((*dst++ = *src++) == '\0') break; } } - /* Not enough room in dst, add NUL and traverse rest of src */ - if (n == 0) { - if (siz != 0) - *d = '\0'; /* NUL-terminate dst */ - while (*s++) + /* Not enough room in dst, add NUL and traverse rest of src. */ + if (nleft == 0) { + if (dsize != 0) + *dst = '\0'; /* NUL-terminate dst */ + while (*src++) ; } - return(s - src - 1); /* count does not include NUL */ + return(src - osrc - 1); /* count does not include NUL */ } +DEF_WEAK(strlcpy); diff --git a/libc/upstream-openbsd/lib/libc/string/strtok.c b/libc/upstream-openbsd/lib/libc/string/strtok.c index 4e963a019..c5765756f 100644 --- a/libc/upstream-openbsd/lib/libc/string/strtok.c +++ b/libc/upstream-openbsd/lib/libc/string/strtok.c @@ -36,15 +36,15 @@ strtok(char *s, const char *delim) return strtok_r(s, delim, &last); } +DEF_STRONG(strtok); char * strtok_r(char *s, const char *delim, char **last) { - char *spanp; + const char *spanp; int c, sc; char *tok; - if (s == NULL && (s = *last) == NULL) return (NULL); @@ -53,7 +53,7 @@ strtok_r(char *s, const char *delim, char **last) */ cont: c = *s++; - for (spanp = (char *)delim; (sc = *spanp++) != 0;) { + for (spanp = delim; (sc = *spanp++) != 0;) { if (c == sc) goto cont; } @@ -70,13 +70,13 @@ cont: */ for (;;) { c = *s++; - spanp = (char *)delim; + spanp = delim; do { if ((sc = *spanp++) == c) { if (c == 0) s = NULL; else - s[-1] = 0; + s[-1] = '\0'; *last = s; return (tok); } @@ -84,3 +84,4 @@ cont: } /* NOTREACHED */ } +DEF_WEAK(strtok_r); diff --git a/libc/upstream-openbsd/lib/libc/string/wcslcpy.c b/libc/upstream-openbsd/lib/libc/string/wcslcpy.c index f49936a88..36a544a33 100644 --- a/libc/upstream-openbsd/lib/libc/string/wcslcpy.c +++ b/libc/upstream-openbsd/lib/libc/string/wcslcpy.c @@ -1,8 +1,7 @@ -/* $OpenBSD: wcslcpy.c,v 1.5 2011/07/24 15:21:28 millert Exp $ */ -/* $NetBSD: wcslcpy.c,v 1.2 2001/01/03 14:33:02 lukem Exp $ */ +/* $OpenBSD: wcslcpy.c,v 1.7 2015/09/12 16:23:14 guenther Exp $ */ /* - * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> + * Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -21,32 +20,32 @@ #include <wchar.h> /* - * Copy src to string dst of size siz. At most siz-1 characters - * will be copied. Always NUL terminates (unless siz == 0). - * Returns wcslen(src); if retval >= siz, truncation occurred. + * Copy string src to buffer dst of size dsize. At most dsize-1 + * chars will be copied. Always NUL terminates (unless dsize == 0). + * Returns wcslen(src); if retval >= dsize, truncation occurred. */ size_t -wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz) +wcslcpy(wchar_t *dst, const wchar_t *src, size_t dsize) { - wchar_t *d = dst; - const wchar_t *s = src; - size_t n = siz; + const wchar_t *osrc = src; + size_t nleft = dsize; - /* Copy as many bytes as will fit */ - if (n != 0) { - while (--n != 0) { - if ((*d++ = *s++) == '\0') + /* Copy as many bytes as will fit. */ + if (nleft != 0) { + while (--nleft != 0) { + if ((*dst++ = *src++) == L'\0') break; } } - /* Not enough room in dst, add NUL and traverse rest of src */ - if (n == 0) { - if (siz != 0) - *d = '\0'; /* NUL-terminate dst */ - while (*s++) + /* Not enough room in dst, add NUL and traverse rest of src. */ + if (nleft == 0) { + if (dsize != 0) + *dst = L'\0'; /* NUL-terminate dst */ + while (*src++) ; } - return(s - src - 1); /* count does not include NUL */ + return(src - osrc - 1); /* count does not include NUL */ } +DEF_WEAK(wcslcpy); diff --git a/libc/upstream-openbsd/lib/libc/time/wcsftime.c b/libc/upstream-openbsd/lib/libc/time/wcsftime.c index 21ccac704..067840401 100644 --- a/libc/upstream-openbsd/lib/libc/time/wcsftime.c +++ b/libc/upstream-openbsd/lib/libc/time/wcsftime.c @@ -1,6 +1,4 @@ -/* $OpenBSD: wcsftime.c,v 1.3 2014/05/06 15:49:45 tedu Exp $ */ -#include "private.h" - +/* $OpenBSD: wcsftime.c,v 1.6 2015/02/09 14:52:28 tedu Exp $ */ /* ** Based on the UCB version with the ID appearing below. ** This is ANSIish only when "multibyte character == plain character". @@ -33,11 +31,13 @@ ** SUCH DAMAGE. */ -#include "tzfile.h" -#include "fcntl.h" +#include <fcntl.h> #include <locale.h> #include <wchar.h> +#include "private.h" +#include "tzfile.h" + struct lc_time_T { const wchar_t * mon[MONSPERYEAR]; const wchar_t * month[MONSPERYEAR]; @@ -292,14 +292,9 @@ label: tm = *t; mkt = mktime(&tm); - if (TYPE_SIGNED(time_t)) - (void) swprintf(buf, - sizeof buf/sizeof buf[0], - L"%ld", (long) mkt); - else - (void) swprintf(buf, - sizeof buf/sizeof buf[0], - L"%lu", (unsigned long) mkt); + (void) swprintf(buf, + sizeof buf/sizeof buf[0], + L"%ld", (long) mkt); pt = _add(buf, pt, ptlim); } continue; @@ -529,8 +524,8 @@ static wchar_t * _yconv(int a, int b, int convert_top, int convert_yy, wchar_t *pt, const wchar_t *ptlim) { - register int lead; - register int trail; + int lead; + int trail; #define DIVISOR 100 trail = a % DIVISOR + b % DIVISOR; |