Sync with upstream OpenBSD.
Also some minor build cleanup.
Change-Id: Ibd20602d7ea45685f0c47fceb00ffd6c7ae35954
diff --git a/libc/upstream-openbsd/android/include/openbsd-compat.h b/libc/upstream-openbsd/android/include/openbsd-compat.h
index b07f55d..caea45a 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 e7ec29d..15e1b97 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 d213435..e6b5d23 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 3a57500..6fcf1cd 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 dcd8edc..8f4722b 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 @@
(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 60da062..f0186b6 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 @@
(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 26b60f3..44d8be4 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 @@
}
(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 e6b1957..67d8f5b 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 c1b47a6..6784cf6 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 af2ab66..723bc0d 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 f28692f..72b9c41 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_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 @@
}
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 @@
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 5424c90..4823677 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 @@
_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 @@
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 c16ffaf..2e69191 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 @@
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 @@
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 e8cd249..d02ccd5 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 @@
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 @@
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 9db70d0..829c22c 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 @@
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 @@
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 5e583cb..58ff0a1 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 @@
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 @@
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 4610535..f708acc 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 @@
}
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 @@
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 391a944..aceef35 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 @@
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 e3f2ab6..854b871 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 @@
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 @@
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 @@
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 @@
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 8fe7c5b..98cdb45 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 @@
_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 @@
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 5f4fb7f..3d7d41e 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 @@
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 @@
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 @@
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 @@
FUNLOCKFILE(fp);
return (ret);
}
+DEF_STRONG(vfprintf);
int
__vfprintf(FILE *fp, const char *fmt0, __va_list ap)
@@ -437,7 +433,11 @@
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 @@
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 @@
PRINT(cp, m);
ret += m;
}
- if (n <= 0)
+ if (n == 0)
goto done;
fmt++; /* skip over '%' */
@@ -563,8 +567,11 @@
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 @@
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 @@
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 @@
* defined manner.''
* -- ANSI X3J11
*/
- /* NOSTRICT */
_umax = (u_long)GETARG(void *);
base = HEX;
xdigs = xdigs_lower;
@@ -846,16 +854,14 @@
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 @@
finish:
#ifdef PRINTF_WIDE_CHAR
- if (convbuf)
- free(convbuf);
+ free(convbuf);
#endif
#ifdef FLOATING_POINT
if (dtoaresult)
@@ -1214,7 +1219,9 @@
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 a6f4123..520c8bc 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 @@
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 @@
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 @@
* defined manner.''
* -- ANSI X3J11
*/
- /* NOSTRICT */
_umax = (u_long)GETARG(void *);
base = HEX;
xdigs = xdigs_lower;
@@ -829,10 +822,7 @@
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 @@
ret = -1;
finish:
- if (convbuf)
- free(convbuf);
+ free(convbuf);
#ifdef FLOATING_POINT
if (dtoaresult)
__freedtoa(dtoaresult);
@@ -1072,6 +1061,7 @@
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 da7c4de..641db4a 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 @@
_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 @@
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 7accd99..baea252 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 @@
}
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 9060fdb..e55a1fe 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 @@
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 @@
environ[cnt + 1] = NULL;
return (0);
}
+DEF_WEAK(putenv);
/*
* setenv --
@@ -129,7 +128,7 @@
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 @@
;
return (0);
}
+DEF_WEAK(setenv);
/*
* unsetenv(name) --
@@ -178,3 +178,4 @@
}
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 14ddcae..de32d43 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 @@
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 @@
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 @@
_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 ceab094..073b0d4 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 d32b659..5fcf084 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 4e963a0..c576575 100644
--- a/libc/upstream-openbsd/lib/libc/string/strtok.c
+++ b/libc/upstream-openbsd/lib/libc/string/strtok.c
@@ -36,15 +36,15 @@
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 @@
*/
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 @@
*/
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 @@
}
/* 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 f49936a..36a544a 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 21ccac7..0678404 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 @@
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 @@
_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;