Commit graph

35 commits

Author SHA1 Message Date
Poul-Henning Kamp 6dbacee284 Make the %V{is} extension handle a NULL pointer like %s does: output "(null)"
Add %M{essage} extension which prints an errno value as the
corresponding string if possible or numerically otherwise.

It is not currently possible to do the syslog(3) like %m extension
because errno would need to get capatured on entry to the first
function in the printf family, so %M requires you to supply errno
as an argument.

Add %Q{uote} extension which will print a string in double quotes with
appropriate back-slash escapes (only) if necessary.
2006-01-25 12:45:24 +00:00
Poul-Henning Kamp 75067f4f70 Add an extensible version of our *printf(3) implementation to libc
on probationary terms:  it may go away again if it transpires it is
a bad idea.

This extensible printf version will only be used if either
    environment variable USE_XPRINTF is defined
or
    one of the extension functions are called.
or
    the global variable __use_xprintf is set greater than zero.

In all other cases our traditional printf implementation will
be used.

The extensible version is slower than the default printf, mostly
because less opportunity for combining I/O operation exists when
faced with extensions.  The default printf on the other hand
is a bad case of spaghetti code.

The extension API has a GLIBC compatible part and a FreeBSD version
of same.  The FreeBSD version exists because the GLIBC version may
run afoul of our FILE * locking in multithreaded programs and it
even further eliminate the opportunities for combining I/O operations.

Include three demo extensions which can be enabled if desired: time
(%T), hexdump (%H) and strvis (%V).

%T can format time_t (%T), struct timeval (%lT) and struct timespec (%llT)
   in one of two human readable duration formats:
	"%.3llT" -> "20349.245"
	"%#.3llT" -> "5h39m9.245"

%H will hexdump a sequence of bytes and takes a pointer and a length
   argument.  The width specifies number of bytes per line.
	"%4H" -> "65 72 20 65"
	"%+4H" -> "0000 65 72 20 65"
	"%#4H" -> "65 72 20 65  |er e|"
	"%+#4H" -> "0000 65 72 20 65  |er e|"

%V will dump a string in strvis format.
	"%V" -> "Hello\tWor\377ld"	(C-style)
	"%0V" -> "Hello\011Wor\377ld"	(octal)
	"%+V" -> "Hello%09Wor%FFld"	(http-style)

Tests, comments, bugreports etc are most welcome.
2005-12-16 18:56:39 +00:00
Tim J. Robbins 9531ef0fc1 Add fgetwln(), a wide character version of fgetln(). 2004-07-16 06:06:09 +00:00
Tim J. Robbins 4549f62011 Document clearerr_unlocked(), feof_unlocked(), ferror_unlocked()
and fileno_unlocked().
2003-01-10 06:22:28 +00:00
Tim J. Robbins 4d844c09ac Add a manual page for flockfile(), ftrylockfile(), and funlockfile(). 2003-01-10 05:34:11 +00:00
Tim J. Robbins cbee408df1 Document getc_unlocked(), getchar_unlocked(), putc_unlocked(),
and putchar_unlocked().
2003-01-10 04:56:20 +00:00
Tim J. Robbins a5b0089e65 Add function versions of getchar_unlocked(), getc_unlocked(),
putchar_unlocked(), putc_unlocked(), feof_unlocked(), ferror_unlocked(),
clearerr_unlocked(), and fileno_unlocked(). The first four are required
by POSIX. The rest are provided for consistency.
2003-01-10 04:35:08 +00:00
Ruslan Ermilov c51d717f0c libc_r wasn't so tied to libc for 22 months. 2002-11-18 09:50:57 +00:00
Alfred Perlstein ac1cc6ee11 Backout "compatibility hack" for __sF.
Requested by: Steve Kargl <sgk@troutmask.apl.washington.edu> (submitter)
2002-11-04 03:23:56 +00:00
Alfred Perlstein 0fc25b925d Provide a hook to make __sF visible outside of libc for commercial apps
if WANT_COMPAT4_STDIO is defined when compiling libc.

Submitted by: Steve Kargl <sgk@troutmask.apl.washington.edu>
2002-11-02 19:47:53 +00:00
Tim J. Robbins 1f4ff8506a Add implementations of wscanf() and related functions: fwscanf(), swscanf(),
vfwscanf(), vswscanf(), vwscanf(). As the name suggests, these are wide-
character versions of the scanf() family of functions.
2002-09-23 12:40:06 +00:00
Tim J. Robbins c5604d0a50 Add implementations of the wprintf() family of functions, which perform
formatted wide-character output.
2002-09-21 13:00:30 +00:00
Poul-Henning Kamp 209c34ba95 Unbreak one of the most confusing breaks of the tree I've seen.
The last commit cannot possibly have been tested.
2002-08-13 18:55:51 +00:00
Tim J. Robbins 439cb19e04 Tidy up SRCS and MAN assignments. 2002-08-13 11:56:02 +00:00
Tim J. Robbins e74101e4ef Basic support for wide character I/O: getwc(), fgetwc(), getwchar(),
putwc(), fputwc(), putwchar(), ungetwc(), fwide().
2002-08-13 09:30:41 +00:00
Ruslan Ermilov 4a558355e5 MAN[1-9] -> MAN. 2001-03-27 17:27:19 +00:00
Peter Wemm 7f3dea244c $Id$ -> $FreeBSD$ 1999-08-28 00:22:10 +00:00
Warner Losh 2ee878400e Add mkstemps to the man page, and create a link for it.
Obtained from: OpenBSD
Poked in the eye about committing new functions without a manpage: obrien
1999-04-04 21:15:37 +00:00
Bruce Evans dcf01d60ba Fixed disordering and incoinsistent style in previous commit. 1999-03-05 13:01:22 +00:00
Dmitrij Tejblum 7307d07db6 Added functions fseeko() and ftello() (from susv2).
Fixed fgetpos() and fsetpos() for offsets > 2GB.

