diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/shlib_version | 2 | ||||
-rw-r--r-- | lib/libc/stdio/Makefile.inc | 7 | ||||
-rw-r--r-- | lib/libc/stdio/dprintf.c | 48 | ||||
-rw-r--r-- | lib/libc/stdio/printf.3 | 29 | ||||
-rw-r--r-- | lib/libc/stdio/stdio.3 | 6 | ||||
-rw-r--r-- | lib/libc/stdio/vdprintf.c | 73 |
6 files changed, 156 insertions, 9 deletions
diff --git a/lib/libc/shlib_version b/lib/libc/shlib_version index 01f5cff837b..8ae224587de 100644 --- a/lib/libc/shlib_version +++ b/lib/libc/shlib_version @@ -1,4 +1,4 @@ major=66 -minor=1 +minor=2 # note: If changes were made to include/thread_private.h or if system # calls were added/changed then librthread/shlib_version also be updated. diff --git a/lib/libc/stdio/Makefile.inc b/lib/libc/stdio/Makefile.inc index bf8cd0e38f5..caee57667a0 100644 --- a/lib/libc/stdio/Makefile.inc +++ b/lib/libc/stdio/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.22 2012/03/21 23:44:35 fgsch Exp $ +# $OpenBSD: Makefile.inc,v 1.23 2013/01/30 00:08:13 brad Exp $ # stdio sources .PATH: ${LIBCSRCDIR}/stdio @@ -19,7 +19,7 @@ SRCS+= asprintf.c clrerr.c fclose.c fdopen.c feof.c ferror.c fflush.c fgetc.c \ putwc.c putwchar.c ungetwc.c \ fwprintf.c swprintf.c vfwprintf.c vswprintf.c vwprintf.c wprintf.c \ fwscanf.c swscanf.c vfwscanf.c vswscanf.c vwscanf.c wscanf.c \ - getdelim.c getline.c + getdelim.c getline.c dprintf.c vdprintf.c MAN+= fclose.3 ferror.3 fflush.3 fgetln.3 fgets.3 fopen.3 fputs.3 \ fread.3 fseek.3 funopen.3 getc.3 mktemp.3 perror.3 printf.3 putc.3 \ @@ -43,7 +43,8 @@ MLINKS+=mktemp.3 mkdtemp.3 MLINKS+=mktemp.3 mkstemps.3 MLINKS+=printf.3 fprintf.3 printf.3 snprintf.3 printf.3 sprintf.3 \ printf.3 vfprintf.3 printf.3 vprintf.3 printf.3 vsnprintf.3 \ - printf.3 vsprintf.3 printf.3 asprintf.3 printf.3 vasprintf.3 + printf.3 vsprintf.3 printf.3 asprintf.3 printf.3 vasprintf.3 \ + printf.3 dprintf.3 printf.3 vdprintf.3 MLINKS+=putc.3 fputc.3 putc.3 putchar.3 putc.3 putw.3 MLINKS+=scanf.3 fscanf.3 scanf.3 sscanf.3 scanf.3 vfscanf.3 scanf.3 vscanf.3 \ scanf.3 vsscanf.3 diff --git a/lib/libc/stdio/dprintf.c b/lib/libc/stdio/dprintf.c new file mode 100644 index 00000000000..dbf7d3457ff --- /dev/null +++ b/lib/libc/stdio/dprintf.c @@ -0,0 +1,48 @@ +/* $OpenBSD: dprintf.c,v 1.1 2013/01/30 00:08:13 brad Exp $ */ +/* $FreeBSD: src/lib/libc/stdio/dprintf.c,v 1.2 2012/11/17 01:49:39 svnexp Exp $ */ + +/*- + * Copyright (c) 2009 David Schultz <das@FreeBSD.org> + * All rights reserved. + * + * Copyright (c) 2011 The FreeBSD Foundation + * All rights reserved. + * Portions of this software were developed by David Chisnall + * under sponsorship from the FreeBSD Foundation. + * + * 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. + */ + +#include <stdio.h> +#include <stdarg.h> + +int +dprintf(int fd, const char * __restrict fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret = vdprintf(fd, fmt, ap); + va_end(ap); + return ret; +} diff --git a/lib/libc/stdio/printf.3 b/lib/libc/stdio/printf.3 index 01307ba9fa7..61767cd4784 100644 --- a/lib/libc/stdio/printf.3 +++ b/lib/libc/stdio/printf.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: printf.3,v 1.59 2011/09/03 22:59:07 jmc Exp $ +.\" $OpenBSD: printf.3,v 1.60 2013/01/30 00:08:13 brad Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -33,7 +33,7 @@ .\" .\" @(#)printf.3 8.1 (Berkeley) 6/4/93 .\" -.Dd $Mdocdate: September 3 2011 $ +.Dd $Mdocdate: January 30 2013 $ .Dt PRINTF 3 .Os .Sh NAME @@ -42,11 +42,13 @@ .Nm sprintf , .Nm snprintf , .Nm asprintf , +.Nm dprintf , .Nm vprintf , .Nm vfprintf , .Nm vsprintf , .Nm vsnprintf , -.Nm vasprintf +.Nm vasprintf , +.Nm vdprintf .Nd formatted output conversion .Sh SYNOPSIS .Fd #include <stdio.h> @@ -60,6 +62,8 @@ .Fn snprintf "char *str" "size_t size" "const char *format" ... .Ft int .Fn asprintf "char **ret" "const char *format" ... +.Ft int +.Fn dprintf "int fd" "const char * restrict format" ... .Fd #include <stdarg.h> .Ft int .Fn vprintf "const char *format" "va_list ap" @@ -71,6 +75,8 @@ .Fn vsnprintf "char *str" "size_t size" "const char *format" "va_list ap" .Ft int .Fn vasprintf "char **ret" "const char *format" "va_list ap" +.Ft int +.Fn vdprintf "int fd" "const char * restrict format" "va_list ap" .Sh DESCRIPTION The .Fn printf @@ -95,6 +101,10 @@ and .Fn vfprintf write output to the supplied stream pointer .Fa stream ; +.Fn dprintf +and +.Fn vdprintf +write output to the given file descriptor; .Fn sprintf , .Fn snprintf , .Fn vsprintf , @@ -754,6 +764,12 @@ and .Fn vsprintf functions conform to .St -ansiC . +The +.Fn dprintf +and +.Fn vdprintf +functions conform to +.St -p1003.1-2008 . .Sh HISTORY The functions .Fn snprintf @@ -769,6 +785,13 @@ and first appeared in the GNU C library. This implementation first appeared in .Ox 2.3 . +.Pp +The functions +.Fn dprintf +and +.Fn vdprintf +first appeared in +.Ox 5.3 . .Sh CAVEATS The conversion formats .Cm \&%D , diff --git a/lib/libc/stdio/stdio.3 b/lib/libc/stdio/stdio.3 index 381dc7fe5af..51a7adf28dd 100644 --- a/lib/libc/stdio/stdio.3 +++ b/lib/libc/stdio/stdio.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: stdio.3,v 1.23 2012/04/12 08:26:38 jmc Exp $ +.\" $OpenBSD: stdio.3,v 1.24 2013/01/30 00:08:13 brad Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -27,7 +27,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: April 12 2012 $ +.Dd $Mdocdate: January 30 2013 $ .Dt STDIO 3 .Os .Sh NAME @@ -210,6 +210,7 @@ definitions are explicitly removed. .It Sy Function Ta Sy Description .It asprintf Ta "formatted output conversion with allocation" .It clearerr Ta "check and reset stream status" +.It dprintf Ta "formatted output conversion" .It fclose Ta "close a stream" .It fdopen Ta "stream open functions" .It feof Ta "check and reset stream status" @@ -267,6 +268,7 @@ definitions are explicitly removed. .It tmpnam Ta "temporary file routines" .It ungetc Ta "un-get character from input stream" .It vasprintf Ta "formatted output conversion with allocation" +.It vdprintf Ta "formatted output conversion" .It vfprintf Ta "formatted output conversion" .It vfscanf Ta "input format conversion" .It vprintf Ta "formatted output conversion" diff --git a/lib/libc/stdio/vdprintf.c b/lib/libc/stdio/vdprintf.c new file mode 100644 index 00000000000..49c19697710 --- /dev/null +++ b/lib/libc/stdio/vdprintf.c @@ -0,0 +1,73 @@ +/* $OpenBSD: vdprintf.c,v 1.1 2013/01/30 00:08:13 brad Exp $ */ +/* $FreeBSD: src/lib/libc/stdio/vdprintf.c,v 1.4 2012/11/17 01:49:40 svnexp Exp $ */ + +/*- + * Copyright (c) 2009 David Schultz <das@FreeBSD.org> + * All rights reserved. + * + * Copyright (c) 2011 The FreeBSD Foundation + * All rights reserved. + * Portions of this software were developed by David Chisnall + * under sponsorship from the FreeBSD Foundation. + * + * 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. + */ + +#include <errno.h> +#include <stdarg.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> + +#include "local.h" + +static int +__dwrite(void *cookie, const char *buf, int n) +{ + int *fdp = cookie; + return (write(*fdp, buf, n)); +} + +int +vdprintf(int fd, const char * __restrict fmt, va_list ap) +{ + FILE f; + struct __sfileext fext; + unsigned char buf[BUFSIZ]; + int ret; + + _FILEEXT_SETUP(&f, &fext); + + f._p = buf; + f._w = sizeof(buf); + f._flags = __SWR; + f._file = -1; + f._bf._base = buf; + f._bf._size = sizeof(buf); + f._cookie = &fd; + f._write = __dwrite; + + if ((ret = __vfprintf(&f, fmt, ap)) < 0) + return ret; + + return fflush(&f) ? EOF : ret; +} |