Basic support for wide character I/O: getwc(), fgetwc(), getwchar(),
putwc(), fputwc(), putwchar(), ungetwc(), fwide().
This commit is contained in:
parent
149004e99d
commit
e74101e4ef
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=101776
@ -69,6 +69,9 @@
|
|||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#include <machine/ansi.h>
|
#include <machine/ansi.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#ifndef NULL
|
#ifndef NULL
|
||||||
#define NULL 0
|
#define NULL 0
|
||||||
#endif
|
#endif
|
||||||
@ -106,6 +109,14 @@ typedef _BSD_WINT_T_ wint_t;
|
|||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
wint_t btowc(int);
|
wint_t btowc(int);
|
||||||
|
wint_t fgetwc(FILE *);
|
||||||
|
wchar_t *
|
||||||
|
fgetws(wchar_t *__restrict, int, FILE *__restrict);
|
||||||
|
wint_t fputwc(wchar_t, FILE *);
|
||||||
|
int fputws(const wchar_t *__restrict, FILE *__restrict);
|
||||||
|
int fwide(FILE *, int);
|
||||||
|
wint_t getwc(FILE *);
|
||||||
|
wint_t getwchar(void);
|
||||||
#if 0
|
#if 0
|
||||||
/* XXX: not implemented */
|
/* XXX: not implemented */
|
||||||
size_t mbrlen(const char * __restrict, size_t, mbstate_t * __restrict);
|
size_t mbrlen(const char * __restrict, size_t, mbstate_t * __restrict);
|
||||||
@ -114,6 +125,12 @@ size_t mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
|
|||||||
int mbsinit(const mbstate_t *);
|
int mbsinit(const mbstate_t *);
|
||||||
size_t mbsrtowcs(wchar_t * __restrict, const char ** __restrict, size_t,
|
size_t mbsrtowcs(wchar_t * __restrict, const char ** __restrict, size_t,
|
||||||
mbstate_t * __restrict);
|
mbstate_t * __restrict);
|
||||||
|
#endif
|
||||||
|
wint_t putwc(wchar_t, FILE *);
|
||||||
|
wint_t putwchar(wchar_t);
|
||||||
|
wint_t ungetwc(wint_t, FILE *);
|
||||||
|
#if 0
|
||||||
|
/* XXX: not implemented */
|
||||||
size_t wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
|
size_t wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
|
||||||
#endif
|
#endif
|
||||||
wchar_t *wcscat(wchar_t * __restrict, const wchar_t * __restrict);
|
wchar_t *wcscat(wchar_t * __restrict, const wchar_t * __restrict);
|
||||||
@ -150,4 +167,9 @@ wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t);
|
|||||||
wchar_t *wmemset(wchar_t *, wchar_t, size_t);
|
wchar_t *wmemset(wchar_t *, wchar_t, size_t);
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
|
#define getwc(fp) fgetwc(fp)
|
||||||
|
#define getwchar() fgetwc(stdin)
|
||||||
|
#define putwc(wc, fp) fputwc(wc, fp)
|
||||||
|
#define putwchar(wc) fputwc(wc, stdout)
|
||||||
|
|
||||||
#endif /* !_WCHAR_H_ */
|
#endif /* !_WCHAR_H_ */
|
||||||
|
@ -6,20 +6,27 @@
|
|||||||
|
|
||||||
SRCS+= _flock_stub.c \
|
SRCS+= _flock_stub.c \
|
||||||
asprintf.c clrerr.c fclose.c fdopen.c feof.c ferror.c fflush.c \
|
asprintf.c clrerr.c fclose.c fdopen.c feof.c ferror.c fflush.c \
|
||||||
fgetc.c fgetln.c fgetpos.c fgets.c fileno.c findfp.c flags.c fopen.c \
|
fgetc.c fgetln.c fgetpos.c fgets.c fgetwc.c fgetws.c fileno.c findfp.c \
|
||||||
fprintf.c fpurge.c fputc.c fputs.c fread.c freopen.c fscanf.c \
|
flags.c fopen.c \
|
||||||
fseek.c fsetpos.c ftell.c funopen.c fvwrite.c fwalk.c fwrite.c \
|
fprintf.c fpurge.c fputc.c fputs.c fputwc.c fputws.c fread.c freopen.c \
|
||||||
getc.c getchar.c gets.c getw.c makebuf.c mktemp.c perror.c \
|
fscanf.c \
|
||||||
printf.c putc.c putchar.c puts.c putw.c refill.c remove.c rewind.c \
|
fseek.c fsetpos.c ftell.c funopen.c fvwrite.c fwalk.c fwide.c fwrite.c \
|
||||||
|
getc.c getchar.c gets.c getw.c getwc.c getwchar.c makebuf.c mktemp.c \
|
||||||
|
perror.c \
|
||||||
|
printf.c putc.c putchar.c puts.c putw.c putwc.c putwchar.c refill.c \
|
||||||
|
remove.c rewind.c \
|
||||||
rget.c scanf.c setbuf.c setbuffer.c setvbuf.c snprintf.c sprintf.c \
|
rget.c scanf.c setbuf.c setbuffer.c setvbuf.c snprintf.c sprintf.c \
|
||||||
sscanf.c stdio.c tempnam.c tmpfile.c tmpnam.c ungetc.c vasprintf.c \
|
sscanf.c stdio.c tempnam.c tmpfile.c tmpnam.c ungetc.c ungetwc.c \
|
||||||
|
vasprintf.c \
|
||||||
vfprintf.c vfscanf.c vprintf.c vscanf.c vsnprintf.c vsprintf.c \
|
vfprintf.c vfscanf.c vprintf.c vscanf.c vsnprintf.c vsprintf.c \
|
||||||
vsscanf.c wbuf.c wsetup.c
|
vsscanf.c wbuf.c wsetup.c
|
||||||
|
|
||||||
.if ${LIB} == "c"
|
.if ${LIB} == "c"
|
||||||
MAN+= fclose.3 ferror.3 fflush.3 fgetln.3 fgets.3 fopen.3 fputs.3 \
|
MAN+= fclose.3 ferror.3 fflush.3 fgetln.3 fgets.3 fgetws.3 fopen.3 fputs.3 \
|
||||||
fread.3 fseek.3 funopen.3 getc.3 mktemp.3 printf.3 putc.3 remove.3 \
|
fputws.3 \
|
||||||
scanf.3 setbuf.3 stdio.3 tmpnam.3 ungetc.3
|
fread.3 fseek.3 funopen.3 fwide.3 getc.3 getwc.3 mktemp.3 printf.3 \
|
||||||
|
putc.3 putwc.3 remove.3 \
|
||||||
|
scanf.3 setbuf.3 stdio.3 tmpnam.3 ungetc.3 ungetwc.3
|
||||||
|
|
||||||
MLINKS+=ferror.3 clearerr.3 ferror.3 feof.3 ferror.3 fileno.3
|
MLINKS+=ferror.3 clearerr.3 ferror.3 feof.3 ferror.3 fileno.3
|
||||||
MLINKS+=fflush.3 fpurge.3
|
MLINKS+=fflush.3 fpurge.3
|
||||||
@ -31,6 +38,7 @@ MLINKS+=fseek.3 fgetpos.3 fseek.3 fseeko.3 fseek.3 fsetpos.3 fseek.3 ftell.3 \
|
|||||||
fseek.3 ftello.3 fseek.3 rewind.3
|
fseek.3 ftello.3 fseek.3 rewind.3
|
||||||
MLINKS+=funopen.3 fropen.3 funopen.3 fwopen.3
|
MLINKS+=funopen.3 fropen.3 funopen.3 fwopen.3
|
||||||
MLINKS+=getc.3 fgetc.3 getc.3 getchar.3 getc.3 getw.3
|
MLINKS+=getc.3 fgetc.3 getc.3 getchar.3 getc.3 getw.3
|
||||||
|
MLINKS+=getwc.3 fgetwc.3 getwc.3 getwchar.3
|
||||||
MLINKS+=mktemp.3 mkdtemp.3 mktemp.3 mkstemp.3 mktemp.3 mkstemps.3
|
MLINKS+=mktemp.3 mkdtemp.3 mktemp.3 mkstemp.3 mktemp.3 mkstemps.3
|
||||||
MLINKS+=printf.3 asprintf.3 printf.3 fprintf.3 \
|
MLINKS+=printf.3 asprintf.3 printf.3 fprintf.3 \
|
||||||
printf.3 snprintf.3 printf.3 sprintf.3 \
|
printf.3 snprintf.3 printf.3 sprintf.3 \
|
||||||
@ -38,6 +46,7 @@ MLINKS+=printf.3 asprintf.3 printf.3 fprintf.3 \
|
|||||||
printf.3 vfprintf.3 printf.3 vprintf.3 printf.3 vsnprintf.3 \
|
printf.3 vfprintf.3 printf.3 vprintf.3 printf.3 vsnprintf.3 \
|
||||||
printf.3 vsprintf.3
|
printf.3 vsprintf.3
|
||||||
MLINKS+=putc.3 fputc.3 putc.3 putchar.3 putc.3 putw.3
|
MLINKS+=putc.3 fputc.3 putc.3 putchar.3 putc.3 putw.3
|
||||||
|
MLINKS+=putwc.3 fputwc.3 putwc.3 putwchar.3
|
||||||
MLINKS+=scanf.3 fscanf.3 scanf.3 sscanf.3 scanf.3 vfscanf.3 scanf.3 vscanf.3 \
|
MLINKS+=scanf.3 fscanf.3 scanf.3 sscanf.3 scanf.3 vfscanf.3 scanf.3 vscanf.3 \
|
||||||
scanf.3 vsscanf.3
|
scanf.3 vsscanf.3
|
||||||
MLINKS+=setbuf.3 setbuffer.3 setbuf.3 setlinebuf.3 setbuf.3 setvbuf.3
|
MLINKS+=setbuf.3 setbuffer.3 setbuf.3 setlinebuf.3 setbuf.3 setvbuf.3
|
||||||
|
@ -43,6 +43,7 @@ asprintf(char **str, char const *fmt, ...)
|
|||||||
int ret;
|
int ret;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
FILE f;
|
FILE f;
|
||||||
|
struct __sFILEX ext;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
f._file = -1;
|
f._file = -1;
|
||||||
@ -54,6 +55,8 @@ asprintf(char **str, char const *fmt, ...)
|
|||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
f._bf._size = f._w = 127; /* Leave room for the NULL */
|
f._bf._size = f._w = 127; /* Leave room for the NULL */
|
||||||
|
f._extra = &ext;
|
||||||
|
INITEXTRA(&f);
|
||||||
ret = __vfprintf(&f, fmt, ap); /* Use unlocked __vfprintf */
|
ret = __vfprintf(&f, fmt, ap); /* Use unlocked __vfprintf */
|
||||||
*f._p = '\0';
|
*f._p = '\0';
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
@ -52,6 +52,7 @@ fgetc(fp)
|
|||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
FLOCKFILE(fp);
|
FLOCKFILE(fp);
|
||||||
|
ORIENT(fp, -1);
|
||||||
retval = __sgetc(fp);
|
retval = __sgetc(fp);
|
||||||
FUNLOCKFILE(fp);
|
FUNLOCKFILE(fp);
|
||||||
return (retval);
|
return (retval);
|
||||||
|
@ -66,6 +66,7 @@ fgets(buf, n, fp)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
FLOCKFILE(fp);
|
FLOCKFILE(fp);
|
||||||
|
ORIENT(fp, -1);
|
||||||
s = buf;
|
s = buf;
|
||||||
n--; /* leave space for NUL */
|
n--; /* leave space for NUL */
|
||||||
while (n != 0) {
|
while (n != 0) {
|
||||||
|
56
lib/libc/stdio/fgetwc.c
Normal file
56
lib/libc/stdio/fgetwc.c
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002 Tim J. Robbins.
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include "namespace.h"
|
||||||
|
#include <errno.h>
|
||||||
|
#include <rune.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
#include "un-namespace.h"
|
||||||
|
#include "libc_private.h"
|
||||||
|
#include "local.h"
|
||||||
|
|
||||||
|
wint_t
|
||||||
|
fgetwc(FILE *fp)
|
||||||
|
{
|
||||||
|
wint_t wc;
|
||||||
|
long r;
|
||||||
|
|
||||||
|
ORIENTLOCK(fp, 1);
|
||||||
|
|
||||||
|
if ((r = fgetrune(fp)) == _INVALID_RUNE) {
|
||||||
|
wc = WEOF;
|
||||||
|
errno = EILSEQ;
|
||||||
|
} else if (r == EOF)
|
||||||
|
wc = WEOF;
|
||||||
|
else
|
||||||
|
wc = (wint_t)r;
|
||||||
|
|
||||||
|
return (wc);
|
||||||
|
}
|
122
lib/libc/stdio/fgetws.3
Normal file
122
lib/libc/stdio/fgetws.3
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
.\" Copyright (c) 1990, 1991, 1993
|
||||||
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
|
.\"
|
||||||
|
.\" This code is derived from software contributed to Berkeley by
|
||||||
|
.\" Chris Torek and the American National Standards Committee X3,
|
||||||
|
.\" on Information Processing Systems.
|
||||||
|
.\"
|
||||||
|
.\" 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.
|
||||||
|
.\" 3. All advertising materials mentioning features or use of this software
|
||||||
|
.\" must display the following acknowledgement:
|
||||||
|
.\" This product includes software developed by the University of
|
||||||
|
.\" California, Berkeley and its contributors.
|
||||||
|
.\" 4. Neither the name of the University nor the names of its contributors
|
||||||
|
.\" may be used to endorse or promote products derived from this software
|
||||||
|
.\" without specific prior written permission.
|
||||||
|
.\"
|
||||||
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||||
|
.\"
|
||||||
|
.\" @(#)fgets.3 8.1 (Berkeley) 6/4/93
|
||||||
|
.\" FreeBSD: src/lib/libc/stdio/fgets.3,v 1.16 2002/05/31 05:01:17 archie Exp
|
||||||
|
.\" $FreeBSD$
|
||||||
|
.\"
|
||||||
|
.Dd August 6, 2002
|
||||||
|
.Dt FGETWS 3
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm fgetws
|
||||||
|
.Nd get a line of wide characters from a stream
|
||||||
|
.Sh LIBRARY
|
||||||
|
.Lb libc
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.In stdio.h
|
||||||
|
.In wchar.h
|
||||||
|
.Ft "wchar_t *"
|
||||||
|
.Fn fgetws "wchar_t *restrict ws" "int n" "FILE *restrict fp"
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
The
|
||||||
|
.Fn fgetws
|
||||||
|
function
|
||||||
|
reads at most one less than the number of characters specified by
|
||||||
|
.Fa n
|
||||||
|
from the given
|
||||||
|
.Fa fp
|
||||||
|
and stores them in the wide character string
|
||||||
|
.Fa ws .
|
||||||
|
Reading stops when a newline character is found,
|
||||||
|
at end-of-file or error.
|
||||||
|
The newline, if any, is retained.
|
||||||
|
If any characters are read and there is no error, a
|
||||||
|
.Ql \e0
|
||||||
|
character is appended to end the string.
|
||||||
|
.Sh RETURN VALUES
|
||||||
|
Upon successful completion,
|
||||||
|
.Fn fgetws
|
||||||
|
returns
|
||||||
|
.Fa ws .
|
||||||
|
If end-of-file occurs before any characters are read,
|
||||||
|
.Fn fgetws
|
||||||
|
returns
|
||||||
|
.Dv NULL
|
||||||
|
and the buffer contents remain unchanged.
|
||||||
|
If an error occurs,
|
||||||
|
.Fn fgetws
|
||||||
|
returns
|
||||||
|
.Dv NULL
|
||||||
|
and the buffer contents are indeterminate.
|
||||||
|
The
|
||||||
|
.Fn fgetws
|
||||||
|
function
|
||||||
|
does not distinguish between end-of-file and error, and callers must use
|
||||||
|
.Xr feof 3
|
||||||
|
and
|
||||||
|
.Xr ferror 3
|
||||||
|
to determine which occurred.
|
||||||
|
.Sh ERRORS
|
||||||
|
.Bl -tag -width Er
|
||||||
|
.It Bq Er EBADF
|
||||||
|
The given
|
||||||
|
.Fa fp
|
||||||
|
argument is not a readable stream.
|
||||||
|
.It Bq Er EILSEQ
|
||||||
|
The data obtained from the input stream does not form a valid
|
||||||
|
multibyte character.
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
The function
|
||||||
|
.Fn fgetws
|
||||||
|
may also fail and set
|
||||||
|
.Va errno
|
||||||
|
for any of the errors specified for the routines
|
||||||
|
.Xr fflush 3 ,
|
||||||
|
.Xr fstat 2 ,
|
||||||
|
.Xr read 2 ,
|
||||||
|
or
|
||||||
|
.Xr malloc 3 .
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr feof 3 ,
|
||||||
|
.Xr ferror 3 ,
|
||||||
|
.Xr fgets 3
|
||||||
|
.Sh STANDARDS
|
||||||
|
The
|
||||||
|
.Fn fgetws
|
||||||
|
function
|
||||||
|
conforms to
|
||||||
|
.St -p1003.1-2001 .
|
70
lib/libc/stdio/fgetws.c
Normal file
70
lib/libc/stdio/fgetws.c
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002 Tim J. Robbins.
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include "namespace.h"
|
||||||
|
#include <errno.h>
|
||||||
|
#include <rune.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
#include "un-namespace.h"
|
||||||
|
#include "libc_private.h"
|
||||||
|
#include "local.h"
|
||||||
|
|
||||||
|
wchar_t *
|
||||||
|
fgetws(wchar_t *__restrict ws, int n, FILE *__restrict fp)
|
||||||
|
{
|
||||||
|
wchar_t *wsp;
|
||||||
|
long r;
|
||||||
|
|
||||||
|
ORIENTLOCK(fp, 1);
|
||||||
|
|
||||||
|
if (n <= 0)
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
wsp = ws;
|
||||||
|
while (n-- > 1) {
|
||||||
|
/* XXX Inefficient */
|
||||||
|
if ((r = fgetrune(fp)) == _INVALID_RUNE) {
|
||||||
|
errno = EILSEQ;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
if (r == EOF) {
|
||||||
|
if (wsp == ws)
|
||||||
|
/* EOF/error, no characters read yet. */
|
||||||
|
return (NULL);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*wsp++ = (wchar_t)r;
|
||||||
|
if (r == L'\n')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*wsp++ = L'\0';
|
||||||
|
|
||||||
|
return (ws);
|
||||||
|
}
|
@ -176,6 +176,12 @@ __sfp()
|
|||||||
fp->_lb._base = NULL; /* no line buffer */
|
fp->_lb._base = NULL; /* no line buffer */
|
||||||
fp->_lb._size = 0;
|
fp->_lb._size = 0;
|
||||||
/* fp->_lock = NULL; */ /* once set always set (reused) */
|
/* fp->_lock = NULL; */ /* once set always set (reused) */
|
||||||
|
fp->_extra->orientation = 0;
|
||||||
|
#ifdef notdef
|
||||||
|
/* Stateful encoding/decoding is not yet supported. */
|
||||||
|
memset(&fp->_extra->wstate, 0, sizeof(mbstate_t));
|
||||||
|
memset(&fp->_extra->rstate, 0, sizeof(mbstate_t));
|
||||||
|
#endif
|
||||||
return (fp);
|
return (fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include "namespace.h"
|
#include "namespace.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "un-namespace.h"
|
#include "un-namespace.h"
|
||||||
|
#include "local.h"
|
||||||
#include "libc_private.h"
|
#include "libc_private.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -52,6 +53,7 @@ fputc(c, fp)
|
|||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
FLOCKFILE(fp);
|
FLOCKFILE(fp);
|
||||||
|
ORIENT(fp, -1);
|
||||||
retval = putc(c, fp);
|
retval = putc(c, fp);
|
||||||
FUNLOCKFILE(fp);
|
FUNLOCKFILE(fp);
|
||||||
return (retval);
|
return (retval);
|
||||||
|
@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include "un-namespace.h"
|
#include "un-namespace.h"
|
||||||
#include "fvwrite.h"
|
#include "fvwrite.h"
|
||||||
#include "libc_private.h"
|
#include "libc_private.h"
|
||||||
|
#include "local.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write the given string to the given file.
|
* Write the given string to the given file.
|
||||||
@ -64,6 +65,7 @@ fputs(s, fp)
|
|||||||
uio.uio_iov = &iov;
|
uio.uio_iov = &iov;
|
||||||
uio.uio_iovcnt = 1;
|
uio.uio_iovcnt = 1;
|
||||||
FLOCKFILE(fp);
|
FLOCKFILE(fp);
|
||||||
|
ORIENT(fp, -1);
|
||||||
retval = __sfvwrite(fp, &uio);
|
retval = __sfvwrite(fp, &uio);
|
||||||
FUNLOCKFILE(fp);
|
FUNLOCKFILE(fp);
|
||||||
return (retval);
|
return (retval);
|
||||||
|
46
lib/libc/stdio/fputwc.c
Normal file
46
lib/libc/stdio/fputwc.c
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002 Tim J. Robbins.
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include "namespace.h"
|
||||||
|
#include <errno.h>
|
||||||
|
#include <rune.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
#include "un-namespace.h"
|
||||||
|
#include "libc_private.h"
|
||||||
|
#include "local.h"
|
||||||
|
|
||||||
|
wint_t
|
||||||
|
fputwc(wchar_t wc, FILE *fp)
|
||||||
|
{
|
||||||
|
|
||||||
|
ORIENTLOCK(fp, 1);
|
||||||
|
|
||||||
|
return (fputrune((rune_t)wc, fp) != EOF ? (wint_t)wc : WEOF);
|
||||||
|
}
|
89
lib/libc/stdio/fputws.3
Normal file
89
lib/libc/stdio/fputws.3
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
.\" Copyright (c) 1990, 1991, 1993
|
||||||
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
|
.\"
|
||||||
|
.\" This code is derived from software contributed to Berkeley by
|
||||||
|
.\" Chris Torek and the American National Standards Committee X3,
|
||||||
|
.\" on Information Processing Systems.
|
||||||
|
.\"
|
||||||
|
.\" 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.
|
||||||
|
.\" 3. All advertising materials mentioning features or use of this software
|
||||||
|
.\" must display the following acknowledgement:
|
||||||
|
.\" This product includes software developed by the University of
|
||||||
|
.\" California, Berkeley and its contributors.
|
||||||
|
.\" 4. Neither the name of the University nor the names of its contributors
|
||||||
|
.\" may be used to endorse or promote products derived from this software
|
||||||
|
.\" without specific prior written permission.
|
||||||
|
.\"
|
||||||
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||||
|
.\"
|
||||||
|
.\" @(#)fputs.3 8.1 (Berkeley) 6/4/93
|
||||||
|
.\" FreeBSD: src/lib/libc/stdio/fputs.3,v 1.8 2001/10/01 16:08:59 ru Exp
|
||||||
|
.\" $FreeBSD$
|
||||||
|
.\"
|
||||||
|
.Dd August 6, 2002
|
||||||
|
.Dt FPUTWS 3
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm fputws
|
||||||
|
.Nd output a line of wide characters to a stream
|
||||||
|
.Sh LIBRARY
|
||||||
|
.Lb libc
|
||||||
|
.Sh SYNOPSIS
|
||||||
|
.In stdio.h
|
||||||
|
.In wchar.h
|
||||||
|
.Ft int
|
||||||
|
.Fn fputws "const wchar_t *restrict ws" "FILE *restrict fp"
|
||||||
|
.Sh DESCRIPTION
|
||||||
|
The
|
||||||
|
.Fn fputws
|
||||||
|
function writes the wide character string pointed to by
|
||||||
|
.Fa ws
|
||||||
|
to the stream pointed to by
|
||||||
|
.Fa fp .
|
||||||
|
.Sh RETURN VALUES
|
||||||
|
The
|
||||||
|
.Fn fputws
|
||||||
|
function
|
||||||
|
returns 0 on success and -1 on error.
|
||||||
|
.Sh ERRORS
|
||||||
|
.Bl -tag -width Er
|
||||||
|
.It Bq Er EBADF
|
||||||
|
The
|
||||||
|
.Fa fp
|
||||||
|
argument supplied
|
||||||
|
is not a writable stream.
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn fputws
|
||||||
|
function may also fail and set
|
||||||
|
.Va errno
|
||||||
|
for any of the errors specified for the routine
|
||||||
|
.Xr write 2 .
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr ferror 3 ,
|
||||||
|
.Xr fputs 3 ,
|
||||||
|
.Xr putwc 3 ,
|
||||||
|
.Xr stdio 3
|
||||||
|
.Sh STANDARDS
|
||||||
|
The
|
||||||
|
.Fn fputws
|
||||||
|
function conforms to
|
||||||
|
.St -p1003.1-2001 .
|
51
lib/libc/stdio/fputws.c
Normal file
51
lib/libc/stdio/fputws.c
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002 Tim J. Robbins.
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include "namespace.h"
|
||||||
|
#include <errno.h>
|
||||||
|
#include <rune.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
#include "un-namespace.h"
|
||||||
|
#include "libc_private.h"
|
||||||
|
#include "local.h"
|
||||||
|
|
||||||
|
int
|
||||||
|
fputws(const wchar_t *__restrict ws, FILE *__restrict fp)
|
||||||
|
{
|
||||||
|
|
||||||
|
ORIENTLOCK(fp, 1);
|
||||||
|
|
||||||
|
/* XXX Inefficient */
|
||||||
|
while (*ws != '\0')
|
||||||
|
if (fputrune((rune_t)*ws++, fp) == EOF)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
@ -66,6 +66,7 @@ fread(buf, size, count, fp)
|
|||||||
if ((resid = count * size) == 0)
|
if ((resid = count * size) == 0)
|
||||||
return (0);
|
return (0);
|
||||||
FLOCKFILE(fp);
|
FLOCKFILE(fp);
|
||||||
|
ORIENT(fp, -1);
|
||||||
if (fp->_r < 0)
|
if (fp->_r < 0)
|
||||||
fp->_r = 0;
|
fp->_r = 0;
|
||||||
total = resid;
|
total = resid;
|
||||||
|
51
lib/libc/stdio/fwide.c
Normal file
51
lib/libc/stdio/fwide.c
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002 Tim J. Robbins.
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include "namespace.h"
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
#include "un-namespace.h"
|
||||||
|
#include "libc_private.h"
|
||||||
|
#include "local.h"
|
||||||
|
|
||||||
|
int
|
||||||
|
fwide(FILE *fp, int mode)
|
||||||
|
{
|
||||||
|
int m;
|
||||||
|
|
||||||
|
FLOCKFILE(fp);
|
||||||
|
/* Only change the orientation if the stream is not oriented yet. */
|
||||||
|
if (mode != 0 && fp->_extra->orientation == 0)
|
||||||
|
fp->_extra->orientation = mode > 0 ? 1 : -1;
|
||||||
|
m = fp->_extra->orientation;
|
||||||
|
FUNLOCKFILE(fp);
|
||||||
|
|
||||||
|
return (m);
|
||||||
|
}
|
@ -67,6 +67,7 @@ fwrite(buf, size, count, fp)
|
|||||||
uio.uio_iovcnt = 1;
|
uio.uio_iovcnt = 1;
|
||||||
|
|
||||||
FLOCKFILE(fp);
|
FLOCKFILE(fp);
|
||||||
|
ORIENT(fp, -1);
|
||||||
/*
|
/*
|
||||||
* The usual case is success (__sfvwrite returns 0);
|
* The usual case is success (__sfvwrite returns 0);
|
||||||
* skip the divide if this happens, since divides are
|
* skip the divide if this happens, since divides are
|
||||||
|
@ -51,6 +51,7 @@ getc(FILE *fp)
|
|||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
FLOCKFILE(fp);
|
FLOCKFILE(fp);
|
||||||
|
ORIENT(fp, -1);
|
||||||
retval = __sgetc(fp);
|
retval = __sgetc(fp);
|
||||||
FUNLOCKFILE(fp);
|
FUNLOCKFILE(fp);
|
||||||
return (retval);
|
return (retval);
|
||||||
|
@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include "namespace.h"
|
#include "namespace.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "un-namespace.h"
|
#include "un-namespace.h"
|
||||||
|
#include "local.h"
|
||||||
#include "libc_private.h"
|
#include "libc_private.h"
|
||||||
|
|
||||||
#undef getchar
|
#undef getchar
|
||||||
@ -55,6 +56,7 @@ getchar()
|
|||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
FLOCKFILE(stdin);
|
FLOCKFILE(stdin);
|
||||||
|
ORIENT(stdin, -1);
|
||||||
retval = getc(stdin);
|
retval = getc(stdin);
|
||||||
FUNLOCKFILE(stdin);
|
FUNLOCKFILE(stdin);
|
||||||
return (retval);
|
return (retval);
|
||||||
|
@ -58,6 +58,8 @@ gets(buf)
|
|||||||
static char w[] =
|
static char w[] =
|
||||||
"warning: this program uses gets(), which is unsafe.\n";
|
"warning: this program uses gets(), which is unsafe.\n";
|
||||||
|
|
||||||
|
/* Orientation set by getchar(). */
|
||||||
|
|
||||||
if (!warned) {
|
if (!warned) {
|
||||||
(void) _write(STDERR_FILENO, w, sizeof(w) - 1);
|
(void) _write(STDERR_FILENO, w, sizeof(w) - 1);
|
||||||
warned = 1;
|
warned = 1;
|
||||||
|
48
lib/libc/stdio/getwc.c
Normal file
48
lib/libc/stdio/getwc.c
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002 Tim J. Robbins.
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include "namespace.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
#include "un-namespace.h"
|
||||||
|
#include "libc_private.h"
|
||||||
|
#include "local.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Synonym for fgetwc(). The only difference is that getwc(), if it is a
|
||||||
|
* macro, may evaluate `fp' more than once. Function call overhead is not
|
||||||
|
* an issue here: wchar.h #define's getwc to fgetwc.
|
||||||
|
*/
|
||||||
|
#undef getwc
|
||||||
|
wint_t
|
||||||
|
getwc(FILE *fp)
|
||||||
|
{
|
||||||
|
|
||||||
|
return (fgetwc(fp));
|
||||||
|
}
|
47
lib/libc/stdio/getwchar.c
Normal file
47
lib/libc/stdio/getwchar.c
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002 Tim J. Robbins.
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include "namespace.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
#include "un-namespace.h"
|
||||||
|
#include "libc_private.h"
|
||||||
|
#include "local.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Synonym for fgetwc(stdin). Function call overhead is not an issue here:
|
||||||
|
* wchar.h #define's getwchar() to fgetwc(stdin).
|
||||||
|
*/
|
||||||
|
#undef getwchar
|
||||||
|
wint_t
|
||||||
|
getwchar(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
return (fgetwc(stdin));
|
||||||
|
}
|
@ -39,6 +39,8 @@
|
|||||||
|
|
||||||
#include <sys/types.h> /* for off_t */
|
#include <sys/types.h> /* for off_t */
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Information local to this implementation of stdio,
|
* Information local to this implementation of stdio,
|
||||||
@ -78,6 +80,16 @@ struct __sFILEX {
|
|||||||
pthread_mutex_t fl_mutex; /* used for MT-safety */
|
pthread_mutex_t fl_mutex; /* used for MT-safety */
|
||||||
pthread_t fl_owner; /* current owner */
|
pthread_t fl_owner; /* current owner */
|
||||||
int fl_count; /* recursive lock count */
|
int fl_count; /* recursive lock count */
|
||||||
|
int orientation; /* orientation for fwide() */
|
||||||
|
#ifdef notdef
|
||||||
|
/*
|
||||||
|
* XXX These are not used yet -- they will be used to store the
|
||||||
|
* multibyte conversion state for writing and reading when
|
||||||
|
* stateful encodings are supported by the locale framework.
|
||||||
|
*/
|
||||||
|
mbstate_t wstate; /* write conversion state */
|
||||||
|
mbstate_t rstate; /* read conversion state */
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -113,4 +125,23 @@ struct __sFILEX {
|
|||||||
(fp)->_extra->fl_mutex = PTHREAD_MUTEX_INITIALIZER; \
|
(fp)->_extra->fl_mutex = PTHREAD_MUTEX_INITIALIZER; \
|
||||||
(fp)->_extra->fl_owner = NULL; \
|
(fp)->_extra->fl_owner = NULL; \
|
||||||
(fp)->_extra->fl_count = 0; \
|
(fp)->_extra->fl_count = 0; \
|
||||||
|
(fp)->_extra->orientation = 0; \
|
||||||
|
/* memset(&(fp)->_extra->wstate, 0, sizeof(mbstate_t)); */ \
|
||||||
|
/* memset(&(fp)->_extra->rstate, 0, sizeof(mbstate_t)); */ \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set the orientation for a stream. If o > 0, the stream has wide-
|
||||||
|
* orientation. If o < 0, the stream has byte-orientation.
|
||||||
|
*/
|
||||||
|
#define ORIENT(fp, o) do { \
|
||||||
|
if ((fp)->_extra->orientation == 0) \
|
||||||
|
(fp)->_extra->orientation = (o); \
|
||||||
|
} while (0)
|
||||||
|
#ifdef FLOCKFILE
|
||||||
|
#define ORIENTLOCK(fp, o) do { \
|
||||||
|
FLOCKFILE(fp); \
|
||||||
|
ORIENT(fp, o); \
|
||||||
|
FUNLOCKFILE(fp); \
|
||||||
|
} while (0)
|
||||||
|
#endif
|
||||||
|
@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include "namespace.h"
|
#include "namespace.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "un-namespace.h"
|
#include "un-namespace.h"
|
||||||
|
#include "local.h"
|
||||||
#include "libc_private.h"
|
#include "libc_private.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -60,6 +61,7 @@ putc(c, fp)
|
|||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
FLOCKFILE(fp);
|
FLOCKFILE(fp);
|
||||||
|
ORIENT(fp, -1);
|
||||||
retval = __sputc(c, fp);
|
retval = __sputc(c, fp);
|
||||||
FUNLOCKFILE(fp);
|
FUNLOCKFILE(fp);
|
||||||
return (retval);
|
return (retval);
|
||||||
|
@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include "namespace.h"
|
#include "namespace.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "un-namespace.h"
|
#include "un-namespace.h"
|
||||||
|
#include "local.h"
|
||||||
#include "libc_private.h"
|
#include "libc_private.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -64,6 +65,7 @@ putchar(c)
|
|||||||
FILE *so = stdout;
|
FILE *so = stdout;
|
||||||
|
|
||||||
FLOCKFILE(so);
|
FLOCKFILE(so);
|
||||||
|
ORIENT(so, -1);
|
||||||
retval = __sputc(c, so);
|
retval = __sputc(c, so);
|
||||||
FUNLOCKFILE(so);
|
FUNLOCKFILE(so);
|
||||||
return (retval);
|
return (retval);
|
||||||
|
48
lib/libc/stdio/putwc.c
Normal file
48
lib/libc/stdio/putwc.c
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002 Tim J. Robbins.
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include "namespace.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
#include "un-namespace.h"
|
||||||
|
#include "libc_private.h"
|
||||||
|
#include "local.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Synonym for fputwc(). The only difference is that putwc(), if it is a
|
||||||
|
* macro, may evaluate `fp' more than once. Function call overhead is not
|
||||||
|
* an issue here: wchar.h #define's putwc to fputwc.
|
||||||
|
*/
|
||||||
|
#undef putwc
|
||||||
|
wint_t
|
||||||
|
putwc(wchar_t wc, FILE *fp)
|
||||||
|
{
|
||||||
|
|
||||||
|
return (fputwc(wc, fp));
|
||||||
|
}
|
47
lib/libc/stdio/putwchar.c
Normal file
47
lib/libc/stdio/putwchar.c
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002 Tim J. Robbins.
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include "namespace.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
#include "un-namespace.h"
|
||||||
|
#include "libc_private.h"
|
||||||
|
#include "local.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Synonym for fputwc(wc, stdout). Function call overhead is not an issue here:
|
||||||
|
* wchar.h #define's putwchar(wc) to fgetwc(wc, stdout).
|
||||||
|
*/
|
||||||
|
#undef putwchar
|
||||||
|
wint_t
|
||||||
|
putwchar(wchar_t wc)
|
||||||
|
{
|
||||||
|
|
||||||
|
return (fputwc(wc, stdout));
|
||||||
|
}
|
@ -76,6 +76,8 @@ __srefill(FILE *fp)
|
|||||||
if (!__sdidinit)
|
if (!__sdidinit)
|
||||||
__sinit();
|
__sinit();
|
||||||
|
|
||||||
|
ORIENT(fp, -1);
|
||||||
|
|
||||||
fp->_r = 0; /* largely a convenience for callers */
|
fp->_r = 0; /* largely a convenience for callers */
|
||||||
|
|
||||||
/* SysV does not make this test; take it out for compatibility */
|
/* SysV does not make this test; take it out for compatibility */
|
||||||
|
@ -53,6 +53,7 @@ snprintf(char *str, size_t n, char const *fmt, ...)
|
|||||||
int ret;
|
int ret;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
FILE f;
|
FILE f;
|
||||||
|
struct __sFILEX ext;
|
||||||
|
|
||||||
on = n;
|
on = n;
|
||||||
if (n != 0)
|
if (n != 0)
|
||||||
@ -64,6 +65,8 @@ snprintf(char *str, size_t n, char const *fmt, ...)
|
|||||||
f._flags = __SWR | __SSTR;
|
f._flags = __SWR | __SSTR;
|
||||||
f._bf._base = f._p = (unsigned char *)str;
|
f._bf._base = f._p = (unsigned char *)str;
|
||||||
f._bf._size = f._w = n;
|
f._bf._size = f._w = n;
|
||||||
|
f._extra = &ext;
|
||||||
|
INITEXTRA(&f);
|
||||||
ret = __vfprintf(&f, fmt, ap);
|
ret = __vfprintf(&f, fmt, ap);
|
||||||
if (on > 0)
|
if (on > 0)
|
||||||
*f._p = '\0';
|
*f._p = '\0';
|
||||||
|
@ -51,11 +51,14 @@ sprintf(char *str, char const *fmt, ...)
|
|||||||
int ret;
|
int ret;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
FILE f;
|
FILE f;
|
||||||
|
struct __sFILEX ext;
|
||||||
|
|
||||||
f._file = -1;
|
f._file = -1;
|
||||||
f._flags = __SWR | __SSTR;
|
f._flags = __SWR | __SSTR;
|
||||||
f._bf._base = f._p = (unsigned char *)str;
|
f._bf._base = f._p = (unsigned char *)str;
|
||||||
f._bf._size = f._w = INT_MAX;
|
f._bf._size = f._w = INT_MAX;
|
||||||
|
f._extra = &ext;
|
||||||
|
INITEXTRA(&f);
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
ret = __vfprintf(&f, fmt, ap);
|
ret = __vfprintf(&f, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
.\" @(#)stdio.3 8.7 (Berkeley) 4/19/94
|
.\" @(#)stdio.3 8.7 (Berkeley) 4/19/94
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd April 19, 1994
|
.Dd August 11, 2002
|
||||||
.Dt STDIO 3
|
.Dt STDIO 3
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -194,8 +194,12 @@ without first removing their current definitions with
|
|||||||
.Dv fwopen ,
|
.Dv fwopen ,
|
||||||
.Dv getc ,
|
.Dv getc ,
|
||||||
.Dv getchar ,
|
.Dv getchar ,
|
||||||
|
.Dv getwc ,
|
||||||
|
.Dv getwchar ,
|
||||||
.Dv putc ,
|
.Dv putc ,
|
||||||
.Dv putchar ,
|
.Dv putchar ,
|
||||||
|
.Dv putwc ,
|
||||||
|
.Dv putwchar ,
|
||||||
.Dv stderr ,
|
.Dv stderr ,
|
||||||
.Dv stdin ,
|
.Dv stdin ,
|
||||||
.Dv stdout ,
|
.Dv stdout ,
|
||||||
@ -207,9 +211,13 @@ Function versions of the macro functions
|
|||||||
.Fn fileno ,
|
.Fn fileno ,
|
||||||
.Fn getc ,
|
.Fn getc ,
|
||||||
.Fn getchar ,
|
.Fn getchar ,
|
||||||
|
.Fn getwc ,
|
||||||
|
.Fn getwchar ,
|
||||||
.Fn putc ,
|
.Fn putc ,
|
||||||
|
.Fn putchar ,
|
||||||
|
.Fn putwc
|
||||||
and
|
and
|
||||||
.Fn putchar
|
.Fn putwchar
|
||||||
exist and will be used if the macro
|
exist and will be used if the macro
|
||||||
definitions are explicitly removed.
|
definitions are explicitly removed.
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
@ -225,7 +233,7 @@ library and system functions, especially
|
|||||||
The
|
The
|
||||||
.Nm
|
.Nm
|
||||||
library conforms to
|
library conforms to
|
||||||
.St -isoC .
|
.St -isoC-99 .
|
||||||
.Sh LIST OF FUNCTIONS
|
.Sh LIST OF FUNCTIONS
|
||||||
.Bl -column "Description"
|
.Bl -column "Description"
|
||||||
.It Sy "Function Description"
|
.It Sy "Function Description"
|
||||||
@ -240,12 +248,16 @@ library conforms to
|
|||||||
.It "fgetln get a line from a stream"
|
.It "fgetln get a line from a stream"
|
||||||
.It "fgetpos reposition a stream"
|
.It "fgetpos reposition a stream"
|
||||||
.It "fgets get a line from a stream"
|
.It "fgets get a line from a stream"
|
||||||
|
.It "fgetwc get next wide character from input stream"
|
||||||
|
.It "fgetws get a line of wide characters from a stream"
|
||||||
.It "fileno check and reset stream status"
|
.It "fileno check and reset stream status"
|
||||||
.It "fopen stream open functions"
|
.It "fopen stream open functions"
|
||||||
.It "fprintf formatted output conversion"
|
.It "fprintf formatted output conversion"
|
||||||
.It "fpurge flush a stream"
|
.It "fpurge flush a stream"
|
||||||
.It "fputc output a character or word to a stream"
|
.It "fputc output a character or word to a stream"
|
||||||
.It "fputs output a line to a stream"
|
.It "fputs output a line to a stream"
|
||||||
|
.It "fputwc output a wide character to a stream"
|
||||||
|
.It "fputws output a line of wide characters to a stream"
|
||||||
.It "fread binary stream input/output"
|
.It "fread binary stream input/output"
|
||||||
.It "freopen stream open functions"
|
.It "freopen stream open functions"
|
||||||
.It "fropen open a stream"
|
.It "fropen open a stream"
|
||||||
@ -254,12 +266,15 @@ library conforms to
|
|||||||
.It "fsetpos reposition a stream"
|
.It "fsetpos reposition a stream"
|
||||||
.It "ftell reposition a stream"
|
.It "ftell reposition a stream"
|
||||||
.It "funopen open a stream"
|
.It "funopen open a stream"
|
||||||
|
.It "fwide set/get orientation of stream"
|
||||||
.It "fwopen open a stream"
|
.It "fwopen open a stream"
|
||||||
.It "fwrite binary stream input/output"
|
.It "fwrite binary stream input/output"
|
||||||
.It "getc get next character or word from input stream"
|
.It "getc get next character or word from input stream"
|
||||||
.It "getchar get next character or word from input stream"
|
.It "getchar get next character or word from input stream"
|
||||||
.It "gets get a line from a stream"
|
.It "gets get a line from a stream"
|
||||||
.It "getw get next character or word from input stream"
|
.It "getw get next character or word from input stream"
|
||||||
|
.It "getwc get next wide character from input stream"
|
||||||
|
.It "getwchar get next wide character from input stream"
|
||||||
.It "mkdtemp create unique temporary file"
|
.It "mkdtemp create unique temporary file"
|
||||||
.It "mkstemp create unique temporary file"
|
.It "mkstemp create unique temporary file"
|
||||||
.It "mktemp create unique temporary file"
|
.It "mktemp create unique temporary file"
|
||||||
@ -269,6 +284,8 @@ library conforms to
|
|||||||
.It "putchar output a character or word to a stream"
|
.It "putchar output a character or word to a stream"
|
||||||
.It "puts output a line to a stream"
|
.It "puts output a line to a stream"
|
||||||
.It "putw output a character or word to a stream"
|
.It "putw output a character or word to a stream"
|
||||||
|
.It "putwc output a wide character to a stream"
|
||||||
|
.It "putwchar output a wide character to a stream"
|
||||||
.It "remove remove directory entry"
|
.It "remove remove directory entry"
|
||||||
.It "rewind reposition a stream"
|
.It "rewind reposition a stream"
|
||||||
.It "scanf input format conversion"
|
.It "scanf input format conversion"
|
||||||
@ -286,6 +303,7 @@ library conforms to
|
|||||||
.It "tmpfile temporary file routines"
|
.It "tmpfile temporary file routines"
|
||||||
.It "tmpnam temporary file routines"
|
.It "tmpnam temporary file routines"
|
||||||
.It "ungetc un-get character from input stream"
|
.It "ungetc un-get character from input stream"
|
||||||
|
.It "ungetwc un-get wide character from input stream"
|
||||||
.It "vasprintf formatted output conversion"
|
.It "vasprintf formatted output conversion"
|
||||||
.It "vfprintf formatted output conversion"
|
.It "vfprintf formatted output conversion"
|
||||||
.It "vfscanf input format conversion"
|
.It "vfscanf input format conversion"
|
||||||
|
@ -112,6 +112,9 @@ ungetc(int c, FILE *fp)
|
|||||||
int
|
int
|
||||||
__ungetc(int c, FILE *fp)
|
__ungetc(int c, FILE *fp)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
ORIENT(fp, -1);
|
||||||
|
|
||||||
if (c == EOF)
|
if (c == EOF)
|
||||||
return (EOF);
|
return (EOF);
|
||||||
if ((fp->_flags & __SRD) == 0) {
|
if ((fp->_flags & __SRD) == 0) {
|
||||||
|
46
lib/libc/stdio/ungetwc.c
Normal file
46
lib/libc/stdio/ungetwc.c
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002 Tim J. Robbins.
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include "namespace.h"
|
||||||
|
#include <errno.h>
|
||||||
|
#include <rune.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
#include "un-namespace.h"
|
||||||
|
#include "libc_private.h"
|
||||||
|
#include "local.h"
|
||||||
|
|
||||||
|
wint_t
|
||||||
|
ungetwc(wint_t wc, FILE *fp)
|
||||||
|
{
|
||||||
|
|
||||||
|
ORIENTLOCK(fp, 1);
|
||||||
|
|
||||||
|
return (fungetrune((rune_t)wc, fp) == EOF ? WEOF : wc);
|
||||||
|
}
|
@ -43,6 +43,7 @@ vasprintf(str, fmt, ap)
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
FILE f;
|
FILE f;
|
||||||
|
struct __sFILEX ext;
|
||||||
|
|
||||||
f._file = -1;
|
f._file = -1;
|
||||||
f._flags = __SWR | __SSTR | __SALC;
|
f._flags = __SWR | __SSTR | __SALC;
|
||||||
@ -53,6 +54,8 @@ vasprintf(str, fmt, ap)
|
|||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
f._bf._size = f._w = 127; /* Leave room for the NULL */
|
f._bf._size = f._w = 127; /* Leave room for the NULL */
|
||||||
|
f._extra = &ext;
|
||||||
|
INITEXTRA(&f);
|
||||||
ret = __vfprintf(&f, fmt, ap);
|
ret = __vfprintf(&f, fmt, ap);
|
||||||
*f._p = '\0';
|
*f._p = '\0';
|
||||||
f._bf._base = reallocf(f._bf._base, f._bf._size + 1);
|
f._bf._base = reallocf(f._bf._base, f._bf._size + 1);
|
||||||
|
@ -151,6 +151,7 @@ __sbprintf(FILE *fp, const char *fmt, va_list ap)
|
|||||||
fake._file = fp->_file;
|
fake._file = fp->_file;
|
||||||
fake._cookie = fp->_cookie;
|
fake._cookie = fp->_cookie;
|
||||||
fake._write = fp->_write;
|
fake._write = fp->_write;
|
||||||
|
fake._extra = fp->_extra;
|
||||||
|
|
||||||
/* set up the buffer */
|
/* set up the buffer */
|
||||||
fake._bf._base = fake._p = buf;
|
fake._bf._base = fake._p = buf;
|
||||||
|
@ -145,6 +145,8 @@ __svfscanf(FILE *fp, const char *fmt0, va_list ap)
|
|||||||
char decimal_point = localeconv()->decimal_point[0];
|
char decimal_point = localeconv()->decimal_point[0];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
ORIENT(fp, -1);
|
||||||
|
|
||||||
nassigned = 0;
|
nassigned = 0;
|
||||||
nconversions = 0;
|
nconversions = 0;
|
||||||
nread = 0;
|
nread = 0;
|
||||||
|
@ -54,6 +54,7 @@ vsnprintf(str, n, fmt, ap)
|
|||||||
size_t on;
|
size_t on;
|
||||||
int ret;
|
int ret;
|
||||||
FILE f;
|
FILE f;
|
||||||
|
struct __sFILEX ext;
|
||||||
|
|
||||||
on = n;
|
on = n;
|
||||||
if (n != 0)
|
if (n != 0)
|
||||||
@ -64,6 +65,8 @@ vsnprintf(str, n, fmt, ap)
|
|||||||
f._flags = __SWR | __SSTR;
|
f._flags = __SWR | __SSTR;
|
||||||
f._bf._base = f._p = (unsigned char *)str;
|
f._bf._base = f._p = (unsigned char *)str;
|
||||||
f._bf._size = f._w = n;
|
f._bf._size = f._w = n;
|
||||||
|
f._extra = &ext;
|
||||||
|
INITEXTRA(&f);
|
||||||
ret = __vfprintf(&f, fmt, ap);
|
ret = __vfprintf(&f, fmt, ap);
|
||||||
if (on > 0)
|
if (on > 0)
|
||||||
*f._p = '\0';
|
*f._p = '\0';
|
||||||
|
@ -52,11 +52,14 @@ vsprintf(str, fmt, ap)
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
FILE f;
|
FILE f;
|
||||||
|
struct __sFILEX ext;
|
||||||
|
|
||||||
f._file = -1;
|
f._file = -1;
|
||||||
f._flags = __SWR | __SSTR;
|
f._flags = __SWR | __SSTR;
|
||||||
f._bf._base = f._p = (unsigned char *)str;
|
f._bf._base = f._p = (unsigned char *)str;
|
||||||
f._bf._size = f._w = INT_MAX;
|
f._bf._size = f._w = INT_MAX;
|
||||||
|
f._extra = &ext;
|
||||||
|
INITEXTRA(&f);
|
||||||
ret = __vfprintf(&f, fmt, ap);
|
ret = __vfprintf(&f, fmt, ap);
|
||||||
*f._p = 0;
|
*f._p = 0;
|
||||||
return (ret);
|
return (ret);
|
||||||
|
@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "local.h"
|
||||||
|
|
||||||
static int
|
static int
|
||||||
eofread(void *, char *, int);
|
eofread(void *, char *, int);
|
||||||
@ -64,6 +65,7 @@ vsscanf(str, fmt, ap)
|
|||||||
_BSD_VA_LIST_ ap;
|
_BSD_VA_LIST_ ap;
|
||||||
{
|
{
|
||||||
FILE f;
|
FILE f;
|
||||||
|
struct __sFILEX ext;
|
||||||
|
|
||||||
f._file = -1;
|
f._file = -1;
|
||||||
f._flags = __SRD;
|
f._flags = __SRD;
|
||||||
@ -72,5 +74,7 @@ vsscanf(str, fmt, ap)
|
|||||||
f._read = eofread;
|
f._read = eofread;
|
||||||
f._ub._base = NULL;
|
f._ub._base = NULL;
|
||||||
f._lb._base = NULL;
|
f._lb._base = NULL;
|
||||||
|
f._extra = &ext;
|
||||||
|
INITEXTRA(&f);
|
||||||
return (__svfscanf(&f, fmt, ap));
|
return (__svfscanf(&f, fmt, ap));
|
||||||
}
|
}
|
||||||
|
@ -69,6 +69,8 @@ __swbuf(c, fp)
|
|||||||
return (EOF);
|
return (EOF);
|
||||||
c = (unsigned char)c;
|
c = (unsigned char)c;
|
||||||
|
|
||||||
|
ORIENT(fp, -1);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If it is completely full, flush it out. Then, in any case,
|
* If it is completely full, flush it out. Then, in any case,
|
||||||
* stuff c into the buffer. If this causes the buffer to fill
|
* stuff c into the buffer. If this causes the buffer to fill
|
||||||
|
Loading…
Reference in New Issue
Block a user