PR:		8637
Submitted by:	 Dan Nelson <dnelson@emsphone.com> (adjusted by me a little)
1999-02-08 21:32:38 +00:00
John Birrell f9a8e5fafb Remote the NetBSD kludge for vfprintf.c 1998-05-08 05:17:11 +00:00
John Birrell ec216c2634 Add FILE locking stubs for libc.
Change the FILE locking to support kernel threads when linked with
libpthread (which you haven't see yet). This requires that libc become
thread-safe and thread-aware, testing __isthreaded before attempting
to do lock/unlock calls. The impact on non-threaded programs is minor.
This change works with libc_r, so it's the best compromise.
1998-04-11 07:40:47 +00:00
Bruce Evans 034abff918 Fixed disordering and inconsistent style in previous commit. 1998-03-12 12:05:14 +00:00
Warner Losh 2f253e75c8 Many security improvements from OpenBSD:
implement mkdtemp
	improve man page for mk*temp
	use arc4random to seed extra XXX's randomly
	Optionally warn of unsafe mktemp uses
From various commits by theo de raadt and Todd Miller.
Obtained from: OpenBSD

This should go into 2.2 after a testing period.
1998-02-13 02:13:24 +00:00
Bruce Evans b966cc2394 Sorted lists. 1997-10-21 08:41:15 +00:00
Bruce Evans 2bc3b4d735 Removed the subdirectory paths from the definitions of MAN[1-9]. They
were a workaround for limitations in bsd.man.mk that were fixed about
2 years ago.
1997-10-15 16:16:41 +00:00
John Birrell 870039320f Changed all paths to be relative to src/lib instead of src/lib/libc
so that all these makefiles can be used to build libc_r too.

Added .if ${LIB} == "c" tests to restrict man page builds to libc
to avoid needlessly building them with libc_r too.

Split libc Makefile into Makefile and Makefile.inc to allow the
libc_r Makefile to include Makefile.inc too.
1997-05-03 03:50:06 +00:00
Peter Wemm 7e546392b5 Revert $FreeBSD$ to $Id$ 1997-02-22 15:12:41 +00:00
Jordan K. Hubbard 1130b656e5 Make the long-awaited change from $Id$ to $FreeBSD$
This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore.  This update would have been
insane otherwise.
1997-01-14 07:20:47 +00:00
Jordan K. Hubbard 941fbd30eb Fix bogus MLINKS line from vasprintf change. 1996-05-29 05:00:12 +00:00
Wolfram Schneider 01fc74a034 add manpage links
asprintf.3 -> printf.3
vasprintf -> printf.3
1996-05-29 01:00:00 +00:00
Peter Wemm 15aa00d597 Add an implementation of the gnu-ish asprintf() and vasprintf(). They are
not based on gpl'ed code, just prototype and usage.  I'm not 100% certain
they behave the same while the system is in trouble (eg: malloc() failing)
but in those circumstances all bets would be off anyway.

These routines work like sprintf() and vsprintf(), except that instead of
using a fixed buffer, they allocate memory and return it to the user
and it's the user's responsibility to free() it.  They have allocate as
much memory as they need (and can get), so the size of strings it can deal
with is limited only by the amount of memory it can malloc() on your
behalf.

There are a few gpl'ed programs starting to use this interface, and it's
becoming more common with the scares about security risks with sprintf().
I dont like the look of the code that the various programs (including
cvs, gdb, libg++, etc) provide if configure can't find it on the system.

It should be possible to modify the stdio core code to provide this
interface more efficiently, I was more worried about having something
that worked and was secure.  :-)  (I noticed that there was once intended
to be a smprintf() routine when our stdio was written for 4.4BSD, but it
looks pretty stillborn, and it's intended interface is not clear).  Since
Linux and gnu libc have this interface, it seemed silly to bring yet
another one onto the scene.
1996-05-27 10:49:43 +00:00
Rodney W. Grimes 6c06b4e2aa Remove trailing whitespace. 1995-05-30 05:51:47 +00:00
Garrett Wollman 2ceb2ce9ee First crack at making libc work with the new make macros. It compiles on
my machine, and a simple static (genassym) and shared (sysctl) executable
both work.  Still to be done: RPCand YP merge.
1994-08-05 01:19:12 +00:00
Rodney W. Grimes 58f0484fa2 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00