summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/stdio')
-rw-r--r--lib/libc/stdio/_flock_stub.c6
-rw-r--r--lib/libc/stdio/clrerr.c4
-rw-r--r--lib/libc/stdio/fclose.c14
-rw-r--r--lib/libc/stdio/fdopen.c2
-rw-r--r--lib/libc/stdio/fflush.c41
-rw-r--r--lib/libc/stdio/fgetc.c2
-rw-r--r--lib/libc/stdio/fgetpos.c2
-rw-r--r--lib/libc/stdio/fgets.c2
-rw-r--r--lib/libc/stdio/findfp.c57
-rw-r--r--lib/libc/stdio/flags.c3
-rw-r--r--lib/libc/stdio/fopen.c9
-rw-r--r--lib/libc/stdio/fpurge.c2
-rw-r--r--lib/libc/stdio/fputc.c2
-rw-r--r--lib/libc/stdio/fputs.c2
-rw-r--r--lib/libc/stdio/fread.c2
-rw-r--r--lib/libc/stdio/freopen.c6
-rw-r--r--lib/libc/stdio/fscanf.c2
-rw-r--r--lib/libc/stdio/fseek.c48
-rw-r--r--lib/libc/stdio/ftell.c2
-rw-r--r--lib/libc/stdio/funopen.c3
-rw-r--r--lib/libc/stdio/fvwrite.c6
-rw-r--r--lib/libc/stdio/fwalk.c16
-rw-r--r--lib/libc/stdio/fwrite.c2
-rw-r--r--lib/libc/stdio/getc.c6
-rw-r--r--lib/libc/stdio/getchar.c2
-rw-r--r--lib/libc/stdio/gets.c2
-rw-r--r--lib/libc/stdio/local.h8
-rw-r--r--lib/libc/stdio/makebuf.c8
-rw-r--r--lib/libc/stdio/mktemp.c2
-rw-r--r--lib/libc/stdio/perror.c6
-rw-r--r--lib/libc/stdio/putc.c11
-rw-r--r--lib/libc/stdio/putchar.c12
-rw-r--r--lib/libc/stdio/puts.c2
-rw-r--r--lib/libc/stdio/putw.c2
-rw-r--r--lib/libc/stdio/refill.c1
-rw-r--r--lib/libc/stdio/rewind.c10
-rw-r--r--lib/libc/stdio/scanf.c2
-rw-r--r--lib/libc/stdio/setvbuf.c2
-rw-r--r--lib/libc/stdio/stdio.c2
-rw-r--r--lib/libc/stdio/tmpfile.c6
-rw-r--r--lib/libc/stdio/ungetc.c46
-rw-r--r--lib/libc/stdio/vasprintf.c3
-rw-r--r--lib/libc/stdio/vfprintf.c111
-rw-r--r--lib/libc/stdio/vfscanf.c48
-rw-r--r--lib/libc/stdio/vscanf.c2
-rw-r--r--lib/libc/stdio/vsnprintf.c3
-rw-r--r--lib/libc/stdio/vsprintf.c3
-rw-r--r--lib/libc/stdio/wbuf.c6
48 files changed, 351 insertions, 190 deletions
diff --git a/lib/libc/stdio/_flock_stub.c b/lib/libc/stdio/_flock_stub.c
index ada714c..83a3e86 100644
--- a/lib/libc/stdio/_flock_stub.c
+++ b/lib/libc/stdio/_flock_stub.c
@@ -35,16 +35,17 @@
#include <stdio.h>
-/* Don't build this in libc_r, just libc: */
-#ifndef _THREAD_SAFE
/*
* Declare weak references in case the application is not linked
* with libpthread.
*/
#pragma weak flockfile=_flockfile_stub
+#pragma weak _flockfile=_flockfile_stub
#pragma weak _flockfile_debug=_flockfile_debug_stub
#pragma weak ftrylockfile=_ftrylockfile_stub
+#pragma weak _ftrylockfile=_ftrylockfile_stub
#pragma weak funlockfile=_funlockfile_stub
+#pragma weak _funlockfile=_funlockfile_stub
/*
* This function is a stub for the _flockfile function in libpthread.
@@ -78,4 +79,3 @@ void
_funlockfile_stub(FILE *fp)
{
}
-#endif
diff --git a/lib/libc/stdio/clrerr.c b/lib/libc/stdio/clrerr.c
index 4e6b720..3232088 100644
--- a/lib/libc/stdio/clrerr.c
+++ b/lib/libc/stdio/clrerr.c
@@ -42,9 +42,11 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <stdio.h>
-#undef clearerr
+#include "un-namespace.h"
#include "libc_private.h"
+#undef clearerr
void
clearerr(fp)
diff --git a/lib/libc/stdio/fclose.c b/lib/libc/stdio/fclose.c
index 8ddb98b..0d6fd80 100644
--- a/lib/libc/stdio/fclose.c
+++ b/lib/libc/stdio/fclose.c
@@ -42,17 +42,19 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
-#include "local.h"
+#include "un-namespace.h"
#include "libc_private.h"
+#include "local.h"
int
fclose(fp)
- register FILE *fp;
+ FILE *fp;
{
- register int r;
+ int r;
if (fp->_flags == 0) { /* not open! */
errno = EBADF;
@@ -71,6 +73,12 @@ fclose(fp)
FUNLOCKFILE(fp);
fp->_file = -1;
fp->_r = fp->_w = 0; /* Mess up if reaccessed. */
+#if 0
+ if (fp->_lock != NULL) {
+ _pthread_mutex_destroy((pthread_mutex_t *)&fp->_lock);
+ fp->_lock = NULL;
+ }
+#endif
fp->_flags = 0; /* Release this FILE for reuse. */
return (r);
}
diff --git a/lib/libc/stdio/fdopen.c b/lib/libc/stdio/fdopen.c
index 44341b3..2e72e71 100644
--- a/lib/libc/stdio/fdopen.c
+++ b/lib/libc/stdio/fdopen.c
@@ -40,11 +40,13 @@
static char sccsid[] = "@(#)fdopen.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
+#include "un-namespace.h"
#include "local.h"
FILE *
diff --git a/lib/libc/stdio/fflush.c b/lib/libc/stdio/fflush.c
index cd7fbe8..09d346b 100644
--- a/lib/libc/stdio/fflush.c
+++ b/lib/libc/stdio/fflush.c
@@ -42,15 +42,19 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <errno.h>
#include <stdio.h>
-#include "local.h"
+#include "un-namespace.h"
#include "libc_private.h"
+#include "local.h"
-/* Flush a single file, or (if fp is NULL) all files. */
+/*
+ * Flush a single file, or (if fp is NULL) all files.
+ * MT-safe version
+ */
int
-fflush(fp)
- register FILE *fp;
+fflush(FILE *fp)
{
int retval;
@@ -60,19 +64,36 @@ fflush(fp)
if ((fp->_flags & (__SWR | __SRW)) == 0) {
errno = EBADF;
retval = EOF;
- } else {
+ } else
retval = __sflush(fp);
- }
FUNLOCKFILE(fp);
return (retval);
}
+/*
+ * Flush a single file, or (if fp is NULL) all files.
+ * Non-MT-safe version
+ */
+int
+__fflush(FILE *fp)
+{
+ int retval;
+
+ if (fp == NULL)
+ return (_fwalk(__sflush));
+ if ((fp->_flags & (__SWR | __SRW)) == 0) {
+ errno = EBADF;
+ retval = EOF;
+ } else
+ retval = __sflush(fp);
+ return (retval);
+}
+
int
-__sflush(fp)
- register FILE *fp;
+__sflush(FILE *fp)
{
- register unsigned char *p;
- register int n, t;
+ unsigned char *p;
+ int n, t;
t = fp->_flags;
if ((t & __SWR) == 0)
diff --git a/lib/libc/stdio/fgetc.c b/lib/libc/stdio/fgetc.c
index 4e52705..a367af3 100644
--- a/lib/libc/stdio/fgetc.c
+++ b/lib/libc/stdio/fgetc.c
@@ -42,7 +42,9 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <stdio.h>
+#include "un-namespace.h"
#include "libc_private.h"
int
diff --git a/lib/libc/stdio/fgetpos.c b/lib/libc/stdio/fgetpos.c
index 6d6cfa1..239f6d1 100644
--- a/lib/libc/stdio/fgetpos.c
+++ b/lib/libc/stdio/fgetpos.c
@@ -42,7 +42,9 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <stdio.h>
+#include "un-namespace.h"
#include "libc_private.h"
int
diff --git a/lib/libc/stdio/fgets.c b/lib/libc/stdio/fgets.c
index 33b7144..ccf5535 100644
--- a/lib/libc/stdio/fgets.c
+++ b/lib/libc/stdio/fgets.c
@@ -42,8 +42,10 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <stdio.h>
#include <string.h>
+#include "un-namespace.h"
#include "local.h"
#include "libc_private.h"
diff --git a/lib/libc/stdio/findfp.c b/lib/libc/stdio/findfp.c
index 3cc08a9..50edcb6 100644
--- a/lib/libc/stdio/findfp.c
+++ b/lib/libc/stdio/findfp.c
@@ -43,15 +43,15 @@ static const char rcsid[] =
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
+#include <machine/atomic.h>
#include <unistd.h>
#include <stdio.h>
-#include <errno.h>
#include <stdlib.h>
#include <string.h>
-#include <libc_private.h>
#include <spinlock.h>
+#include "libc_private.h"
#include "local.h"
#include "glue.h"
@@ -65,7 +65,7 @@ int __sdidinit;
/* the usual - (stdin + stdout + stderr) */
static FILE usual[FOPEN_MAX - 3];
-static struct glue uglue = { 0, FOPEN_MAX - 3, usual };
+static struct glue uglue = { NULL, FOPEN_MAX - 3, usual };
FILE __sF[3] = {
std(__SRD, STDIN_FILENO), /* stdin */
@@ -73,6 +73,7 @@ FILE __sF[3] = {
std(__SWR|__SNBF, STDERR_FILENO) /* stderr */
};
struct glue __sglue = { &uglue, 3, __sF };
+static struct glue *lastglue = &uglue;
static struct glue * moreglue __P((int));
@@ -80,12 +81,18 @@ static spinlock_t thread_lock = _SPINLOCK_INITIALIZER;
#define THREAD_LOCK() if (__isthreaded) _SPINLOCK(&thread_lock)
#define THREAD_UNLOCK() if (__isthreaded) _SPINUNLOCK(&thread_lock)
+#if NOT_YET
+#define SET_GLUE_PTR(ptr, val) atomic_set_ptr(&(ptr), (uintptr_t)(val))
+#else
+#define SET_GLUE_PTR(ptr, val) ptr = val
+#endif
+
static struct glue *
moreglue(n)
- register int n;
+ int n;
{
- register struct glue *g;
- register FILE *p;
+ struct glue *g;
+ FILE *p;
static FILE empty;
g = (struct glue *)malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE));
@@ -106,22 +113,28 @@ moreglue(n)
FILE *
__sfp()
{
- register FILE *fp;
- register int n;
- register struct glue *g;
+ FILE *fp;
+ int n;
+ struct glue *g;
if (!__sdidinit)
__sinit();
+ /*
+ * The list must be locked because a FILE may be updated.
+ */
THREAD_LOCK();
- for (g = &__sglue;; g = g->next) {
+ for (g = &__sglue; g != NULL; g = g->next) {
for (fp = g->iobs, n = g->niobs; --n >= 0; fp++)
if (fp->_flags == 0)
goto found;
- if (g->next == NULL && (g->next = moreglue(NDYNAMIC)) == NULL)
- break;
}
- THREAD_UNLOCK();
- return (NULL);
+ THREAD_UNLOCK(); /* don't hold lock while malloc()ing. */
+ if ((g == moreglue(NDYNAMIC)) == NULL)
+ return (NULL);
+ THREAD_LOCK(); /* reacquire the lock */
+ SET_GLUE_PTR(lastglue->next, g); /* atomically append glue to list */
+ lastglue = g; /* not atomic; only accessed when locked */
+ fp = g->iobs;
found:
fp->_flags = 1; /* reserve this slot; caller sets real flags */
THREAD_UNLOCK();
@@ -137,6 +150,7 @@ found:
fp->_ub._size = 0;
fp->_lb._base = NULL; /* no line buffer */
fp->_lb._size = 0;
+ /* fp->_lock = NULL; */
return (fp);
}
@@ -150,14 +164,23 @@ __warn_references(f_prealloc,
void
f_prealloc()
{
- register struct glue *g;
+ struct glue *g;
int n;
n = getdtablesize() - FOPEN_MAX + 20; /* 20 for slop. */
+ /*
+ * It should be safe to walk the list without locking it;
+ * new nodes are only added to the end and none are ever
+ * removed.
+ */
for (g = &__sglue; (n -= g->niobs) > 0 && g->next; g = g->next)
/* void */;
- if (n > 0)
- g->next = moreglue(n);
+ if ((n > 0) && ((g = moreglue(n)) != NULL)) {
+ THREAD_LOCK();
+ SET_GLUE_PTR(lastglue->next, g);
+ lastglue = g;
+ THREAD_UNLOCK();
+ }
}
/*
diff --git a/lib/libc/stdio/flags.c b/lib/libc/stdio/flags.c
index afcc4d8..4f39460 100644
--- a/lib/libc/stdio/flags.c
+++ b/lib/libc/stdio/flags.c
@@ -46,11 +46,12 @@ static const char rcsid[] =
#include <sys/file.h>
#include <stdio.h>
#include <errno.h>
+
#include "local.h"
/*
* Return the (stdio) flags for a given mode. Store the flags
- * to be passed to an open() syscall through *optr.
+ * to be passed to an _open() syscall through *optr.
* Return 0 on error.
*/
int
diff --git a/lib/libc/stdio/fopen.c b/lib/libc/stdio/fopen.c
index 1ef6bda..4ea2eb9 100644
--- a/lib/libc/stdio/fopen.c
+++ b/lib/libc/stdio/fopen.c
@@ -40,11 +40,14 @@
static char sccsid[] = "@(#)fopen.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
+#include "un-namespace.h"
+
#include "local.h"
FILE *
@@ -52,8 +55,8 @@ fopen(file, mode)
const char *file;
const char *mode;
{
- register FILE *fp;
- register int f;
+ FILE *fp;
+ int f;
int flags, oflags;
if ((flags = __sflags(mode, &oflags)) == 0)
@@ -71,7 +74,7 @@ fopen(file, mode)
fp->_write = __swrite;
fp->_seek = __sseek;
fp->_close = __sclose;
-
+ /* fp->_lock = NULL; */
/*
* When opening in append mode, even though we use O_APPEND,
* we need to seek to the end so that ftell() gets the right
diff --git a/lib/libc/stdio/fpurge.c b/lib/libc/stdio/fpurge.c
index acf0b8b..4959098 100644
--- a/lib/libc/stdio/fpurge.c
+++ b/lib/libc/stdio/fpurge.c
@@ -42,9 +42,11 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
+#include "un-namespace.h"
#include "local.h"
#include "libc_private.h"
diff --git a/lib/libc/stdio/fputc.c b/lib/libc/stdio/fputc.c
index 60079f1..24eb560 100644
--- a/lib/libc/stdio/fputc.c
+++ b/lib/libc/stdio/fputc.c
@@ -42,7 +42,9 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <stdio.h>
+#include "un-namespace.h"
#include "libc_private.h"
int
diff --git a/lib/libc/stdio/fputs.c b/lib/libc/stdio/fputs.c
index 63a5321..0967c6a 100644
--- a/lib/libc/stdio/fputs.c
+++ b/lib/libc/stdio/fputs.c
@@ -42,8 +42,10 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <stdio.h>
#include <string.h>
+#include "un-namespace.h"
#include "fvwrite.h"
#include "libc_private.h"
diff --git a/lib/libc/stdio/fread.c b/lib/libc/stdio/fread.c
index 886a9fc..f7e8985 100644
--- a/lib/libc/stdio/fread.c
+++ b/lib/libc/stdio/fread.c
@@ -42,8 +42,10 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <stdio.h>
#include <string.h>
+#include "un-namespace.h"
#include "local.h"
#include "libc_private.h"
diff --git a/lib/libc/stdio/freopen.c b/lib/libc/stdio/freopen.c
index f6fa754..fd8612c 100644
--- a/lib/libc/stdio/freopen.c
+++ b/lib/libc/stdio/freopen.c
@@ -42,6 +42,7 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -49,7 +50,8 @@ static const char rcsid[] =
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
-#include <libc_private.h>
+#include "un-namespace.h"
+#include "libc_private.h"
#include "local.h"
/*
@@ -146,7 +148,7 @@ freopen(file, mode, fp)
* assume stderr is always fd STDERR_FILENO, even if being freopen'd.
*/
if (wantfd >= 0 && f != wantfd) {
- if (dup2(f, wantfd) >= 0) {
+ if (_dup2(f, wantfd) >= 0) {
(void)_close(f);
f = wantfd;
}
diff --git a/lib/libc/stdio/fscanf.c b/lib/libc/stdio/fscanf.c
index 8b7b941..45c399a 100644
--- a/lib/libc/stdio/fscanf.c
+++ b/lib/libc/stdio/fscanf.c
@@ -42,12 +42,14 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <stdio.h>
#if __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
+#include "un-namespace.h"
#include "libc_private.h"
#if __STDC__
diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c
index 8c2732e..f873975 100644
--- a/lib/libc/stdio/fseek.c
+++ b/lib/libc/stdio/fseek.c
@@ -42,12 +42,14 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
+#include "un-namespace.h"
#include "local.h"
#include "libc_private.h"
@@ -62,13 +64,31 @@ fseek(fp, offset, whence)
return (fseeko(fp, offset, whence));
}
+int
+fseeko(fp, offset, whence)
+ FILE *fp;
+ off_t offset;
+ int whence;
+{
+ int ret;
+
+ /* make sure stdio is set up */
+ if (!__sdidinit)
+ __sinit();
+
+ FLOCKFILE(fp);
+ ret = _fseeko(fp, offset, whence);
+ FUNLOCKFILE(fp);
+ return (ret);
+}
+
/*
* Seek the given file to the given offset.
* `Whence' must be one of the three SEEK_* macros.
*/
int
-fseeko(fp, offset, whence)
- register FILE *fp;
+_fseeko(fp, offset, whence)
+ FILE *fp;
off_t offset;
int whence;
{
@@ -78,17 +98,11 @@ fseeko(fp, offset, whence)
struct stat st;
int havepos;
- /* make sure stdio is set up */
- if (!__sdidinit)
- __sinit();
-
- FLOCKFILE(fp);
/*
* Have to be able to seek.
*/
if ((seekfn = fp->_seek) == NULL) {
- errno = ESPIPE; /* historic practice */
- FUNLOCKFILE(fp);
+ errno = ESPIPE; /* historic practice */
return (EOF);
}
@@ -108,10 +122,8 @@ fseeko(fp, offset, whence)
curoff = fp->_offset;
else {
curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR);
- if (curoff == -1) {
- FUNLOCKFILE(fp);
+ if (curoff == -1)
return (EOF);
- }
}
if (fp->_flags & __SRD) {
curoff -= fp->_r;
@@ -133,7 +145,6 @@ fseeko(fp, offset, whence)
default:
errno = EINVAL;
- FUNLOCKFILE(fp);
return (EOF);
}
@@ -151,7 +162,7 @@ fseeko(fp, offset, whence)
goto dumb;
if ((fp->_flags & __SOPT) == 0) {
if (seekfn != __sseek ||
- fp->_file < 0 || fstat(fp->_file, &st) ||
+ fp->_file < 0 || _fstat(fp->_file, &st) ||
(st.st_mode & S_IFMT) != S_IFREG) {
fp->_flags |= __SNPT;
goto dumb;
@@ -167,7 +178,7 @@ fseeko(fp, offset, whence)
if (whence == SEEK_SET)
target = offset;
else {
- if (fstat(fp->_file, &st))
+ if (_fstat(fp->_file, &st))
goto dumb;
target = st.st_size + offset;
}
@@ -217,7 +228,6 @@ fseeko(fp, offset, whence)
if (HASUB(fp))
FREEUB(fp);
fp->_flags &= ~__SEOF;
- FUNLOCKFILE(fp);
return (0);
}
@@ -244,7 +254,6 @@ fseeko(fp, offset, whence)
fp->_p += n;
fp->_r -= n;
}
- FUNLOCKFILE(fp);
return (0);
/*
@@ -253,10 +262,8 @@ fseeko(fp, offset, whence)
*/
dumb:
if (__sflush(fp) ||
- (*seekfn)(fp->_cookie, (fpos_t)offset, whence) == POS_ERR) {
- FUNLOCKFILE(fp);
+ (*seekfn)(fp->_cookie, (fpos_t)offset, whence) == POS_ERR)
return (EOF);
- }
/* success: clear EOF indicator and discard ungetc() data */
if (HASUB(fp))
FREEUB(fp);
@@ -264,6 +271,5 @@ dumb:
fp->_r = 0;
/* fp->_w = 0; */ /* unnecessary (I think...) */
fp->_flags &= ~__SEOF;
- FUNLOCKFILE(fp);
return (0);
}
diff --git a/lib/libc/stdio/ftell.c b/lib/libc/stdio/ftell.c
index 9057f89..e4a4e11 100644
--- a/lib/libc/stdio/ftell.c
+++ b/lib/libc/stdio/ftell.c
@@ -42,9 +42,11 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <sys/types.h>
#include <stdio.h>
#include <errno.h>
+#include "un-namespace.h"
#include "local.h"
#include "libc_private.h"
diff --git a/lib/libc/stdio/funopen.c b/lib/libc/stdio/funopen.c
index 4d65b68..f66c60e 100644
--- a/lib/libc/stdio/funopen.c
+++ b/lib/libc/stdio/funopen.c
@@ -32,6 +32,8 @@
* 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.
+ *
+ * $FreeBSD$
*/
#if defined(LIBC_SCCS) && !defined(lint)
@@ -40,6 +42,7 @@ static char sccsid[] = "@(#)funopen.c 8.1 (Berkeley) 6/4/93";
#include <stdio.h>
#include <errno.h>
+
#include "local.h"
FILE *
diff --git a/lib/libc/stdio/fvwrite.c b/lib/libc/stdio/fvwrite.c
index 75d7191..82a49cb 100644
--- a/lib/libc/stdio/fvwrite.c
+++ b/lib/libc/stdio/fvwrite.c
@@ -143,7 +143,7 @@ __sfvwrite(fp, uio)
COPY(w);
/* fp->_w -= w; */ /* unneeded */
fp->_p += w;
- if (fflush(fp))
+ if (__fflush(fp))
goto err;
} else if (len >= (w = fp->_bf._size)) {
/* write directly */
@@ -183,7 +183,7 @@ __sfvwrite(fp, uio)
COPY(w);
/* fp->_w -= w; */
fp->_p += w;
- if (fflush(fp))
+ if (__fflush(fp))
goto err;
} else if (s >= (w = fp->_bf._size)) {
w = (*fp->_write)(fp->_cookie, p, w);
@@ -197,7 +197,7 @@ __sfvwrite(fp, uio)
}
if ((nldist -= w) == 0) {
/* copied the newline: flush and forget */
- if (fflush(fp))
+ if (__fflush(fp))
goto err;
nlknown = 0;
}
diff --git a/lib/libc/stdio/fwalk.c b/lib/libc/stdio/fwalk.c
index b1a25d1..17cb5ce 100644
--- a/lib/libc/stdio/fwalk.c
+++ b/lib/libc/stdio/fwalk.c
@@ -42,20 +42,26 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
-#include <errno.h>
+#include <sys/types.h>
+#include <machine/atomic.h>
#include <stdio.h>
#include "local.h"
#include "glue.h"
int
_fwalk(function)
- register int (*function)(FILE *);
+ int (*function)(FILE *);
{
- register FILE *fp;
- register int n, ret;
- register struct glue *g;
+ FILE *fp;
+ int n, ret;
+ struct glue *g;
ret = 0;
+ /*
+ * It should be safe to walk the list without locking it;
+ * new nodes are only added to the end and none are ever
+ * removed.
+ */
for (g = &__sglue; g != NULL; g = g->next)
for (fp = g->iobs, n = g->niobs; --n >= 0; fp++)
if (fp->_flags != 0)
diff --git a/lib/libc/stdio/fwrite.c b/lib/libc/stdio/fwrite.c
index 681b9d3..13653b6 100644
--- a/lib/libc/stdio/fwrite.c
+++ b/lib/libc/stdio/fwrite.c
@@ -42,7 +42,9 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <stdio.h>
+#include "un-namespace.h"
#include "local.h"
#include "fvwrite.h"
#include "libc_private.h"
diff --git a/lib/libc/stdio/getc.c b/lib/libc/stdio/getc.c
index eff320a..1668407 100644
--- a/lib/libc/stdio/getc.c
+++ b/lib/libc/stdio/getc.c
@@ -42,14 +42,12 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <stdio.h>
+#include "un-namespace.h"
#include "libc_private.h"
-/*
- * A subroutine version of the macro getc.
- */
#undef getc
-
int
getc(fp)
register FILE *fp;
diff --git a/lib/libc/stdio/getchar.c b/lib/libc/stdio/getchar.c
index ec8810d..92f714e 100644
--- a/lib/libc/stdio/getchar.c
+++ b/lib/libc/stdio/getchar.c
@@ -45,7 +45,9 @@ static const char rcsid[] =
/*
* A subroutine version of the macro getchar.
*/
+#include "namespace.h"
#include <stdio.h>
+#include "un-namespace.h"
#include "libc_private.h"
#undef getchar
diff --git a/lib/libc/stdio/gets.c b/lib/libc/stdio/gets.c
index 1f9be80..7a368cf 100644
--- a/lib/libc/stdio/gets.c
+++ b/lib/libc/stdio/gets.c
@@ -42,9 +42,11 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <unistd.h>
#include <stdio.h>
#include <sys/cdefs.h>
+#include "un-namespace.h"
__warn_references(gets, "warning: this program uses gets(), which is unsafe.");
diff --git a/lib/libc/stdio/local.h b/lib/libc/stdio/local.h
index cbc07a9..2f95a58 100644
--- a/lib/libc/stdio/local.h
+++ b/lib/libc/stdio/local.h
@@ -34,13 +34,19 @@
* SUCH DAMAGE.
*
* @(#)local.h 8.3 (Berkeley) 7/3/94
+ *
+ * $FreeBSD$
*/
+#include <sys/types.h> /* for off_t */
+
/*
* Information local to this implementation of stdio,
* in particular, macros and private variables.
*/
+extern int _fseeko __P((FILE *, off_t, int));
+extern int __fflush __P((FILE *fp));
extern int __sflush __P((FILE *));
extern FILE *__sfp __P((void));
extern int __srefill __P((FILE *));
@@ -56,6 +62,8 @@ extern int __swhatbuf __P((FILE *, size_t *, int *));
extern int _fwalk __P((int (*)(FILE *)));
extern int __swsetup __P((FILE *));
extern int __sflags __P((const char *, int *));
+extern int __ungetc __P((int, FILE *));
+extern int __vfprintf __P((FILE *, const char *, _BSD_VA_LIST_));
extern int __sdidinit;
diff --git a/lib/libc/stdio/makebuf.c b/lib/libc/stdio/makebuf.c
index 7dcbd70..34fe8e6 100644
--- a/lib/libc/stdio/makebuf.c
+++ b/lib/libc/stdio/makebuf.c
@@ -32,25 +32,29 @@
* 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.
+ *
+ * $FreeBSD$
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)makebuf.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include "local.h"
+#include "un-namespace.h"
/*
* Allocate a file buffer, or switch to unbuffered I/O.
* Per the ANSI C standard, ALL tty devices default to line buffered.
*
* As a side effect, we set __SOPT or __SNPT (en/dis-able fseek
- * optimisation) right after the fstat() that finds the buffer size.
+ * optimisation) right after the _fstat() that finds the buffer size.
*/
void
__smakebuf(fp)
@@ -93,7 +97,7 @@ __swhatbuf(fp, bufsize, couldbetty)
{
struct stat st;
- if (fp->_file < 0 || fstat(fp->_file, &st) < 0) {
+ if (fp->_file < 0 || _fstat(fp->_file, &st) < 0) {
*couldbetty = 0;
*bufsize = BUFSIZ;
return (__SNPT);
diff --git a/lib/libc/stdio/mktemp.c b/lib/libc/stdio/mktemp.c
index 870e4db..e4c8c28 100644
--- a/lib/libc/stdio/mktemp.c
+++ b/lib/libc/stdio/mktemp.c
@@ -39,6 +39,7 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+/* #include "namespace.h" */
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -48,6 +49,7 @@ static const char rcsid[] =
#include <string.h>
#include <ctype.h>
#include <unistd.h>
+/* #include "un-namespace.h" */
char *_mktemp __P((char *));
diff --git a/lib/libc/stdio/perror.c b/lib/libc/stdio/perror.c
index bb61824..c137e06 100644
--- a/lib/libc/stdio/perror.c
+++ b/lib/libc/stdio/perror.c
@@ -29,18 +29,22 @@
* 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.
+ *
+ * $FreeBSD$
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)perror.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
+#include "un-namespace.h"
void
perror(s)
@@ -63,5 +67,5 @@ perror(s)
v++;
v->iov_base = "\n";
v->iov_len = 1;
- (void)writev(STDERR_FILENO, iov, (v - iov) + 1);
+ (void)_writev(STDERR_FILENO, iov, (v - iov) + 1);
}
diff --git a/lib/libc/stdio/putc.c b/lib/libc/stdio/putc.c
index fe1591c..72d6bbf 100644
--- a/lib/libc/stdio/putc.c
+++ b/lib/libc/stdio/putc.c
@@ -42,14 +42,19 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <stdio.h>
+#include "un-namespace.h"
#include "libc_private.h"
/*
- * A subroutine version of the macro putc.
+ * putc has traditionally been a macro in <stdio.h>. That is no
+ * longer true because POSIX requires it to be thread-safe. POSIX
+ * does define putc_unlocked() which is defined as a macro and is
+ * probably what you want to use instead.
+ *
+ * #undef putc
*/
-#undef putc
-
int
putc(c, fp)
int c;
diff --git a/lib/libc/stdio/putchar.c b/lib/libc/stdio/putchar.c
index cebd872..a611fbb 100644
--- a/lib/libc/stdio/putchar.c
+++ b/lib/libc/stdio/putchar.c
@@ -42,11 +42,19 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <stdio.h>
+#include "un-namespace.h"
#include "libc_private.h"
-#undef putchar
-
+/*
+ * putchar has traditionally been a macro in <stdio.h>. That is no
+ * longer true because POSIX requires it to be thread-safe. POSIX
+ * does define putchar_unlocked() which is defined as a macro and is
+ * probably what you want to use instead.
+ *
+ * #undef putchar
+ */
/*
* A subroutine version of the macro putchar
*/
diff --git a/lib/libc/stdio/puts.c b/lib/libc/stdio/puts.c
index 59f153d..cdf1b53 100644
--- a/lib/libc/stdio/puts.c
+++ b/lib/libc/stdio/puts.c
@@ -42,8 +42,10 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <stdio.h>
#include <string.h>
+#include "un-namespace.h"
#include "fvwrite.h"
#include "libc_private.h"
diff --git a/lib/libc/stdio/putw.c b/lib/libc/stdio/putw.c
index 8eac4cf..a7e93b7 100644
--- a/lib/libc/stdio/putw.c
+++ b/lib/libc/stdio/putw.c
@@ -42,7 +42,9 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <stdio.h>
+#include "un-namespace.h"
#include "fvwrite.h"
#include "libc_private.h"
diff --git a/lib/libc/stdio/refill.c b/lib/libc/stdio/refill.c
index 8793830..2db485bba 100644
--- a/lib/libc/stdio/refill.c
+++ b/lib/libc/stdio/refill.c
@@ -45,6 +45,7 @@ static const char rcsid[] =
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
+
#include "local.h"
static int lflush __P((FILE *));
diff --git a/lib/libc/stdio/rewind.c b/lib/libc/stdio/rewind.c
index 98c5846..c4de2c1 100644
--- a/lib/libc/stdio/rewind.c
+++ b/lib/libc/stdio/rewind.c
@@ -42,17 +42,19 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <errno.h>
#include <stdio.h>
+#include "un-namespace.h"
#include "libc_private.h"
+#include "local.h"
void
-rewind(fp)
- register FILE *fp;
+rewind(FILE *fp)
{
FLOCKFILE(fp);
- (void) fseek(fp, 0L, SEEK_SET);
+ (void) _fseeko(fp, (off_t)0, SEEK_SET);
clearerr(fp);
FUNLOCKFILE(fp);
- errno = 0; /* not required, but seems reasonable */
+ errno = 0; /* not required, but seems reasonable */
}
diff --git a/lib/libc/stdio/scanf.c b/lib/libc/stdio/scanf.c
index b183c17..fac6cee 100644
--- a/lib/libc/stdio/scanf.c
+++ b/lib/libc/stdio/scanf.c
@@ -42,12 +42,14 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <stdio.h>
#if __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
+#include "un-namespace.h"
#include "libc_private.h"
#if __STDC__
diff --git a/lib/libc/stdio/setvbuf.c b/lib/libc/stdio/setvbuf.c
index 4693b9f..f25391f 100644
--- a/lib/libc/stdio/setvbuf.c
+++ b/lib/libc/stdio/setvbuf.c
@@ -42,8 +42,10 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <stdio.h>
#include <stdlib.h>
+#include "un-namespace.h"
#include "local.h"
#include "libc_private.h"
diff --git a/lib/libc/stdio/stdio.c b/lib/libc/stdio/stdio.c
index b8a3f47..57be5bb 100644
--- a/lib/libc/stdio/stdio.c
+++ b/lib/libc/stdio/stdio.c
@@ -42,9 +42,11 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
+#include "un-namespace.h"
#include "local.h"
/*
diff --git a/lib/libc/stdio/tmpfile.c b/lib/libc/stdio/tmpfile.c
index a0162c2..e3e296b 100644
--- a/lib/libc/stdio/tmpfile.c
+++ b/lib/libc/stdio/tmpfile.c
@@ -40,6 +40,7 @@
static char sccsid[] = "@(#)tmpfile.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>
@@ -47,6 +48,7 @@ static char sccsid[] = "@(#)tmpfile.c 8.1 (Berkeley) 6/4/93";
#include <stdio.h>
#include <string.h>
#include <paths.h>
+#include "un-namespace.h"
FILE *
tmpfile()
@@ -61,13 +63,13 @@ tmpfile()
(void)memcpy(buf + sizeof(_PATH_TMP) - 1, TRAILER, sizeof(TRAILER));
sigfillset(&set);
- (void)sigprocmask(SIG_BLOCK, &set, &oset);
+ (void)_sigprocmask(SIG_BLOCK, &set, &oset);
fd = mkstemp(buf);
if (fd != -1)
(void)unlink(buf);
- (void)sigprocmask(SIG_SETMASK, &oset, NULL);
+ (void)_sigprocmask(SIG_SETMASK, &oset, NULL);
if (fd == -1)
return (NULL);
diff --git a/lib/libc/stdio/ungetc.c b/lib/libc/stdio/ungetc.c
index 3f4b32c..872abad 100644
--- a/lib/libc/stdio/ungetc.c
+++ b/lib/libc/stdio/ungetc.c
@@ -42,9 +42,11 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "un-namespace.h"
#include "local.h"
#include "libc_private.h"
@@ -57,11 +59,10 @@ static int __submore __P((FILE *));
* are all at the end (stack-style).
*/
static int
-__submore(fp)
- register FILE *fp;
+__submore(FILE *fp)
{
- register int i;
- register unsigned char *p;
+ int i;
+ unsigned char *p;
if (fp->_ub._base == fp->_ubuf) {
/*
@@ -89,30 +90,42 @@ __submore(fp)
return (0);
}
+/*
+ * MT-safe version
+ */
int
-ungetc(c, fp)
- int c;
- register FILE *fp;
+ungetc(int c, FILE *fp)
{
+ int ret;
+
if (c == EOF)
return (EOF);
if (!__sdidinit)
__sinit();
FLOCKFILE(fp);
+ ret = __ungetc(c, fp);
+ FUNLOCKFILE(fp);
+ return (ret);
+}
+
+/*
+ * Non-MT-safe version
+ */
+int
+__ungetc(int c, FILE *fp)
+{
+ if (c == EOF)
+ return (EOF);
if ((fp->_flags & __SRD) == 0) {
/*
* Not already reading: no good unless reading-and-writing.
* Otherwise, flush any current write stuff.
*/
- if ((fp->_flags & __SRW) == 0) {
- FUNLOCKFILE(fp);
+ if ((fp->_flags & __SRW) == 0)
return (EOF);
- }
if (fp->_flags & __SWR) {
- if (__sflush(fp)) {
- FUNLOCKFILE(fp);
+ if (__sflush(fp))
return (EOF);
- }
fp->_flags &= ~__SWR;
fp->_w = 0;
fp->_lbfsize = 0;
@@ -126,13 +139,10 @@ ungetc(c, fp)
* This may require expanding the current ungetc buffer.
*/
if (HASUB(fp)) {
- if (fp->_r >= fp->_ub._size && __submore(fp)) {
- FUNLOCKFILE(fp);
+ if (fp->_r >= fp->_ub._size && __submore(fp))
return (EOF);
- }
*--fp->_p = c;
fp->_r++;
- FUNLOCKFILE(fp);
return (c);
}
fp->_flags &= ~__SEOF;
@@ -146,7 +156,6 @@ ungetc(c, fp)
fp->_p[-1] == c) {
fp->_p--;
fp->_r++;
- FUNLOCKFILE(fp);
return (c);
}
@@ -161,6 +170,5 @@ ungetc(c, fp)
fp->_ubuf[sizeof(fp->_ubuf) - 1] = c;
fp->_p = &fp->_ubuf[sizeof(fp->_ubuf) - 1];
fp->_r = 1;
- FUNLOCKFILE(fp);
return (c);
}
diff --git a/lib/libc/stdio/vasprintf.c b/lib/libc/stdio/vasprintf.c
index 37fb0fd..98180cb 100644
--- a/lib/libc/stdio/vasprintf.c
+++ b/lib/libc/stdio/vasprintf.c
@@ -34,6 +34,7 @@ static char rcsid[] = "$FreeBSD$";
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
+#include "local.h"
int
vasprintf(str, fmt, ap)
@@ -53,7 +54,7 @@ vasprintf(str, fmt, ap)
return (-1);
}
f._bf._size = f._w = 127; /* Leave room for the NULL */
- ret = vfprintf(&f, fmt, ap);
+ ret = __vfprintf(&f, fmt, ap);
*f._p = '\0';
f._bf._base = reallocf(f._bf._base, f._bf._size + 1);
if (f._bf._base == NULL) {
diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c
index f8eb9ca..fff9aa8 100644
--- a/lib/libc/stdio/vfprintf.c
+++ b/lib/libc/stdio/vfprintf.c
@@ -48,6 +48,7 @@ static const char rcsid[] =
* This code is large and complicated...
*/
+#include "namespace.h"
#include <sys/types.h>
#include <limits.h>
@@ -60,10 +61,11 @@ static const char rcsid[] =
#else
#include <varargs.h>
#endif
+#include "un-namespace.h"
+#include "libc_private.h"
#include "local.h"
#include "fvwrite.h"
-#include "libc_private.h"
/* Define FLOATING_POINT to get floating point. */
#define FLOATING_POINT
@@ -80,11 +82,9 @@ static void __grow_type_table __P((int, unsigned char **, int *));
* then reset it so that it can be reused.
*/
static int
-__sprint(fp, uio)
- FILE *fp;
- register struct __suio *uio;
+__sprint(FILE *fp, struct __suio *uio)
{
- register int err;
+ int err;
if (uio->uio_resid == 0) {
uio->uio_iovcnt = 0;
@@ -102,10 +102,7 @@ __sprint(fp, uio)
* worries about ungetc buffers and so forth.
*/
static int
-__sbprintf(fp, fmt, ap)
- register FILE *fp;
- const char *fmt;
- va_list ap;
+__sbprintf(FILE *fp, const char *fmt, va_list ap)
{
int ret;
FILE fake;
@@ -123,8 +120,8 @@ __sbprintf(fp, fmt, ap)
fake._lbfsize = 0; /* not actually used, but Just In Case */
/* do the work, then copy any error status */
- ret = vfprintf(&fake, fmt, ap);
- if (ret >= 0 && fflush(&fake))
+ ret = __vfprintf(&fake, fmt, ap);
+ if (ret >= 0 && __fflush(&fake))
ret = EOF;
if (fake._flags & __SERR)
fp->_flags |= __SERR;
@@ -145,11 +142,7 @@ __sbprintf(fp, fmt, ap)
* use the given digits.
*/
static char *
-__ultoa(val, endp, base, octzero, xdigs)
- register u_long val;
- char *endp;
- int base, octzero;
- char *xdigs;
+__ultoa(u_long val, char *endp, int base, int octzero, char *xdigs)
{
register char *cp = endp;
register long sval;
@@ -205,14 +198,10 @@ __ultoa(val, endp, base, octzero, xdigs)
/* Identical to __ultoa, but for quads. */
static char *
-__uqtoa(val, endp, base, octzero, xdigs)
- register u_quad_t val;
- char *endp;
- int base, octzero;
- char *xdigs;
+__uqtoa(u_quad_t val, char *endp, int base, int octzero, char *xdigs)
{
- register char *cp = endp;
- register quad_t sval;
+ char *cp = endp;
+ quad_t sval;
/* quick test for small values; __ultoa is typically much faster */
/* (perhaps instead we should run until small, then call __ultoa?) */
@@ -257,6 +246,20 @@ __uqtoa(val, endp, base, octzero, xdigs)
return (cp);
}
+/*
+ * MT-safe version
+ */
+int
+vfprintf(FILE *fp, const char *fmt0, va_list ap)
+{
+ int ret;
+
+ FLOCKFILE(fp);
+ ret = __vfprintf(fp, fmt0, ap);
+ FUNLOCKFILE(fp);
+ return (ret);
+}
+
#ifdef FLOATING_POINT
#include <math.h>
#include "floatio.h"
@@ -287,18 +290,18 @@ static int exponent __P((char *, int, int));
#define SHORTINT 0x040 /* short integer */
#define ZEROPAD 0x080 /* zero (as opposed to blank) pad */
#define FPT 0x100 /* Floating point number */
+/*
+ * Non-MT-safe version
+ */
int
-vfprintf(fp, fmt0, ap)
- FILE *fp;
- const char *fmt0;
- va_list ap;
+__vfprintf(FILE *fp, const char *fmt0, va_list ap)
{
- register char *fmt; /* format string */
- register int ch; /* character from fmt */
- register int n, n2; /* handy integer (short term usage) */
- register char *cp; /* handy char pointer (short term usage) */
- register struct __siov *iovp;/* for PRINT macro */
- register int flags; /* flags as above */
+ char *fmt; /* format string */
+ int ch; /* character from fmt */
+ int n, n2; /* handy integer (short term usage) */
+ char *cp; /* handy char pointer (short term usage) */
+ struct __siov *iovp; /* for PRINT macro */
+ int flags; /* flags as above */
int ret; /* return value accumulator */
int width; /* width from format (%8d), or 0 */
int prec; /* precision from format (%.3d), or -1 */
@@ -418,19 +421,14 @@ vfprintf(fp, fmt0, ap)
}
- FLOCKFILE(fp);
/* sorry, fprintf(read_only_file, "") returns EOF, not 0 */
- if (cantwrite(fp)) {
- FUNLOCKFILE(fp);
+ if (cantwrite(fp))
return (EOF);
- }
/* optimise fprintf(stderr) (and other unbuffered Unix files) */
if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
- fp->_file >= 0) {
- FUNLOCKFILE(fp);
+ fp->_file >= 0)
return (__sbprintf(fp, fmt0, ap));
- }
fmt = (char *)fmt0;
argtable = NULL;
@@ -867,7 +865,6 @@ done:
error:
if (__sferror(fp))
ret = EOF;
- FUNLOCKFILE(fp);
if ((argtable != NULL) && (argtable != statargtable))
free (argtable);
return (ret);
@@ -902,16 +899,13 @@ error:
* It will be replaces with a malloc-ed one if it overflows.
*/
static void
-__find_arguments (fmt0, ap, argtable)
- const char *fmt0;
- va_list ap;
- void ***argtable;
+__find_arguments (const char *fmt0, va_list ap, void ***argtable)
{
- register char *fmt; /* format string */
- register int ch; /* character from fmt */
- register int n, n2; /* handy integer (short term usage) */
- register char *cp; /* handy char pointer (short term usage) */
- register int flags; /* flags as above */
+ char *fmt; /* format string */
+ int ch; /* character from fmt */
+ int n, n2; /* handy integer (short term usage) */
+ char *cp; /* handy char pointer (short term usage) */
+ int flags; /* flags as above */
int width; /* width from format (%8d), or 0 */
unsigned char *typetable; /* table of types */
unsigned char stattypetable [STATIC_ARG_TBL_SIZE];
@@ -1174,10 +1168,7 @@ done:
* Increase the size of the type table.
*/
static void
-__grow_type_table (nextarg, typetable, tablesize)
- int nextarg;
- unsigned char **typetable;
- int *tablesize;
+__grow_type_table (int nextarg, unsigned char **typetable, int *tablesize)
{
unsigned char *const oldtable = *typetable;
const int oldsize = *tablesize;
@@ -1206,10 +1197,8 @@ __grow_type_table (nextarg, typetable, tablesize)
extern char *__dtoa __P((double, int, int, int *, int *, char **));
static char *
-cvt(value, ndigits, flags, sign, decpt, ch, length)
- double value;
- int ndigits, flags, *decpt, ch, *length;
- char *sign;
+cvt(double value, int ndigits, int flags, char *sign, int *decpt,
+ int ch, int *length)
{
int mode, dsgn;
char *digits, *bp, *rve;
@@ -1250,11 +1239,9 @@ cvt(value, ndigits, flags, sign, decpt, ch, length)
}
static int
-exponent(p0, exp, fmtch)
- char *p0;
- int exp, fmtch;
+exponent(char *p0, int exp, int fmtch)
{
- register char *p, *t;
+ char *p, *t;
char expbuf[MAXEXP];
p = p0;
diff --git a/lib/libc/stdio/vfscanf.c b/lib/libc/stdio/vfscanf.c
index 6a83216..04ce95c 100644
--- a/lib/libc/stdio/vfscanf.c
+++ b/lib/libc/stdio/vfscanf.c
@@ -42,6 +42,7 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
@@ -51,8 +52,10 @@ static const char rcsid[] =
#include <varargs.h>
#endif
#include <string.h>
+#include "un-namespace.h"
#include "collate.h"
+#include "libc_private.h"
#include "local.h"
#define FLOATING_POINT
@@ -100,21 +103,32 @@ static const char rcsid[] =
static u_char *__sccl(char *, u_char *);
/*
- * vfscanf
+ * __vfscanf - MT-safe version
*/
int
-__svfscanf(fp, fmt0, ap)
- register FILE *fp;
- char const *fmt0;
- va_list ap;
+__vfscanf(FILE *fp, char const *fmt0, va_list ap)
{
- register u_char *fmt = (u_char *)fmt0;
- register int c; /* character from format, or conversion */
- register size_t width; /* field width, or 0 */
- register char *p; /* points into all kinds of strings */
- register int n; /* handy integer */
- register int flags; /* flags as defined above */
- register char *p0; /* saves original value of p when necessary */
+ int ret;
+
+ FLOCKFILE(fp);
+ ret = __svfscanf(fp, fmt0, ap);
+ FUNLOCKFILE(fp);
+ return (ret);
+}
+
+/*
+ * __svfscanf - non-MT-safe version of __vfscanf
+ */
+int
+__svfscanf(FILE *fp, char const *fmt0, va_list ap)
+{
+ u_char *fmt = (u_char *)fmt0;
+ int c; /* character from format, or conversion */
+ size_t width; /* field width, or 0 */
+ char *p; /* points into all kinds of strings */
+ int n; /* handy integer */
+ int flags; /* flags as defined above */
+ char *p0; /* saves original value of p when necessary */
int nassigned; /* number of fields assigned */
int nconversions; /* number of conversions */
int nread; /* number of characters consumed from fp */
@@ -539,13 +553,13 @@ literal:
*/
if (flags & NDIGITS) {
if (p > buf)
- (void) ungetc(*(u_char *)--p, fp);
+ (void) __ungetc(*(u_char *)--p, fp);
goto match_failure;
}
c = ((u_char *)p)[-1];
if (c == 'x' || c == 'X') {
--p;
- (void) ungetc(c, fp);
+ (void) __ungetc(c, fp);
}
if ((flags & SUPPRESS) == 0) {
u_quad_t res;
@@ -635,16 +649,16 @@ literal:
if (flags & EXPOK) {
/* no digits at all */
while (p > buf)
- ungetc(*(u_char *)--p, fp);
+ __ungetc(*(u_char *)--p, fp);
goto match_failure;
}
/* just a bad exponent (e and maybe sign) */
c = *(u_char *)--p;
if (c != 'e' && c != 'E') {
- (void) ungetc(c, fp);/* sign */
+ (void) __ungetc(c, fp);/* sign */
c = *(u_char *)--p;
}
- (void) ungetc(c, fp);
+ (void) __ungetc(c, fp);
}
if ((flags & SUPPRESS) == 0) {
double res;
diff --git a/lib/libc/stdio/vscanf.c b/lib/libc/stdio/vscanf.c
index 53fb362..64541c8 100644
--- a/lib/libc/stdio/vscanf.c
+++ b/lib/libc/stdio/vscanf.c
@@ -42,7 +42,9 @@ static const char rcsid[] =
"$FreeBSD$";
#endif /* LIBC_SCCS and not lint */
+#include "namespace.h"
#include <stdio.h>
+#include "un-namespace.h"
#include "libc_private.h"
int
diff --git a/lib/libc/stdio/vsnprintf.c b/lib/libc/stdio/vsnprintf.c
index b8e4c8c..b301b08 100644
--- a/lib/libc/stdio/vsnprintf.c
+++ b/lib/libc/stdio/vsnprintf.c
@@ -44,6 +44,7 @@ static const char rcsid[] =
#include <limits.h>
#include <stdio.h>
+#include "local.h"
int
vsnprintf(str, n, fmt, ap)
@@ -65,7 +66,7 @@ vsnprintf(str, n, fmt, ap)
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._w = n;
- ret = vfprintf(&f, fmt, ap);
+ ret = __vfprintf(&f, fmt, ap);
if (on > 0)
*f._p = '\0';
return (ret);
diff --git a/lib/libc/stdio/vsprintf.c b/lib/libc/stdio/vsprintf.c
index d357af0..dbfd339 100644
--- a/lib/libc/stdio/vsprintf.c
+++ b/lib/libc/stdio/vsprintf.c
@@ -44,6 +44,7 @@ static const char rcsid[] =
#include <stdio.h>
#include <limits.h>
+#include "local.h"
int
vsprintf(str, fmt, ap)
@@ -58,7 +59,7 @@ vsprintf(str, fmt, ap)
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._w = INT_MAX;
- ret = vfprintf(&f, fmt, ap);
+ ret = __vfprintf(&f, fmt, ap);
*f._p = 0;
return (ret);
}
diff --git a/lib/libc/stdio/wbuf.c b/lib/libc/stdio/wbuf.c
index 847699a..54da709 100644
--- a/lib/libc/stdio/wbuf.c
+++ b/lib/libc/stdio/wbuf.c
@@ -49,6 +49,8 @@ static const char rcsid[] =
* Write the given character into the (probably full) buffer for
* the given file. Flush the buffer out if it is or becomes full,
* or if c=='\n' and the file is line buffered.
+ *
+ * Non-MT-safe
*/
int
__swbuf(c, fp)
@@ -80,14 +82,14 @@ __swbuf(c, fp)
*/
n = fp->_p - fp->_bf._base;
if (n >= fp->_bf._size) {
- if (fflush(fp))
+ if (__fflush(fp))
return (EOF);
n = 0;
}
fp->_w--;
*fp->_p++ = c;
if (++n == fp->_bf._size || (fp->_flags & __SLBF && c == '\n'))
- if (fflush(fp))
+ if (__fflush(fp))
return (EOF);
return (c);
}
OpenPOWER on IntegriCloud