summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/shlib_version4
-rw-r--r--lib/libc/stdio/asprintf.c7
-rw-r--r--lib/libc/stdio/fileext.h42
-rw-r--r--lib/libc/stdio/findfp.c38
-rw-r--r--lib/libc/stdio/freopen.c4
-rw-r--r--lib/libc/stdio/local.h12
-rw-r--r--lib/libc/stdio/snprintf.c5
-rw-r--r--lib/libc/stdio/sprintf.c4
-rw-r--r--lib/libc/stdio/sscanf.c6
-rw-r--r--lib/libc/stdio/ungetc.c22
-rw-r--r--lib/libc/stdio/vasprintf.c7
-rw-r--r--lib/libc/stdio/vfprintf.c4
-rw-r--r--lib/libc/stdio/vsnprintf.c6
-rw-r--r--lib/libc/stdio/vsprintf.c5
-rw-r--r--lib/libc/stdio/vsscanf.c7
15 files changed, 130 insertions, 43 deletions
diff --git a/lib/libc/shlib_version b/lib/libc/shlib_version
index eaa383b64ee..ca182c4511c 100644
--- a/lib/libc/shlib_version
+++ b/lib/libc/shlib_version
@@ -1,4 +1,4 @@
-major=35
-minor=2
+major=36
+minor=0
# note: If changes were made to include/thread_private.h or if system
# calls were added/changed then libpthread must also be updated.
diff --git a/lib/libc/stdio/asprintf.c b/lib/libc/stdio/asprintf.c
index f93d2cd7fad..72c217a4119 100644
--- a/lib/libc/stdio/asprintf.c
+++ b/lib/libc/stdio/asprintf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: asprintf.c,v 1.11 2005/03/31 18:36:29 pat Exp $ */
+/* $OpenBSD: asprintf.c,v 1.12 2005/04/30 09:25:17 espie Exp $ */
/*
* Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -17,13 +17,14 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: asprintf.c,v 1.11 2005/03/31 18:36:29 pat Exp $";
+static char rcsid[] = "$OpenBSD: asprintf.c,v 1.12 2005/04/30 09:25:17 espie Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <stdarg.h>
+#include "local.h"
int
asprintf(char **str, const char *fmt, ...)
@@ -31,8 +32,10 @@ asprintf(char **str, const char *fmt, ...)
int ret;
va_list ap;
FILE f;
+ struct __sfileext fext;
unsigned char *_base;
+ _FILEEXT_SETUP(&f, &fext);
va_start(ap, fmt);
f._file = -1;
f._flags = __SWR | __SSTR | __SALC;
diff --git a/lib/libc/stdio/fileext.h b/lib/libc/stdio/fileext.h
new file mode 100644
index 00000000000..5619940c2bc
--- /dev/null
+++ b/lib/libc/stdio/fileext.h
@@ -0,0 +1,42 @@
+/* $OpenBSD: fileext.h,v 1.1 2005/04/30 09:25:17 espie Exp $ */
+/* $NetBSD: fileext.h,v 1.5 2003/07/18 21:46:41 nathanw Exp $ */
+
+/*-
+ * Copyright (c)2001 Citrus Project,
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Citrus$
+ */
+
+/*
+ * file extension
+ */
+struct __sfileext {
+ struct __sbuf _ub; /* ungetc buffer */
+ /* further data */
+};
+
+#define _EXT(fp) ((struct __sfileext *)((fp)->_ext._base))
+#define _UB(fp) _EXT(fp)->_ub
+#define _FILEEXT_SETUP(f, fext) /* LINTED */(f)->_ext._base = (unsigned char *)(fext)
diff --git a/lib/libc/stdio/findfp.c b/lib/libc/stdio/findfp.c
index 733872f43ee..f4de6458146 100644
--- a/lib/libc/stdio/findfp.c
+++ b/lib/libc/stdio/findfp.c
@@ -31,7 +31,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: findfp.c,v 1.5 2004/09/28 18:12:44 otto Exp $";
+static char rcsid[] = "$OpenBSD: findfp.c,v 1.6 2005/04/30 09:25:17 espie Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -48,13 +48,17 @@ int __sdidinit;
#define NDYNAMIC 10 /* add ten more whenever necessary */
#define std(flags, file) \
- {0,0,0,flags,file,{0},0,__sF+file,__sclose,__sread,__sseek,__swrite}
-/* p r w flags file _bf z cookie close read seek write */
+ {0,0,0,flags,file,{0},0,__sF+file,__sclose,__sread,__sseek,__swrite, \
+ {(unsigned char *)(__sFext+file), 0}}
+/* p r w flags file _bf z cookie close read seek write
+ ext */
/* the usual - (stdin + stdout + stderr) */
static FILE usual[FOPEN_MAX - 3];
+static struct __sfileext usualext[FOPEN_MAX - 3];
static struct glue uglue = { 0, FOPEN_MAX - 3, usual };
+struct __sfileext __sFext[3];
FILE __sF[3] = {
std(__SRD, STDIN_FILENO), /* stdin */
std(__SWR, STDOUT_FILENO), /* stdout */
@@ -67,17 +71,27 @@ moreglue(int n)
{
struct glue *g;
FILE *p;
+ struct __sfileext *pext;
static FILE empty;
+ char *data;
- g = (struct glue *)malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE));
- if (g == NULL)
+ data = malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE)
+ + n * sizeof(struct __sfileext));
+ if (data == NULL)
return (NULL);
- p = (FILE *)ALIGN(g + 1);
+ g = (struct glue *)data;
+ p = (FILE *)ALIGN(data + sizeof(*g));
+ pext = (struct __sfileext *)
+ (ALIGN(data + sizeof(*g)) + n * sizeof(FILE));
g->next = NULL;
g->niobs = n;
g->iobs = p;
- while (--n >= 0)
- *p++ = empty;
+ while (--n >= 0) {
+ *p = empty;
+ _FILEEXT_SETUP(p, pext);
+ p++;
+ pext++;
+ }
return (g);
}
@@ -111,8 +125,8 @@ found:
fp->_lbfsize = 0; /* not line buffered */
fp->_file = -1; /* no file */
/* fp->_cookie = <any>; */ /* caller sets cookie, _read/_write etc */
- fp->_ub._base = NULL; /* no ungetc buffer */
- fp->_ub._size = 0;
+ _UB(fp)._base = NULL; /* no ungetc buffer */
+ _UB(fp)._size = 0;
fp->_lb._base = NULL; /* no line buffer */
fp->_lb._size = 0;
return (fp);
@@ -156,6 +170,10 @@ _cleanup(void)
void
__sinit(void)
{
+ int i;
+
+ for (i = 0; i < FOPEN_MAX - 3; i++)
+ _FILEEXT_SETUP(usual+i, usualext+i);
/* make sure we clean up on exit */
__atexit_register_cleanup(_cleanup); /* conservative */
__sdidinit = 1;
diff --git a/lib/libc/stdio/freopen.c b/lib/libc/stdio/freopen.c
index 9267d4421a7..0131001bea6 100644
--- a/lib/libc/stdio/freopen.c
+++ b/lib/libc/stdio/freopen.c
@@ -31,7 +31,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: freopen.c,v 1.6 2004/09/28 18:12:44 otto Exp $";
+static char rcsid[] = "$OpenBSD: freopen.c,v 1.7 2005/04/30 09:25:17 espie Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -115,7 +115,7 @@ freopen(const char *file, const char *mode, FILE *fp)
fp->_lbfsize = 0;
if (HASUB(fp))
FREEUB(fp);
- fp->_ub._size = 0;
+ _UB(fp)._size = 0;
if (HASLB(fp))
FREELB(fp);
fp->_lb._size = 0;
diff --git a/lib/libc/stdio/local.h b/lib/libc/stdio/local.h
index 085cad26234..c2e912eae2b 100644
--- a/lib/libc/stdio/local.h
+++ b/lib/libc/stdio/local.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: local.h,v 1.9 2005/03/31 18:36:29 pat Exp $ */
+/* $OpenBSD: local.h,v 1.10 2005/04/30 09:25:17 espie Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -37,6 +37,8 @@
* in particular, macros and private variables.
*/
+#include "fileext.h"
+
int __sflush(FILE *);
FILE *__sfp(void);
int __srefill(FILE *);
@@ -66,11 +68,11 @@ extern int __sdidinit;
* Test whether the given stdio file has an active ungetc buffer;
* release such a buffer, without restoring ordinary unread data.
*/
-#define HASUB(fp) ((fp)->_ub._base != NULL)
+#define HASUB(fp) (_UB(fp)._base != NULL)
#define FREEUB(fp) { \
- if ((fp)->_ub._base != (fp)->_ubuf) \
- free((char *)(fp)->_ub._base); \
- (fp)->_ub._base = NULL; \
+ if (_UB(fp)._base != (fp)->_ubuf) \
+ free(_UB(fp)._base); \
+ _UB(fp)._base = NULL; \
}
/*
diff --git a/lib/libc/stdio/snprintf.c b/lib/libc/stdio/snprintf.c
index 738232abc30..653d0f01f08 100644
--- a/lib/libc/stdio/snprintf.c
+++ b/lib/libc/stdio/snprintf.c
@@ -31,12 +31,13 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: snprintf.c,v 1.10 2005/03/31 18:36:29 pat Exp $";
+static char rcsid[] = "$OpenBSD: snprintf.c,v 1.11 2005/04/30 09:25:17 espie Exp $";
#endif /* LIBC_SCCS and not lint */
#include <limits.h>
#include <stdio.h>
#include <stdarg.h>
+#include "local.h"
int
snprintf(char *str, size_t n, const char *fmt, ...)
@@ -45,6 +46,7 @@ snprintf(char *str, size_t n, const char *fmt, ...)
int ret;
char dummy;
FILE f;
+ struct __sfileext fext;
/* While snprintf(3) specifies size_t stdio uses an int internally */
if (n > INT_MAX)
@@ -55,6 +57,7 @@ snprintf(char *str, size_t n, const char *fmt, ...)
n = 1;
}
va_start(ap, fmt);
+ _FILEEXT_SETUP(&f, &fext);
f._file = -1;
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
diff --git a/lib/libc/stdio/sprintf.c b/lib/libc/stdio/sprintf.c
index 68e8f54896c..a2cb5819a4a 100644
--- a/lib/libc/stdio/sprintf.c
+++ b/lib/libc/stdio/sprintf.c
@@ -31,7 +31,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: sprintf.c,v 1.10 2005/03/31 18:36:29 pat Exp $";
+static char rcsid[] = "$OpenBSD: sprintf.c,v 1.11 2005/04/30 09:25:17 espie Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -50,7 +50,9 @@ sprintf(char *str, const char *fmt, ...)
int ret;
va_list ap;
FILE f;
+ struct __sfileext fext;
+ _FILEEXT_SETUP(&f, &fext);
f._file = -1;
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
diff --git a/lib/libc/stdio/sscanf.c b/lib/libc/stdio/sscanf.c
index b529cb762a6..0104e941e03 100644
--- a/lib/libc/stdio/sscanf.c
+++ b/lib/libc/stdio/sscanf.c
@@ -31,7 +31,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: sscanf.c,v 1.8 2005/03/31 18:36:29 pat Exp $";
+static char rcsid[] = "$OpenBSD: sscanf.c,v 1.9 2005/04/30 09:25:17 espie Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -53,12 +53,14 @@ sscanf(const char *str, const char *fmt, ...)
int ret;
va_list ap;
FILE f;
+ struct __sfileext fext;
+ _FILEEXT_SETUP(&f, &fext);
f._flags = __SRD;
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._r = strlen(str);
f._read = eofread;
- f._ub._base = NULL;
+ _UB(&f)._base = NULL;
f._lb._base = NULL;
va_start(ap, fmt);
ret = __svfscanf(&f, fmt, ap);
diff --git a/lib/libc/stdio/ungetc.c b/lib/libc/stdio/ungetc.c
index 3407aecb324..dc16a8ad562 100644
--- a/lib/libc/stdio/ungetc.c
+++ b/lib/libc/stdio/ungetc.c
@@ -31,7 +31,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: ungetc.c,v 1.6 2004/09/28 18:12:44 otto Exp $";
+static char rcsid[] = "$OpenBSD: ungetc.c,v 1.7 2005/04/30 09:25:17 espie Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -52,29 +52,29 @@ __submore(FILE *fp)
int i;
unsigned char *p;
- if (fp->_ub._base == fp->_ubuf) {
+ if (_UB(fp)._base == fp->_ubuf) {
/*
* Get a new buffer (rather than expanding the old one).
*/
if ((p = malloc((size_t)BUFSIZ)) == NULL)
return (EOF);
- fp->_ub._base = p;
- fp->_ub._size = BUFSIZ;
+ _UB(fp)._base = p;
+ _UB(fp)._size = BUFSIZ;
p += BUFSIZ - sizeof(fp->_ubuf);
for (i = sizeof(fp->_ubuf); --i >= 0;)
p[i] = fp->_ubuf[i];
fp->_p = p;
return (0);
}
- i = fp->_ub._size;
- p = realloc(fp->_ub._base, i << 1);
+ i = _UB(fp)._size;
+ p = realloc(_UB(fp)._base, i << 1);
if (p == NULL)
return (EOF);
/* no overlap (hence can use memcpy) because we doubled the size */
(void)memcpy((void *)(p + i), (void *)p, (size_t)i);
fp->_p = p + i;
- fp->_ub._base = p;
- fp->_ub._size = i << 1;
+ _UB(fp)._base = p;
+ _UB(fp)._size = i << 1;
return (0);
}
@@ -108,7 +108,7 @@ ungetc(int c, FILE *fp)
* This may require expanding the current ungetc buffer.
*/
if (HASUB(fp)) {
- if (fp->_r >= fp->_ub._size && __submore(fp))
+ if (fp->_r >= _UB(fp)._size && __submore(fp))
return (EOF);
*--fp->_p = c;
fp->_r++;
@@ -134,8 +134,8 @@ ungetc(int c, FILE *fp)
*/
fp->_ur = fp->_r;
fp->_up = fp->_p;
- fp->_ub._base = fp->_ubuf;
- fp->_ub._size = sizeof(fp->_ubuf);
+ _UB(fp)._base = fp->_ubuf;
+ _UB(fp)._size = sizeof(fp->_ubuf);
fp->_ubuf[sizeof(fp->_ubuf) - 1] = c;
fp->_p = &fp->_ubuf[sizeof(fp->_ubuf) - 1];
fp->_r = 1;
diff --git a/lib/libc/stdio/vasprintf.c b/lib/libc/stdio/vasprintf.c
index ee7f584efa2..f0145b9450c 100644
--- a/lib/libc/stdio/vasprintf.c
+++ b/lib/libc/stdio/vasprintf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vasprintf.c,v 1.9 2004/09/28 18:12:44 otto Exp $ */
+/* $OpenBSD: vasprintf.c,v 1.10 2005/04/30 09:25:17 espie Exp $ */
/*
* Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -17,20 +17,23 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: vasprintf.c,v 1.9 2004/09/28 18:12:44 otto Exp $";
+static char rcsid[] = "$OpenBSD: vasprintf.c,v 1.10 2005/04/30 09:25:17 espie Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
+#include "local.h"
int
vasprintf(char **str, const char *fmt, _BSD_VA_LIST_ ap)
{
int ret;
FILE f;
+ struct __sfileext fext;
unsigned char *_base;
+ _FILEEXT_SETUP(&f, &fext);
f._file = -1;
f._flags = __SWR | __SSTR | __SALC;
f._bf._base = f._p = (unsigned char *)malloc(128);
diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c
index d0dbcdc0709..0e6054613ec 100644
--- a/lib/libc/stdio/vfprintf.c
+++ b/lib/libc/stdio/vfprintf.c
@@ -31,7 +31,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: vfprintf.c,v 1.28 2004/09/28 18:12:44 otto Exp $";
+static char *rcsid = "$OpenBSD: vfprintf.c,v 1.29 2005/04/30 09:25:17 espie Exp $";
#endif /* LIBC_SCCS and not lint */
/*
@@ -86,8 +86,10 @@ __sbprintf(FILE *fp, const char *fmt, va_list ap)
{
int ret;
FILE fake;
+ struct __sfileext fakeext;
unsigned char buf[BUFSIZ];
+ _FILEEXT_SETUP(&fake, &fakeext);
/* copy the important variables */
fake._flags = fp->_flags & ~__SNBF;
fake._file = fp->_file;
diff --git a/lib/libc/stdio/vsnprintf.c b/lib/libc/stdio/vsnprintf.c
index 9454f7621fa..11d17f6a430 100644
--- a/lib/libc/stdio/vsnprintf.c
+++ b/lib/libc/stdio/vsnprintf.c
@@ -31,11 +31,12 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: vsnprintf.c,v 1.7 2004/09/28 18:12:44 otto Exp $";
+static char rcsid[] = "$OpenBSD: vsnprintf.c,v 1.8 2005/04/30 09:25:17 espie Exp $";
#endif /* LIBC_SCCS and not lint */
#include <limits.h>
#include <stdio.h>
+#include "local.h"
int
vsnprintf(char *str, size_t n, const char *fmt, _BSD_VA_LIST_ ap)
@@ -43,6 +44,9 @@ vsnprintf(char *str, size_t n, const char *fmt, _BSD_VA_LIST_ ap)
int ret;
char dummy;
FILE f;
+ struct __sfileext fext;
+
+ _FILEEXT_SETUP(&f, &fext);
/* While snprintf(3) specifies size_t stdio uses an int internally */
if (n > INT_MAX)
diff --git a/lib/libc/stdio/vsprintf.c b/lib/libc/stdio/vsprintf.c
index 8e4b6809127..958a12e8b67 100644
--- a/lib/libc/stdio/vsprintf.c
+++ b/lib/libc/stdio/vsprintf.c
@@ -31,11 +31,12 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: vsprintf.c,v 1.9 2004/09/28 18:12:44 otto Exp $";
+static char rcsid[] = "$OpenBSD: vsprintf.c,v 1.10 2005/04/30 09:25:17 espie Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#include <limits.h>
+#include "local.h"
#if defined(APIWARN)
__warn_references(vsprintf,
@@ -47,7 +48,9 @@ vsprintf(char *str, const char *fmt, _BSD_VA_LIST_ ap)
{
int ret;
FILE f;
+ struct __sfileext fext;
+ _FILEEXT_SETUP(&f, &fext);
f._file = -1;
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
diff --git a/lib/libc/stdio/vsscanf.c b/lib/libc/stdio/vsscanf.c
index a2c4da98626..34b54cb7dea 100644
--- a/lib/libc/stdio/vsscanf.c
+++ b/lib/libc/stdio/vsscanf.c
@@ -31,11 +31,12 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: vsscanf.c,v 1.6 2004/09/28 18:12:44 otto Exp $";
+static char rcsid[] = "$OpenBSD: vsscanf.c,v 1.7 2005/04/30 09:25:17 espie Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
#include <string.h>
+#include "local.h"
/* ARGSUSED */
static int
@@ -49,12 +50,14 @@ int
vsscanf(const char *str, const char *fmt, _BSD_VA_LIST_ ap)
{
FILE f;
+ struct __sfileext fext;
+ _FILEEXT_SETUP(&f, &fext);
f._flags = __SRD;
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._r = strlen(str);
f._read = eofread;
- f._ub._base = NULL;
+ _UB(&f)._base = NULL;
f._lb._base = NULL;
return (__svfscanf(&f, fmt, ap));
}