summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/vfprintf.c
diff options
context:
space:
mode:
authordeischen <deischen@FreeBSD.org>2001-01-24 13:01:12 +0000
committerdeischen <deischen@FreeBSD.org>2001-01-24 13:01:12 +0000
commit1635c221b7b2678beeeb2b5fa728edd7c8c3735b (patch)
treed7d4f61b9e319a781a335702fe846592726c22b9 /lib/libc/stdio/vfprintf.c
parent08685e9e9fd9de1e8dc51cada55659344adaf0cc (diff)
downloadFreeBSD-src-1635c221b7b2678beeeb2b5fa728edd7c8c3735b.zip
FreeBSD-src-1635c221b7b2678beeeb2b5fa728edd7c8c3735b.tar.gz
Remove _THREAD_SAFE and make libc thread-safe by default by
adding (weak definitions to) stubs for some of the pthread functions. If the threads library is linked in, the real pthread functions will pulled in. Use the following convention for system calls wrapped by the threads library: __sys_foo - actual system call _foo - weak definition to __sys_foo foo - weak definition to __sys_foo Change all libc uses of system calls wrapped by the threads library from foo to _foo. In order to define the prototypes for _foo(), we introduce namespace.h and un-namespace.h (suggested by bde). All files that need to reference these system calls, should include namespace.h before any standard includes, then include un-namespace.h after the standard includes and before any local includes. <db.h> is an exception and shouldn't be included in between namespace.h and un-namespace.h namespace.h will define foo to _foo, and un-namespace.h will undefine foo. Try to eliminate some of the recursive calls to MT-safe functions in libc/stdio in preparation for adding a mutex to FILE. We have recursive mutexes, but would like to avoid using them if possible. Remove uneeded includes of <errno.h> from a few files. Add $FreeBSD$ to a few files in order to pass commitprep. Approved by: -arch
Diffstat (limited to 'lib/libc/stdio/vfprintf.c')
-rw-r--r--lib/libc/stdio/vfprintf.c111
1 files changed, 49 insertions, 62 deletions
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;
OpenPOWER on IntegriCloud