diff options
Diffstat (limited to 'stdio')
59 files changed, 0 insertions, 5580 deletions
diff --git a/stdio/.cvsignore b/stdio/.cvsignore deleted file mode 100644 index 602b74c1ae..0000000000 --- a/stdio/.cvsignore +++ /dev/null @@ -1,8 +0,0 @@ -*.d *.o *.so *.po *.go stamp.* *.stamp *.ustamp *.udeps -*.gz *.Z *.tar *.tgz -=* -TODO COPYING* AUTHORS copyr-* copying.* -glibc-* - -mpn-copy.mk -distinfo diff --git a/stdio/Makefile b/stdio/Makefile deleted file mode 100644 index 53cf73cdb4..0000000000 --- a/stdio/Makefile +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright (C) 1991,92,93,94,95,96,2001 Free Software Foundation, Inc. -# This file is part of the GNU C Library. - -# The GNU C Library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. - -# The GNU C Library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. - -# You should have received a copy of the GNU Lesser General Public -# License along with the GNU C Library; if not, write to the Free -# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -# 02111-1307 USA. - -# -# Specific makefile for stdio. -# -subdir := stdio - -headers := stdio.h linewrap.h - -routines := \ - feof ferror clearerr fileno \ - newstream fopen freopen fdopen fopncook fmemopen \ - setbuf setvbuf setbuffer setlinebuf \ - fseek ftell rewind fgetpos fsetpos \ - fread fwrite \ - ungetc \ - fgetc getc getchar \ - fputc putc putchar \ - fgets gets fputs puts \ - getdelim \ - fclose fcloseall fflush \ - vdprintf vsnprintf vsprintf vasprintf vsscanf vscanf \ - memstream obstream linewrap \ - __fbufsize __freading __fwriting __freadable __fwritable __flbf \ - __fpurge __fpending __fsetlocking \ - internals sysd-stdio pipestream stdio_init libc_fatal -aux := defs glue - - -include ../Rules diff --git a/stdio/Versions b/stdio/Versions deleted file mode 100644 index ccfda9c268..0000000000 --- a/stdio/Versions +++ /dev/null @@ -1,70 +0,0 @@ -libc { - GLIBC_2.0 { - # more or less standard functions - __fillbf; __flshfp; - - # functions used in inline functions or macros - __getdelim; __line_wrap_output; __line_wrap_update; - __vfscanf; __vsscanf; - - # variables in normal name space - stderr; stdin; stdout; - - # c* - clearerr; - - # f* - fclose; fcloseall; fdopen; feof; ferror; fflush; fgetc; fgetpos; fgets; - fileno; fmemopen; fopen; fopencookie; fputc; fputs; fread; freopen; - fseek; fsetpos; ftell; fwrite; - - # g* - getc; getchar; getdelim; gets; - - # l* - line_wrap_stream; line_unwrap_stream; line_wrapped; line_wrap_lmargin; - line_wrap_set_lmargin; line_wrap_rmargin; line_wrap_set_rmargin; - line_wrap_wmargin; line_wrap_set_wmargin; line_wrap_point; - - # o* - open_memstream; open_obstack_stream; obstack_printf; obstack_vprintf; - - # p* - pclose; popen; putc; putchar; puts; - - # r* - rewind; - - # s* - setbuf; setbuffer; setlinebuf; setvbuf; - - # u* - ungetc; - - # v* - vasprintf; vdprintf; vscanf; vsnprintf; vsprintf; vsscanf; - } - GLIBC_2.1 { - # functions used in other libraries - __asprintf; - - # c* - clearerr_unlocked; - - # f* - feof_unlocked; ferror_unlocked; fflush_unlocked; fgets_unlocked; - fileno_unlocked; fputc_unlocked; fputs_unlocked; - fread_unlocked; fwrite_unlocked; - - # g* - getc_unlocked; getchar_unlocked; - - # p* - putc_unlocked; putchar_unlocked; - } - GLIBC_2.2.4 { - # Functions to access FILE internals. - __fbufsize; __freading; __fwriting; __freadable; __fwritable; __flbf; - __fpurge; __fpending; __fsetlocking; _flushlbf; - } -} diff --git a/stdio/__fbufsize.c b/stdio/__fbufsize.c deleted file mode 100644 index ad42ee2427..0000000000 --- a/stdio/__fbufsize.c +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stdio_ext.h> - -size_t -__fbufsize (FILE *fp) -{ - return fp->__bufsize; -} diff --git a/stdio/__flbf.c b/stdio/__flbf.c deleted file mode 100644 index 9eb80abdbf..0000000000 --- a/stdio/__flbf.c +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stdio_ext.h> - -int -__flbf (FILE *fp) -{ - return fp->__linebuf; -} diff --git a/stdio/__fpending.c b/stdio/__fpending.c deleted file mode 100644 index 0e7b8f02f0..0000000000 --- a/stdio/__fpending.c +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stdio_ext.h> - -size_t -__fpending (FILE *fp) -{ - return (fp->__put_limit >= fp->__bufp ? fp->__bufp - fp->__buffer : 0); -} diff --git a/stdio/__fpurge.c b/stdio/__fpurge.c deleted file mode 100644 index db882b68f5..0000000000 --- a/stdio/__fpurge.c +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stdio_ext.h> - -void -__fpurge (FILE *fp) -{ - fp->__get_limit = fp->__put_limit = fp->__bufp = fp->__buffer; -} diff --git a/stdio/__freadable.c b/stdio/__freadable.c deleted file mode 100644 index 5674d5bef5..0000000000 --- a/stdio/__freadable.c +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stdio_ext.h> - -int -__freadable (FILE *fp) -{ - return !!fp->__mode.__read; -} diff --git a/stdio/__freading.c b/stdio/__freading.c deleted file mode 100644 index 16d0fd97f8..0000000000 --- a/stdio/__freading.c +++ /dev/null @@ -1,26 +0,0 @@ -/* Copyright (C) 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stdio_ext.h> - -int -__freading (FILE *fp) -{ - /* This is not really right for unbuffered streams. */ - return (!fp->__mode.__write || fp->__put_limit == fp->__buffer); -} diff --git a/stdio/__fsetlocking.c b/stdio/__fsetlocking.c deleted file mode 100644 index a0e40d71c9..0000000000 --- a/stdio/__fsetlocking.c +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright (C) 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stdio_ext.h> -#include <errno.h> -#include <stdlib.h> - -int -__fsetlocking (FILE *fp, int type) -{ - /* We don't really support locking. */ - - switch (type) - { - case FSETLOCKING_QUERY: - case FSETLOCKING_BYCALLER: - break; - case FSETLOCKING_INTERNAL: - abort (); - default: - __set_errno (EINVAL); - return -1; - } - - return FSETLOCKING_BYCALLER; -} diff --git a/stdio/__fwritable.c b/stdio/__fwritable.c deleted file mode 100644 index 396629542c..0000000000 --- a/stdio/__fwritable.c +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stdio_ext.h> - -int -__fwritable (FILE *fp) -{ - return !!fp->__mode.__write; -} diff --git a/stdio/__fwriting.c b/stdio/__fwriting.c deleted file mode 100644 index 36266ef34d..0000000000 --- a/stdio/__fwriting.c +++ /dev/null @@ -1,26 +0,0 @@ -/* Copyright (C) 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stdio_ext.h> - -int -__fwriting (FILE *fp) -{ - /* This is not really right for unbuffered streams. */ - return (!fp->__mode.__read || fp->__get_limit == fp->__buffer); -} diff --git a/stdio/clearerr.c b/stdio/clearerr.c deleted file mode 100644 index 02a1d77780..0000000000 --- a/stdio/clearerr.c +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright (C) 1991, 1997, 1998 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <stdio.h> - -#undef clearerr - - -/* Clear the EOF and error indicators for STREAM. */ -void -clearerr (FILE *stream) -{ - __clearerr (stream); -} - -weak_alias (clearerr, clearerr_unlocked) diff --git a/stdio/fclose.c b/stdio/fclose.c deleted file mode 100644 index 6af0903f9b..0000000000 --- a/stdio/fclose.c +++ /dev/null @@ -1,60 +0,0 @@ -/* Copyright (C) 1991, 1995, 1996, 1998 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stddef.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> - - -/* Close a stream. */ -int -fclose (stream) - FILE *stream; -{ - int status; - - if (!__validfp (stream)) - { - __set_errno (EINVAL); - return EOF; - } - - if (stream->__mode.__write && - /* Flush the buffer. */ - __flshfp (stream, EOF) == EOF) - return EOF; - - /* Free the buffer's storage. */ - if (stream->__buffer != NULL && !stream->__userbuf) - free (stream->__buffer); - - /* Close the system file descriptor. */ - if (stream->__io_funcs.__close != NULL) - status = (*stream->__io_funcs.__close) (stream->__cookie); - else if (!stream->__seen && stream->__cookie != NULL) - status = __stdio_close (stream->__cookie); - else - status = 0; - - /* Nuke the stream, making it available for re-use. */ - __invalidate (stream); - - return status < 0 ? EOF : 0; -} diff --git a/stdio/fcloseall.c b/stdio/fcloseall.c deleted file mode 100644 index b247506be1..0000000000 --- a/stdio/fcloseall.c +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright (C) 1991, 1995, 1996 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stddef.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> - - -/* Close a stream. */ -int -__fcloseall () -{ - /* Close all streams. */ - register FILE *f; - for (f = __stdio_head; f != NULL; f = f->__next) - if (__validfp(f)) - (void) fclose(f); - return 0; -} -weak_alias (__fcloseall, fcloseall) diff --git a/stdio/feof.c b/stdio/feof.c deleted file mode 100644 index 87d0463350..0000000000 --- a/stdio/feof.c +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (C) 1991, 1996, 1998 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <stdio.h> - -#undef feof -#undef feof_unlocked - -/* Return non-zero if STREAM has its EOF indicator set. */ -int -feof (stream) - FILE *stream; -{ - if (!__validfp (stream)) - { - __set_errno (EINVAL); - return -1; - } - - return stream->__eof; -} - -weak_alias (feof, feof_unlocked) diff --git a/stdio/ferror.c b/stdio/ferror.c deleted file mode 100644 index 5ccc9abb37..0000000000 --- a/stdio/ferror.c +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright (C) 1991, 1996, 1997, 1998 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <stdio.h> - -#undef ferror -#undef ferror_unlocked - - -/* Return non-zero if STREAM has its error indicator set. */ -int -ferror (stream) - FILE *stream; -{ - if (!__validfp (stream)) - { - __set_errno (EINVAL); - return -1; - } - - return stream->__error; -} - -weak_alias (ferror, ferror_unlocked) diff --git a/stdio/fflush.c b/stdio/fflush.c deleted file mode 100644 index b184e187e2..0000000000 --- a/stdio/fflush.c +++ /dev/null @@ -1,47 +0,0 @@ -/* Copyright (C) 1991, 1996, 1998 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> - -/* Flush STREAM's buffer. - If STREAM is NULL, flush the buffers of all streams that are writing. */ -int -fflush (stream) - register FILE *stream; -{ - if (stream == NULL) - { - int lossage = 0; - for (stream = __stdio_head; stream != NULL; stream = stream->__next) - if (__validfp (stream) && stream->__mode.__write) - lossage |= fflush (stream) == EOF; - return lossage ? EOF : 0; - } - - if (!__validfp (stream) || !stream->__mode.__write) - { - __set_errno (EINVAL); - return EOF; - } - - return __flshfp (stream, EOF); -} - -weak_alias(fflush, fflush_unlocked) diff --git a/stdio/fgetc.c b/stdio/fgetc.c deleted file mode 100644 index f196c3ddda..0000000000 --- a/stdio/fgetc.c +++ /dev/null @@ -1,35 +0,0 @@ -/* Copyright (C) 1991, 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <stdio.h> - - -/* Read a character from STREAM. */ -int -fgetc (stream) - FILE *stream; -{ - if (!__validfp (stream) || !stream->__mode.__read) - { - __set_errno (EINVAL); - return EOF; - } - - return __getc (stream); -} diff --git a/stdio/fgetpos.c b/stdio/fgetpos.c deleted file mode 100644 index 647d63b999..0000000000 --- a/stdio/fgetpos.c +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright (C) 1991, 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <stdio.h> - -#undef fgetpos - - -/* Put the current position of STREAM in *POS. */ -int -fgetpos (stream, pos) - FILE *stream; - fpos_t *pos; -{ - if (!__validfp (stream) || pos == NULL) - { - __set_errno (EINVAL); - return -1; - } - - *pos = ftell (stream); - if (*pos < 0L) - return -1; - return 0; -} diff --git a/stdio/fgets.c b/stdio/fgets.c deleted file mode 100644 index fbf5973a71..0000000000 --- a/stdio/fgets.c +++ /dev/null @@ -1,125 +0,0 @@ -/* Copyright (C) 1991, 92, 95, 96, 97, 98 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <stdio.h> -#include <string.h> - -/* Reads characters from STREAM into S, until either a newline character - is read, N - 1 characters have been read, or EOF is seen. Returns - the newline, unlike gets. Finishes by appending a null character and - returning S. If EOF is seen before any characters have been written - to S, the function returns NULL without appending the null character. - If there is a file error, always return NULL. */ -char * -fgets (s, n, stream) - char *s; - int n; - FILE *stream; -{ - register char *p = s; - - if (!__validfp (stream) || s == NULL || n <= 0) - { - __set_errno (EINVAL); - return NULL; - } - - if (ferror (stream)) - return NULL; - - if (stream->__buffer == NULL && stream->__userbuf) - { - /* Unbuffered stream. Not much optimization to do. */ - register int c = 0; - while (--n > 0 && (c = getc (stream)) != EOF) - if ((*p++ = c) == '\n') - break; - if (c == EOF && (p == s || ferror (stream))) - return NULL; - *p = '\0'; - return s; - } - - /* Leave space for the null. */ - --n; - - if (n > 0 && - (!stream->__seen || stream->__buffer == NULL || stream->__pushed_back)) - { - /* Do one with getc to allocate a buffer. */ - int c = getc (stream); - if (c == EOF) - return NULL; - *p++ = c; - if (c == '\n') - { - *p = '\0'; - return s; - } - else - --n; - } - - while (n > 0) - { - size_t i; - char *found; - - i = stream->__get_limit - stream->__bufp; - if (i == 0) - { - /* Refill the buffer. */ - int c = __fillbf (stream); - if (c == EOF) - break; - *p++ = c; - --n; - if (c == '\n') - { - *p = '\0'; - return s; - } - i = stream->__get_limit - stream->__bufp; - } - - if (i > (size_t) n) - i = n; - - found = (char *) __memccpy ((void *) p, stream->__bufp, '\n', i); - - if (found != NULL) - { - stream->__bufp += found - p; - p = found; - break; - } - - stream->__bufp += i; - n -= i; - p += i; - } - - if (p == s) - return NULL; - - *p = '\0'; - return ferror (stream) ? NULL : s; -} - -weak_alias (fgets, fgets_unlocked) diff --git a/stdio/fileno.c b/stdio/fileno.c deleted file mode 100644 index bfab916cb2..0000000000 --- a/stdio/fileno.c +++ /dev/null @@ -1,50 +0,0 @@ -/* Copyright (C) 1991, 93, 94, 96, 97, 98 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <stdio.h> - -/* Return the system file descriptor associated with STREAM. */ -int -fileno (stream) - FILE *stream; -{ - extern void __stdio_check_funcs __P ((FILE *)); - - if (! __validfp (stream)) - { - __set_errno (EINVAL); - return -1; - } - - __stdio_check_funcs (stream); - - if (stream->__io_funcs.__fileno == NULL) - { -#ifdef EOPNOTSUPP - __set_errno (EOPNOTSUPP); -#else - __set_errno (ENOSYS); -#endif - return -1; - } - - return (*stream->__io_funcs.__fileno) (stream->__cookie); -} - -weak_alias(fileno, fileno_unlocked) diff --git a/stdio/fmemopen.c b/stdio/fmemopen.c deleted file mode 100644 index 1ae0e5b7ae..0000000000 --- a/stdio/fmemopen.c +++ /dev/null @@ -1,109 +0,0 @@ -/* Copyright (C) 1991, 1992, 1993, 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <stddef.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - - -/* Defined in fopen.c. */ -extern int __getmode __P ((const char *mode, __io_mode *mptr)); - -/* Open a new stream that will read and/or write from the buffer in - S, which is of LEN bytes. If the mode indicates appending, the - buffer pointer is set to point to the first '\0' in the buffer. - If S is NULL, the buffer is allocated by malloc and will be freed - when the stream is closed. The only purpose of this is to write - things and then read what's been written. If LEN is zero, writes will - always return errors and reads will always return end-of-file. - - The stream is set up such that seeks and tells will always fail and - once the buffer is full of written characters or empty of characters - to read, attempted writes always return an output error and attempted - reads always return end-of-file. */ -FILE * -fmemopen (s, len, mode) - void *s; - size_t len; - const char *mode; -{ - __io_mode m; - register FILE *stream; - - if (!__getmode (mode, &m)) - return NULL; - - stream = __newstream (); - if (stream == NULL) - return NULL; - - stream->__mode = m; - - /* Input gets EOF. */ - stream->__room_funcs.__input = NULL; - /* Output gets error. */ - stream->__room_funcs.__output = NULL; - - /* Do nothing for close. */ - stream->__io_funcs.__close = NULL; - /* Can't seek outside the buffer. */ - stream->__io_funcs.__seek = NULL; - /* There is no associated file descriptor to fetch. */ - stream->__io_funcs.__fileno = NULL; - - stream->__seen = 1; - - stream->__userbuf = s != NULL && len > 0; - if (s == NULL) - { - s = malloc (len); - if (s == NULL) - { - int save = errno; - (void) fclose (stream); - __set_errno (save); - return NULL; - } - } - - stream->__buffer = (char *) s; - stream->__bufsize = len; - - stream->__bufp = stream->__buffer; - stream->__get_limit = (stream->__buffer + - (stream->__mode.__read ? stream->__bufsize : 0)); - stream->__put_limit = (stream->__buffer + - (stream->__mode.__write ? stream->__bufsize : 0)); - stream->__cookie = NULL; - - if (stream->__mode.__append) - { - char *p = memchr (stream->__bufp, '\0', - stream->__get_limit - stream->__bufp); - if (p == NULL) - stream->__bufp = stream->__get_limit; - else - stream->__bufp = p; - } - else if (stream->__mode.__truncate) - memset ((void *) stream->__buffer, 0, len); - - return stream; -} diff --git a/stdio/fopen.c b/stdio/fopen.c deleted file mode 100644 index 62e78e39bf..0000000000 --- a/stdio/fopen.c +++ /dev/null @@ -1,112 +0,0 @@ -/* Copyright (C) 1991, 92, 93, 96, 97, 98 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <ctype.h> -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - - -#define badmode() return ((__set_errno (EINVAL)), 0) - -/* Dissect the given mode string into an __io_mode. */ -int -__getmode (const char *mode, __io_mode *mptr) -{ - register unsigned char i; - - if (mode == NULL) - badmode (); - - memset ((void *) mptr, 0, sizeof (*mptr)); - - switch (*mode) - { - case 'a': - mptr->__write = mptr->__create = mptr->__append = 1; - break; - case 'w': - mptr->__write = mptr->__create = mptr->__truncate = 1; - break; - case 'r': - mptr->__read = 1; - break; - default: - badmode (); - } - - for (i = 1; i < 4; ++i) - { - switch (*++mode) - { - case '\0': - break; - case '+': - mptr->__read = mptr->__write = 1; - continue; - case 'b': - mptr->__binary = 1; - continue; - case 'x': - mptr->__exclusive = 1; - continue; - } - break; - } - - if (!mptr->__read && !mptr->__write) - badmode (); - - return 1; -} - -/* Open a new stream on the given file. */ -FILE * -fopen (filename, mode) - const char *filename; - const char *mode; -{ - FILE *stream; - __io_mode m; - - if (filename == NULL) - { - __set_errno (EINVAL); - return NULL; - } - - if (!__getmode (mode, &m)) - return NULL; - - stream = __newstream (); - if (stream == NULL) - return NULL; - - if (__stdio_open (filename, m, &stream->__cookie)) - { - int save = errno; - (void) fclose (stream); - __set_errno (save); - return NULL; - } - - stream->__mode = m; - - return stream; -} diff --git a/stdio/fopncook.c b/stdio/fopncook.c deleted file mode 100644 index adbbc48c0e..0000000000 --- a/stdio/fopncook.c +++ /dev/null @@ -1,49 +0,0 @@ -/* Copyright (C) 1991, 1992, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stdio.h> - - -/* Defined in fopen.c. */ -extern int __getmode __P ((const char *mode, __io_mode *mptr)); - -/* Open a new stream on the given magic cookie descriptor. */ -FILE * -fopencookie (cookie, mode, functions) - void *cookie; - const char *mode; - __io_functions functions; -{ - __io_mode m; - FILE *f; - - if (!__getmode (mode, &m)) - return NULL; - - f = __newstream (); - if (f == NULL) - return NULL; - - f->__cookie = cookie; - f->__mode = m; - f->__io_funcs = functions; - f->__room_funcs = __default_room_functions; - f->__seen = 1; - - return f; -} diff --git a/stdio/fputc.c b/stdio/fputc.c deleted file mode 100644 index 57d618cf07..0000000000 --- a/stdio/fputc.c +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright (C) 1991, 1996, 1997, 1998, 1999 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <stdio.h> - - -/* Write the character C to STREAM. */ -int -fputc (c, stream) - int c; - FILE *stream; -{ - if (!__validfp (stream) || !stream->__mode.__write) - { - __set_errno (EINVAL); - return EOF; - } - - return __putc (c, stream); -} - -#ifndef fputc -weak_alias (fputc, fputc_unlocked) -#endif diff --git a/stdio/fputs.c b/stdio/fputs.c deleted file mode 100644 index f2457f7fbd..0000000000 --- a/stdio/fputs.c +++ /dev/null @@ -1,35 +0,0 @@ -/* Copyright (C) 1991, 1992, 1997, 1998 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <stdio.h> -#include <string.h> - - -/* Write the string S to STREAM. */ -int -fputs (const char *s, FILE *stream) -{ - const size_t len = strlen (s); - if (len == 1) - return putc (*s, stream) == EOF ? EOF : 0; - if (fwrite ((void *) s, 1, len, stream) != len) - return EOF; - return 0; -} -weak_alias (fputs, fputs_unlocked) diff --git a/stdio/fread.c b/stdio/fread.c deleted file mode 100644 index 528c567114..0000000000 --- a/stdio/fread.c +++ /dev/null @@ -1,135 +0,0 @@ -/* Copyright (C) 1991, 92, 95, 96, 97, 98 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <stdio.h> -#include <string.h> - - -#define default_func __default_room_functions.__input - -/* Read NMEMB chunks of SIZE bytes each from STREAM into P. */ -size_t -fread (p, size, nmemb, stream) - void *p; - size_t size; - size_t nmemb; - register FILE *stream; -{ - register char *ptr = (char *) p; - register size_t to_read = size * nmemb; - size_t bytes = to_read; - - if (!__validfp (stream) || !stream->__mode.__read) - { - __set_errno (EINVAL); - return 0; - } - if (feof (stream) || ferror (stream)) - return 0; - if (p == NULL || to_read == 0) - return 0; - - if (!stream->__seen || stream->__buffer == NULL || stream->__pushed_back) - { - /* This stream has never been seen before, or it has a character - pushed back. Call __fillbf to deal with those cases. Life will - be simpler after this call. */ - int c = __fillbf (stream); - if (c == EOF) - return 0; - *ptr++ = c; - if (--to_read == 0) - return 1; - } - - read_from_buffer:; - if (stream->__bufp < stream->__get_limit) - { - /* First off, empty out the buffer. */ - register size_t copy = stream->__get_limit - stream->__bufp; - if (copy > to_read) - copy = to_read; - to_read -= copy; - if (copy > 20) - memcpy((void *) ptr, (void *) stream->__bufp, copy); - else - { - register size_t i; - for (i = 0; i < copy; ++i) - ptr[i] = stream->__bufp[i]; - } - stream->__bufp += copy; - if (to_read == 0) - return nmemb; - ptr += copy; - } - - /* Reading directly into the user's buffer doesn't help when - using a user-specified input buffer filling/expanding function, - so we don't do it in that case. */ - if (to_read >= stream->__bufsize && - stream->__room_funcs.__input == default_func && - stream->__offset == stream->__target) - { - /* Read directly into the user's buffer. */ - if (stream->__io_funcs.__read != NULL) - while (to_read > 0) - { - register int count; - count = (*stream->__io_funcs.__read) (stream->__cookie, - ptr, to_read); - if (count > 0) - { - to_read -= count; - if (stream->__offset != -1) - { - stream->__offset += count; - stream->__target += count; - } - ptr += count; - } - else if (count == 0) - { - stream->__eof = 1; - break; - } - else - { - stream->__error = 1; - break; - } - } - else - stream->__eof = 1; - } - else - { - int c = __fillbf (stream); - if (c == EOF) - return (bytes - to_read) / size; - *ptr++ = (char) c; - --to_read; - if (to_read > 0) - goto read_from_buffer; - } - - return (bytes - to_read) / size; -} - -weak_alias (fread, fread_unlocked) diff --git a/stdio/freopen.c b/stdio/freopen.c deleted file mode 100644 index dc4ff3feb1..0000000000 --- a/stdio/freopen.c +++ /dev/null @@ -1,75 +0,0 @@ -/* Copyright (C) 1991, 1994, 1995, 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <stdio.h> - - -/* Defined in fopen.c. */ -extern int __getmode __P ((const char *, __io_mode *)); - -/* Defined in sysd-stdio.c. */ -extern int __stdio_reopen __P ((const char *filename, __io_mode mode, - void *cookieptr, __io_close_fn closefn)); - -/* Replace STREAM, opening it on FILENAME. */ -FILE * -freopen (filename, mode, stream) - const char *filename; - const char *mode; - register FILE *stream; -{ - __io_mode m; - void *cookie; - - if (!__getmode (mode, &m)) - { - (void) fclose (stream); - __set_errno (EINVAL); - return NULL; - } - - if (stream->__mode.__write) - /* Flush the stream. */ - (void) fflush (stream); - - /* Open the file, attempting to preserve the old cookie value. */ - cookie = stream->__cookie; - if (__stdio_reopen (filename, m, &cookie, - stream->__seen ? - stream->__io_funcs.__close : - __stdio_close)) - { - int save = errno; - (void) fclose (stream); - __set_errno (save); - return NULL; - } - - /* Close the stream, first disabling its cookie close function because - __stdio_reopen has already dealt with closing the old cookie. */ - stream->__seen = 1; /* It might have no functions yet. */ - stream->__io_funcs.__close = NULL; - (void) fclose (stream); - - stream->__magic = _IOMAGIC; - stream->__cookie = cookie; - stream->__mode = m; - - return stream; -} diff --git a/stdio/fseek.c b/stdio/fseek.c deleted file mode 100644 index fb2e580fd0..0000000000 --- a/stdio/fseek.c +++ /dev/null @@ -1,179 +0,0 @@ -/* Copyright (C) 1991, 92, 93, 95, 96, 97 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <stdio.h> - - -/* Move the file position of STREAM to OFFSET - bytes from the beginning of the file if WHENCE - is SEEK_SET, the end of the file is it is SEEK_END, - or the current position if it is SEEK_CUR. */ -int -fseek (stream, offset, whence) - register FILE *stream; - long int offset; - int whence; -{ - long int o; - - if (!__validfp (stream)) - { - __set_errno (EINVAL); - return EOF; - } - - /* Write out any pending data. */ - if (stream->__mode.__write && __flshfp (stream, EOF) == EOF) - return EOF; - - /* Make sure we know the current offset info. */ - stream->__offset = -1; - if (__stdio_check_offset (stream) == EOF) - return EOF; - - /* We are moving the file position, so we are no longer at EOF. */ - stream->__eof = 0; - - if (stream->__pushed_back) - { - /* Discard the character pushed back by ungetc. */ - stream->__bufp = stream->__pushback_bufp; - stream->__pushed_back = 0; - } - - /* Check the WHENCE argument for validity, and process OFFSET - into an absolute position in O. By the end of this switch, - either we have returned, or O contains an absolute position. */ - o = offset; - switch (whence) - { - default: - __set_errno (EINVAL); - return EOF; - - case SEEK_END: - /* We don't know where the end of the file is, - so seek to the position in the file the user asked - for, and then look where that is. */ - if (stream->__io_funcs.__seek == NULL) - { - __set_errno (ESPIPE); - return EOF; - } - else - { - fpos_t pos = (fpos_t) o; - if ((*stream->__io_funcs.__seek) - (stream->__cookie, &pos, SEEK_END) < 0) - { - if (errno == ESPIPE) - stream->__io_funcs.__seek = NULL; - return EOF; - } - stream->__offset = pos; - /* Make O be absolute, rather than - relative to the end of the file. */ - o = pos; - } - - /* Fall through to try an absolute seek. */ - - case SEEK_SET: - /* Make O be relative to the buffer. */ - o -= stream->__target; - /* Make O be relative to the current position in the buffer. */ - o -= stream->__bufp - stream->__buffer; - - /* Fall through to see if we can do it by - moving the pointer around in the buffer. */ - - case SEEK_CUR: - /* If the offset is small enough, we can just - move the pointer around in the buffer. */ - -#if 0 /* Why did I think this would ever work??? */ - if (stream->__put_limit > stream->__buffer) - { - /* We are writing. */ - if (stream->__bufp + o >= stream->__buffer && - stream->__put_limit > stream->__bufp + o && - stream->__get_limit > stream->__bufp + o) - { - /* We have read all the data we will change soon. - We can just move the pointer around. */ - stream->__bufp += o; - return 0; - } - else - { - /* Flush the buffer. */ - if (__flshfp(stream, EOF) == EOF) - return EOF; - } - } else -#endif - if (o < 0 ? - (-o <= stream->__bufp - stream->__buffer) : - (o <= stream->__get_limit - stream->__bufp)) - { - stream->__bufp += o; - return 0; - } - - /* Turn it into an absolute seek. */ - o += stream->__bufp - stream->__buffer; - o += stream->__target; - break; - } - - if (o < 0) - { - /* Negative file position is meaningless. */ - __set_errno (EINVAL); - return -1; - } - - /* O is now an absolute position, the new target. */ - stream->__target = o; - - /* Set bufp and both end pointers to the beginning of the buffer. - The next i/o will force a call to the input/output room function. */ - stream->__bufp - = stream->__get_limit = stream->__put_limit = stream->__buffer; - - /* Make sure __flshfp doesn't think the put_limit is at the beginning - of the buffer because of line-buffering magic. */ - stream->__linebuf_active = 0; - - /* If there is no seek function, seeks always fail. */ - if (stream->__io_funcs.__seek == NULL) - { - /* This is preemptive, since we don't actually do the seeking. - But it makes more sense for fseek to to fail with ESPIPE - than for the next reading or writing operation to fail - that way. */ - __set_errno (ESPIPE); - return EOF; - } - - /* Don't actually seek. The next reading or writing operation - will force a call to the input or output room function, - which will move to the target file position before reading or writing. */ - return 0; -} diff --git a/stdio/fsetpos.c b/stdio/fsetpos.c deleted file mode 100644 index 073644369f..0000000000 --- a/stdio/fsetpos.c +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright (C) 1991, 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <stdio.h> - -#undef fsetpos - - -/* Set the file position of STREAM to *POS. */ -int -fsetpos (stream, pos) - FILE *stream; - const fpos_t *pos; -{ - if (pos == NULL) - { - __set_errno (EINVAL); - return EOF; - } - - return fseek (stream, *pos, SEEK_SET); -} diff --git a/stdio/ftell.c b/stdio/ftell.c deleted file mode 100644 index 03c3ebc332..0000000000 --- a/stdio/ftell.c +++ /dev/null @@ -1,54 +0,0 @@ -/* Copyright (C) 1991, 1992, 1994, 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <stdio.h> - -/* Return the offset in bytes from the beginning - of the file of the file position of STREAM. */ -long int -ftell (stream) - FILE *stream; -{ - long int pos; - - if (!__validfp (stream)) - { - __set_errno (EINVAL); - return -1L; - } - - if (__stdio_check_offset (stream) == EOF) - return -1L; - - /* Start with the file position associated with the beginning - of our buffer. */ - pos = stream->__target; - - if (stream->__pushed_back) - /* ungetc was just called, so our real buffer pointer is squirreled - away in STREAM->__pushback_bufp, not in STREAM->__bufp as normal. - Calling ungetc is supposed to decrement the file position. ANSI - says the file position is unspecified if you ungetc when the - position is zero; -1 seems as good as anything to me. */ - pos += stream->__pushback_bufp - stream->__buffer - 1; - else - pos += stream->__bufp - stream->__buffer; - - return pos; -} diff --git a/stdio/fwrite.c b/stdio/fwrite.c deleted file mode 100644 index 588e40b48f..0000000000 --- a/stdio/fwrite.c +++ /dev/null @@ -1,222 +0,0 @@ -/* Copyright (C) 1991, 92, 93, 94, 96, 97, 98 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <stdio.h> -#include <string.h> - - -/* Write NMEMB chunks of SIZE bytes each from PTR onto STREAM. */ -size_t -fwrite (ptr, size, nmemb, stream) - const void *ptr; - size_t size; - size_t nmemb; - register FILE *stream; -{ - register const unsigned char *p = (const unsigned char *) ptr; - register size_t to_write = size * nmemb; - register size_t written = 0; - int newlinep; - size_t buffer_space; - int default_func; - - if (!__validfp (stream) || !stream->__mode.__write) - { - __set_errno (EINVAL); - return 0; - } - - if (ferror (stream)) - return 0; - if (p == NULL || to_write == 0) - return 0; - - if (!stream->__seen || stream->__put_limit == stream->__buffer) - { - /* This stream has never been seen before. - Calling __flshfp will give it a buffer - and I/O functions if it needs them. */ - if (__flshfp (stream, *p++) == EOF) - return 0; - if (--to_write == 0) - return 1; - else - ++written; - } - - default_func - = stream->__room_funcs.__output == __default_room_functions.__output; - - { - int save = errno; - - if (__stdio_check_offset (stream) == EOF && errno != ESPIPE) - { - stream->__error = 1; - goto done; - } - - __set_errno (save); - } - - if (stream->__buffer == NULL && default_func && - stream->__offset == stream->__target) - write_through: - /* This is an unbuffered stream using the standard output - buffer-flushing function, so we just do a straight write. */ - { - int count = (stream->__io_funcs.__write == NULL ? to_write : - (*stream->__io_funcs.__write) (stream->__cookie, - (const char *) p, - to_write)); - if (count > 0) - { - written += count; - if (stream->__offset != -1) - { - stream->__offset += count; - stream->__target = stream->__offset; - } - to_write -= count; - p += count; - } - else - stream->__error = 1; - goto done; - } - - /* We ignore the end pointer here since we want to find out how much space - is really in the buffer, even for a line-buffered stream. */ - buffer_space = stream->__bufsize - (stream->__bufp - stream->__buffer); - - newlinep = (stream->__linebuf && - memchr ((const void *) p, '\n', to_write) != NULL); - - if (newlinep && stream->__bufp == stream->__buffer && - stream->__offset == stream->__target) - /* The buffer's empty, and we want to write our data - out soon anyway, so just write it straight out. */ - goto write_through; - - if (stream->__bufsize == 0 && !default_func) - { - /* No buffer, and a special function. - We can't do much better than putc. */ - while (to_write-- > 0) - { - if (__flshfp (stream, *p++) == EOF) - break; - else - ++written; - } - } - else if (!default_func || buffer_space >= to_write) - { - /* There is enough room in the buffer for everything we want to write - or the user has specified his own output buffer-flushing/expanding - function. */ - fill_buffer: - while (to_write > 0) - { - register size_t n = to_write; - - if (n > buffer_space) - n = buffer_space; - - buffer_space -= n; - - written += n; - to_write -= n; - - if (n < 20) - while (n-- > 0) - *stream->__bufp++ = *p++; - else - { - memcpy ((void *) stream->__bufp, (void *) p, n); - stream->__bufp += n; - p += n; - } - - if (to_write == 0) - /* Done writing. */ - break; - else if (buffer_space == 0) - { - /* We have filled the buffer, so flush it. */ - if (fflush (stream) == EOF) - break; - - /* Reset our record of the space available in the buffer, - since we have just flushed it. */ - check_space: - buffer_space = (stream->__bufsize - - (stream->__bufp - stream->__buffer)); - if (buffer_space == 0) - { - /* With a custom output-room function, flushing might - not create any buffer space. Try writing a single - character to create the space. */ - if (__flshfp (stream, *p++) == EOF) - goto done; - ++written; - --to_write; - goto check_space; - } - } - } - - /* We have written all the data into the buffer. If we are - line-buffered and just put a newline in the buffer, flush now to - make sure it gets out. */ - if (newlinep) - fflush (stream); - } - else - { - /* It won't all fit in the buffer. */ - - if (stream->__bufp != stream->__buffer) - { - /* There are characters in the buffer. Flush them. */ - if (__flshfp (stream, EOF) == EOF) - goto done; - } - - /* The buffer has been flushed. - Now either fill it or write directly. */ - - buffer_space = stream->__bufsize - (stream->__bufp - stream->__buffer); - - if (stream->__offset == stream->__target && - (buffer_space < to_write || newlinep)) - /* What we have to write is bigger than the buffer, - or it contains a newline and we're line-buffered, - so write it out. */ - goto write_through; - else - /* It will fit in the buffer. */ - goto fill_buffer; - } - - done:; - return (size_t) written / size; -} - -weak_alias (fwrite, fwrite_unlocked) diff --git a/stdio/getc.c b/stdio/getc.c deleted file mode 100644 index eee136a902..0000000000 --- a/stdio/getc.c +++ /dev/null @@ -1,6 +0,0 @@ -#include <stdio.h> -#undef getc -#define fgetc getc -#include <fgetc.c> - -weak_alias (getc, getc_unlocked) diff --git a/stdio/getchar.c b/stdio/getchar.c deleted file mode 100644 index 49f47c41ac..0000000000 --- a/stdio/getchar.c +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright (C) 1991, 1997, 1998 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stdio.h> - -#undef getchar - - -/* Read a character from stdin. */ -int -getchar (void) -{ - return __getc (stdin); -} - -weak_alias (getchar, getchar_unlocked) diff --git a/stdio/getdelim.c b/stdio/getdelim.c deleted file mode 100644 index b8c9e74950..0000000000 --- a/stdio/getdelim.c +++ /dev/null @@ -1,177 +0,0 @@ -/* Copyright (C) 1991, 1992, 1995, 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stddef.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <limits.h> -#include <errno.h> - -/* Read up to (and including) a TERMINATOR from STREAM into *LINEPTR - (and null-terminate it). *LINEPTR is a pointer returned from malloc (or - NULL), pointing to *N characters of space. It is realloc'd as - necessary. Returns the number of characters read (not including the - null terminator), or -1 on error or EOF. */ - -ssize_t -__getdelim (lineptr, n, terminator, stream) - char **lineptr; - size_t *n; - int terminator; - FILE *stream; -{ - char *line, *p; - size_t size, copy; - - if (!__validfp (stream) || lineptr == NULL || n == NULL) - { - __set_errno (EINVAL); - return -1; - } - - if (ferror (stream)) - return -1; - - /* Make sure we have a line buffer to start with. */ - if (*lineptr == NULL || *n < 2) /* !seen and no buf yet need 2 chars. */ - { -#ifndef MAX_CANON -#define MAX_CANON 256 -#endif - line = realloc (*lineptr, MAX_CANON); - if (line == NULL) - return -1; - *lineptr = line; - *n = MAX_CANON; - } - - line = *lineptr; - size = *n; - - copy = size; - p = line; - - if (stream->__buffer == NULL && stream->__userbuf) - { - /* Unbuffered stream. Not much optimization to do. */ - - while (1) - { - size_t len; - - while (--copy > 0) - { - register int c = getc (stream); - if (c == EOF) - goto lose; - else if ((*p++ = c) == terminator) - goto win; - } - - /* Need to enlarge the line buffer. */ - len = p - line; - size *= 2; - line = realloc (line, size); - if (line == NULL) - goto lose; - *lineptr = line; - *n = size; - p = line + len; - copy = size - len; - } - } - else - { - /* Leave space for the terminating null. */ - --copy; - - if (!stream->__seen || stream->__buffer == NULL || stream->__pushed_back) - { - /* Do one with getc to allocate a buffer. */ - int c = getc (stream); - if (c == EOF) - goto lose; - *p++ = c; - if (c == terminator) - goto win; - --copy; - } - - while (1) - { - size_t i; - char *found; - - i = stream->__get_limit - stream->__bufp; - if (i == 0) - { - /* Refill the buffer. */ - int c = __fillbf (stream); - if (c == EOF) - goto lose; - *p++ = c; - if (c == terminator) - goto win; - --copy; - i = stream->__get_limit - stream->__bufp; - } - - if (i > copy) - i = copy; - - found = (char *) __memccpy ((void *) p, stream->__bufp, - terminator, i); - if (found != NULL) - { - stream->__bufp += found - p; - p = found; - goto win; - } - - stream->__bufp += i; - p += i; - copy -= i; - if (copy == 0) - { - /* Need to enlarge the line buffer. */ - size_t len = p - line; - size *= 2; - line = realloc (line, size); - if (line == NULL) - goto lose; - *lineptr = line; - *n = size; - p = line + len; - copy = size - len; - /* Leave space for the terminating null. */ - --copy; - } - } - } - - lose: - if (p == *lineptr) - return -1; - /* Return a partial line since we got an error in the middle. */ - win: - *p = '\0'; - return p - *lineptr; -} - -weak_alias (__getdelim, getdelim) diff --git a/stdio/gets.c b/stdio/gets.c deleted file mode 100644 index 992e17f8ac..0000000000 --- a/stdio/gets.c +++ /dev/null @@ -1,59 +0,0 @@ -/* Copyright (C) 1991, 1994, 1995, 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stdio.h> -#include <errno.h> -#include <string.h> - -link_warning (gets, "the `gets' function is dangerous and should not be used.") - -/* Read a newline-terminated string from stdin into S, - removing the trailing newline. Return S or NULL. */ -char * -gets (s) - char *s; -{ - register char *p = s; - register int c; - FILE *stream = stdin; - - if (!__validfp (stream) || p == NULL) - { - __set_errno (EINVAL); - return NULL; - } - - if (feof (stream) || ferror (stream)) - return NULL; - - while ((c = getchar ()) != EOF) - if (c == '\n') - break; - else - *p++ = c; - - *p = '\0'; - - /* Return null if we had an error, or if we got EOF - before writing any characters. */ - - if (ferror (stream) || (feof (stream) && p == s)) - return NULL; - - return s; -} diff --git a/stdio/glue.c b/stdio/glue.c deleted file mode 100644 index a320f461ea..0000000000 --- a/stdio/glue.c +++ /dev/null @@ -1,112 +0,0 @@ -/* Copyright (C) 1991, 1992, 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* This file provides glue between Unix stdio and GNU stdio. - It supports use of Unix stdio `getc' and `putc' (and, by extension, - `getchar' and `putchar') macros on GNU stdio streams (they are slow, but - they work). It also supports all stdio operations (including Unix - `getc' and `putc') on Unix's stdin, stdout, and stderr (the elements of - `_iob'). - - The reasoning behind this is to allow programs (and especially - libraries) compiled with Unix header files to work with the GNU C - library. */ - -#include <stdio.h> -#include <errno.h> - -typedef union - { - struct - { - int magic; - FILE **streamp; /* Overlaps GNU stdio `bufp' member. */ - /* These two overlap the GNU stdio `get_limit' and `put_limit' - members. They must be <= `streamp'/`bufp' for GNU getc and putc - to do the right thing. */ - FILE **streamp2, **streamp3; - } glue; - struct _iobuf - { - int _cnt; - unsigned char *_ptr; - unsigned char *_base; - int _bufsiz; - short int _flag; - char _file; - } unix_iobuf; - FILE gnu_stream; - } unix_FILE; - -/* These are the Unix stdio's stdin, stdout, and stderr. - In Unix stdin is (&_iob[0]), stdout is (&_iob[1]), and stderr is - (&_iob[2]). The magic number marks these as glued streams. The - __validfp macro in stdio.h is used by every stdio function. It checks - for glued streams, and replaces them with the GNU stdio stream. */ -unix_FILE _iob[] = - { -#define S(name) { { _GLUEMAGIC, &name, &name, &name } } - S (stdin), - S (stdout), - S (stderr), -#undef S - }; - -/* Called by the Unix stdio `getc' macro. - The macro is assumed to look something like: - (--file->_cnt < 0 ? _filbuf (file) ...) - In a Unix stdio FILE `_cnt' is the first element. - In a GNU stdio or glued FILE, the first element is the magic number. */ -int -_filbuf (unix_FILE *file) -{ - switch (++file->glue.magic) /* Compensate for Unix getc's decrement. */ - { - case _GLUEMAGIC: - /* This is a glued stream. */ - return getc (*file->glue.streamp); - - case _IOMAGIC: - /* This is a normal GNU stdio stream. */ - return getc ((FILE *) file); - - default: - /* Bogus stream. */ - __set_errno (EINVAL); - return EOF; - } -} - -/* Called by the Unix stdio `putc' macro. Much like getc, above. */ -int -_flsbuf (int c, unix_FILE *file) -{ - /* Compensate for putc's decrement. */ - switch (++file->glue.magic) - { - case _GLUEMAGIC: - return putc (c, *file->glue.streamp); - - case _IOMAGIC: - return putc (c, (FILE *) file); - - default: - __set_errno (EINVAL); - return EOF; - } -} diff --git a/stdio/internals.c b/stdio/internals.c deleted file mode 100644 index 81f15deb18..0000000000 --- a/stdio/internals.c +++ /dev/null @@ -1,688 +0,0 @@ -/* Copyright (C) 1991, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - - -/* Make sure that FP has its functions set. */ -void -__stdio_check_funcs (register FILE *fp) -{ - if (!fp->__seen) - { - /* Initialize the stream's info, including buffering info. - This may give a buffer, change I/O functions, etc. - If no buffer is set (and the stream is not made explicitly - unbuffered), we allocate a buffer below, using the bufsize - set by this function. */ - extern void __stdio_init_stream __P ((FILE *)); - fp->__room_funcs = __default_room_functions; - fp->__io_funcs = __default_io_functions; - __stdio_init_stream (fp); - fp->__seen = 1; - } -} - - -/* Minimum size of a buffer we will allocate by default. - If this much memory is not available, - the stream in question will be made unbuffered instead. */ -#define MIN_BUFSIZE 128 - -/* Figure out what kind of buffering (none, line, or full) - and what buffer size to give FP. */ -static void -init_stream (register FILE *fp) -{ - __stdio_check_funcs (fp); - - if (fp->__buffer == NULL && !fp->__userbuf) - { - int save; - - if (fp->__bufsize == 0) - fp->__bufsize = BUFSIZ; - - /* Try to get however many bytes of buffering __stdio_pickbuf - specified, but if that much memory isn't available, - try half as much each time until it succeeds or the buffer - size becomes too small to be useful. */ - save = errno; - while (fp->__bufsize >= MIN_BUFSIZE) - { - fp->__buffer = (char *) malloc (fp->__bufsize); - if (fp->__buffer == NULL) - fp->__bufsize /= 2; - else - break; - } - __set_errno (save); - - if (fp->__buffer == NULL) - { - /* We can't get space for the buffer, so make it unbuffered. */ - fp->__userbuf = 1; - fp->__bufsize = 0; - } - } - - if (fp->__bufp == NULL) - { - /* Set the buffer pointer to the beginning of the buffer. */ - fp->__bufp = fp->__buffer; - fp->__put_limit = fp->__get_limit = fp->__buffer; - } -} - - -/* Determine the current file position of STREAM if it is unknown. */ -int -__stdio_check_offset (stream) - FILE *stream; -{ - init_stream (stream); - - if (stream->__offset == (fpos_t) -1) - { - /* This stream's offset is unknown or unknowable. */ - if (stream->__io_funcs.__seek == NULL) - { - /* Unknowable. */ - __set_errno (ESPIPE); - return EOF; - } - else - { - /* Unknown. Find it out. */ - fpos_t pos = (fpos_t) 0; - if ((*stream->__io_funcs.__seek) (stream->__cookie, - &pos, SEEK_CUR) < 0) - { - if (errno == ESPIPE) - /* Object is incapable of seeking. */ - stream->__io_funcs.__seek = NULL; - return EOF; - } - stream->__offset = pos; - } - } - - if (stream->__target == (fpos_t) -1) - /* This stream was opened on an existing object with - an unknown file position. The position is now known. - Make this the target position. */ - stream->__target = stream->__offset; - - return 0; -} - - -/* Move FP's file position to its target file position, - seeking as necessary and updating its `offset' field. - Sets ferror(FP) (and possibly errno) for errors. */ -static void -seek_to_target (FILE *fp) -{ - int save = errno; - if (__stdio_check_offset (fp) == EOF) - { - if (errno == ESPIPE) - __set_errno (save); - else - fp->__error = 1; - } - else if (fp->__target != fp->__offset) - { - /* We are not at the target file position. - Seek to that position. */ - if (fp->__io_funcs.__seek == NULL) - { - /* We can't seek! */ - __set_errno (ESPIPE); - fp->__error = 1; - } - else - { - fpos_t pos = fp->__target; - if ((*fp->__io_funcs.__seek) (fp->__cookie, &pos, SEEK_SET) < 0) - /* Seek failed! */ - fp->__error = 1; - else - { - fp->__offset = pos; - if (pos != fp->__target) - { - /* Seek didn't go to the right place! - This should never happen. */ -#ifdef EGRATUITOUS - /* It happens in the Hurd when the io server doesn't - obey the protocol for io_seek. */ - __set_errno (EGRATUITOUS); -#else - /* I don't think this can happen in Unix. */ - __set_errno (ESPIPE); /* ??? */ -#endif - fp->__error = 1; - } - } - } - } -} - -/* Flush the buffer for FP. - If C is not EOF, it is also to be written. - If the stream is line buffered and C is a newline, it is written - to the output, otherwise it is put in the buffer after it has been - flushed to avoid a system call for a single character. - This is the default `output room' function. */ -static void -flushbuf (register FILE *fp, int c) -{ - int flush_only = c == EOF; - size_t buffer_written; - size_t to_write; - - /* Set if target and get_limit have already been twiddled appropriately. */ - int twiddled = 0; - - if (fp->__put_limit == fp->__buffer) - { - /* The stream needs to be primed for writing. */ - - size_t buffer_offset = 0; - - if (fp->__target == -1) - /* For an unseekable object, data recently read bears no relation - to data we will write later. Discard the buffer. */ - fp->__get_limit = fp->__buffer; - else - /* If the user has read some of the buffer, the target position - is incremented for each character he has read. */ - fp->__target += fp->__bufp - fp->__buffer; - - if (fp->__mode.__read && fp->__room_funcs.__input != NULL && - !fp->__mode.__append) - { - int save = errno; - const int aligned = (fp->__buffer == NULL || - __stdio_check_offset (fp) == EOF || - fp->__target % fp->__bufsize == 0); - __set_errno (save); - - if (!aligned) - { - /* Move to a block (buffer size) boundary and read in a block. - Then the output will be written as a whole block, too. */ - const size_t o = fp->__target % fp->__bufsize; - fp->__target -= o; - if ((*fp->__room_funcs.__input) (fp) == EOF && ferror (fp)) - return; - else - __clearerr (fp); - - if ((size_t) (fp->__get_limit - fp->__buffer) < o) - /* Oops. We didn't read enough (probably because we got EOF). - Forget we even mentioned it. */ - fp->__target += o; - else - /* Start bufp as far into the buffer as we were into - this block before we read it. */ - buffer_offset = o; - - /* The target position is now set to where the beginning of the - buffer maps to; and the get_limit was set by the input-room - function. */ - twiddled = 1; - } - } - - if (fp->__buffer != NULL) - { - /* Set up to write output into the buffer. */ - fp->__put_limit = fp->__buffer + fp->__bufsize; - fp->__bufp = fp->__buffer + buffer_offset; - - if (!flush_only) - { - /* Put C in the buffer to be written out. - We only need to actually write it out now if - it is a newline on a line-buffered stream. */ - *fp->__bufp++ = (unsigned char) c; - if (!fp->__linebuf || (unsigned char) c != '\n') - { - /* There is no need to flush C from the buffer right now. - Record that nothing was written from the buffer, - and go do clean-up at end. */ - buffer_written = 0; - goto end; - } - else - /* We put C in the buffer, so don't write it again later. */ - flush_only = 1; - } - } - - if ((size_t) (fp->__bufp - fp->__buffer) <= buffer_offset && flush_only) - { - /* There is nothing new in the buffer, only data that - was read back aligned from the file. */ - buffer_written = 0; - goto end; - } - } - - /* If there is read data in the buffer past what was written, - write all of that as well. Otherwise, just write what has been - written into the buffer. */ - buffer_written = fp->__bufp - fp->__buffer; - to_write = (buffer_written == 0 ? 0 : - fp->__get_limit > fp->__bufp ? - fp->__get_limit - fp->__buffer : - buffer_written); - - if (fp->__io_funcs.__write == NULL || (to_write == 0 && flush_only)) - { - /* There is no writing function or we're coming from an fflush - call with nothing in the buffer, so just say the buffer's - been flushed, increment the file offset, and return. */ - fp->__bufp = fp->__buffer; - if (fp->__offset != -1) - fp->__offset += to_write; - goto end; - } - - if (to_write > 0) - { - int wrote; - - /* Go to the target file position. Don't bother if appending; - the write will just ignore the file position anyway. */ - if (!fp->__mode.__append) - seek_to_target (fp); - - if (!ferror(fp)) - { - /* Write out the buffered data. */ - wrote = (*fp->__io_funcs.__write) (fp->__cookie, fp->__buffer, - to_write); - if (wrote > 0) - { - if (fp->__mode.__append) - /* The write has written the data to the end of the file - and updated the file position to after the data. Don't - bother to find the current position; we can get it - later if we need it. */ - fp->__offset = fp->__target = -1; - else if (fp->__offset != -1) - /* Record that we've moved forward in the file. */ - fp->__offset += wrote; - } - if (wrote < (int) to_write) - /* The writing function should always write - the whole buffer unless there is an error. */ - fp->__error = 1; - } - } - - /* Reset the buffer pointer to the beginning of the buffer. */ - fp->__bufp = fp->__buffer; - - /* If we're not just flushing, write the last character, C. */ - if (!flush_only && !ferror (fp)) - { - if (fp->__buffer == NULL || (fp->__linebuf && (unsigned char) c == '\n')) - { - /* Either we're unbuffered, or we're line-buffered and - C is a newline, so really write it out immediately. */ - char cc = (unsigned char) c; - if ((*fp->__io_funcs.__write)(fp->__cookie, &cc, 1) < 1) - fp->__error = 1; - else if (fp->__offset != -1) - { - /* Record that we've moved forward in the file. */ - ++fp->__offset; - ++fp->__target; - } - } - else - /* Just put C in the buffer. */ - *fp->__bufp++ = (unsigned char) c; - } - - end: - - if (!twiddled) - { - if (fp->__target != -1) - /* The new target position moves up as - much as the user wrote into the buffer. */ - fp->__target += buffer_written; - - /* Set the reading limit to the beginning of the buffer, - so the next `getc' will call __fillbf. */ - fp->__get_limit = fp->__buffer; - } - - if (feof (fp) || ferror (fp)) - fp->__bufp = fp->__put_limit; -} - - -/* Fill the buffer for FP and return the first character read (or EOF). - This is the default `input_room' function. */ -static int -fillbuf (register FILE *fp) -{ - /* How far into the buffer we read we want to start bufp. */ - size_t buffer_offset = 0; - register char *buffer; - register size_t to_read, nread = 0; - /* This must be unsigned to avoid sign extension in return. */ - unsigned char c; - - if (fp->__io_funcs.__read == NULL) - { - /* There is no read function, so always return EOF. */ - fp->__eof = 1; - goto end; - } - - if (fp->__buffer == NULL) - { - /* We're unbuffered, so we want to read only one character. */ - buffer = (char *) &c; - to_read = 1; - } - else - { - /* We're buffered, so try to fill the buffer. */ - buffer = fp->__buffer; - to_read = fp->__bufsize; - } - - /* We're reading, so we're not at the end-of-file. */ - fp->__eof = 0; - - /* Go to the target file position. */ - { - int save = errno; - if (__stdio_check_offset (fp) == 0 && fp->__target != fp->__offset) - { - /* Move to a block (buffer size) boundary. */ - if (fp->__bufsize != 0) - { - buffer_offset = fp->__target % fp->__bufsize; - fp->__target -= buffer_offset; - } - seek_to_target (fp); - } - __set_errno (save); - } - - while (!ferror (fp) && !feof (fp) && nread <= buffer_offset) - { - /* Try to fill the buffer. */ - int count = (*fp->__io_funcs.__read) (fp->__cookie, buffer, to_read); - if (count == 0) - fp->__eof = 1; - else if (count < 0) - fp->__error = 1; - else - { - buffer += count; - nread += count; - to_read -= count; - if (fp->__offset != -1) - /* Record that we've moved forward in the file. */ - fp->__offset += count; - } - } - - if (fp->__buffer == NULL) - /* There is no buffer, so return the character we read - without all the buffer pointer diddling. */ - return (feof (fp) || ferror (fp)) ? EOF : c; - - /* Reset the buffer pointer to the beginning of the buffer - (plus whatever offset we may have set above). */ - fp->__bufp = fp->__buffer + buffer_offset; - - end:; - - if (feof (fp) || ferror (fp)) - { - /* Set both end pointers to the beginning of the buffer so - the next i/o call will force a call to __fillbf/__flshfp. */ - fp->__put_limit = fp->__get_limit = fp->__buffer; - return EOF; - } - - /* Set the end pointer to one past the last character we read. */ - fp->__get_limit = fp->__buffer + nread; - - /* Make it so the next `putc' will call __flshfp. */ - fp->__put_limit = fp->__buffer; - - /* Return the first character in the buffer. */ - return *((unsigned char *) (fp->__bufp++)); -} - - -/* Default I/O and room functions. */ - -extern __io_read_fn __stdio_read; -extern __io_write_fn __stdio_write; -extern __io_seek_fn __stdio_seek; -extern __io_close_fn __stdio_close; -extern __io_fileno_fn __stdio_fileno; -const __io_functions __default_io_functions = - { - __stdio_read, __stdio_write, __stdio_seek, __stdio_close, __stdio_fileno - }; - -const __room_functions __default_room_functions = - { - fillbuf, flushbuf - }; - - -/* Flush the buffer for FP and also write C if FLUSH_ONLY is nonzero. - This is the function used by putc and fflush. */ -int -__flshfp (fp, c) - register FILE *fp; - int c; -{ - int flush_only = c == EOF; - - if (!__validfp (fp) || !fp->__mode.__write) - { - __set_errno (EINVAL); - return EOF; - } - - if (ferror (fp)) - return EOF; - - if (fp->__pushed_back) - { - /* Discard the char pushed back by ungetc. */ - fp->__bufp = fp->__pushback_bufp; - fp->__pushed_back = 0; - } - - /* Make sure the stream is initialized (has functions and buffering). */ - init_stream (fp); - - /* Do this early, so a `putc' on such a stream will never return success. */ - if (fp->__room_funcs.__output == NULL) - { - /* A NULL `output room' function means - to always return an output error. */ - fp->__error = 1; - return EOF; - } - - if (!flush_only && - /* Will C fit into the buffer? - See below about linebuf_active. */ - fp->__bufp < (fp->__linebuf_active ? fp->__buffer + fp->__bufsize : - fp->__put_limit)) - { - /* The character will fit in the buffer, so put it there. */ - *fp->__bufp++ = (unsigned char) c; - if (fp->__linebuf && (unsigned char) c == '\n') - flush_only = 1; - else - return (unsigned char) c; - } - - if (fp->__linebuf_active) - /* This is an active line-buffered stream, so its put-limit is set - to the beginning of the buffer in order to force a __flshfp call - on each putc (see below). We undo this hack here (by setting - the limit to the end of the buffer) to simplify the interface - with the output-room function. */ - fp->__put_limit = fp->__buffer + fp->__bufsize; - - /* Make room in the buffer. */ - (*fp->__room_funcs.__output) (fp, flush_only ? EOF : (unsigned char) c); - - if (fp->__linebuf) - { - /* This is a line-buffered stream, and it is now ready to do - some output. We call this an "active line-buffered stream". - We set the put_limit to the beginning of the buffer, - so the next `putc' call will force a call to this function. - Setting the linebuf_active flag tells the code above - (on the next call) to undo this hackery. */ - fp->__put_limit = fp->__buffer; - fp->__linebuf_active = 1; - } - - if (ferror (fp)) - return EOF; - if (flush_only) - return 0; - return (unsigned char) c; -} - - -/* Fill the buffer for FP and return the first character read. - This is the function used by getc. */ -int -__fillbf (fp) - register FILE *fp; -{ - register int c; - fpos_t new_target; - - if (!__validfp (fp) || !fp->__mode.__read) - { - __set_errno (EINVAL); - return EOF; - } - - if (fp->__pushed_back) - { - /* Return the char pushed back by ungetc. */ - fp->__bufp = fp->__pushback_bufp; - fp->__pushed_back = 0; - return fp->__pushback; - } - - /* Make sure the stream is initialized (has functions and buffering). */ - init_stream (fp); - - /* If we're trying to read the first character of a new - line of input from an unbuffered or line buffered stream, - we must flush all line-buffered output streams. */ - if (fp->__buffer == NULL || fp->__linebuf) - { - register FILE *f; - for (f = __stdio_head; f != NULL; f = f->__next) - if (__validfp (f) && f->__linebuf && f->__mode.__write) - (void) __flshfp (f, EOF); - } - - /* Note we must do this after flushing all line-buffered - streams, or else __flshfp would undo it! */ - if (fp->__linebuf_active) - { - /* This is an active line-buffered stream, meaning it is in the midst - of writing, but has a bogus put_limit. Restore it to normality. */ - fp->__put_limit = fp->__buffer + fp->__bufsize; - fp->__linebuf_active = 0; - } - - /* We want the beginning of the buffer to now - map to just past the last data we read. */ - new_target = fp->__target + (fp->__get_limit - fp->__buffer); - - if (fp->__put_limit > fp->__buffer) - { - /* There is written data in the buffer. - Flush it out. */ - if (fp->__room_funcs.__output == NULL) - fp->__error = 1; - else - (*fp->__room_funcs.__output) (fp, EOF); - } - - fp->__target = new_target; - - if (ferror (fp)) - c = EOF; - else if (fp->__room_funcs.__input != NULL) - { - c = (*fp->__room_funcs.__input) (fp); - if (fp->__buffer == NULL) - /* This is an unbuffered stream, so the target sync above - won't do anything the next time around. Instead, note that - we have read one character. The (nonexistent) buffer now - maps to the position just past that character. */ - ++fp->__target; - } - else - { - /* A NULL `input_room' function means always return EOF. */ - fp->__eof = 1; - c = EOF; - } - - return c; -} - - -/* Nuke a stream, but don't kill its link in the chain. */ -void -__invalidate (stream) - register FILE *stream; -{ - /* Save its link. */ - register FILE *next = stream->__next; - - /* Pulverize the deceased. */ - memset((void *) stream, 0, sizeof(FILE)); - - /* Restore the deceased's link. */ - stream->__next = next; -} diff --git a/stdio/linewrap.c b/stdio/linewrap.c deleted file mode 100644 index eab8c75ff3..0000000000 --- a/stdio/linewrap.c +++ /dev/null @@ -1,521 +0,0 @@ -/* Word-wrapping and line-truncating streams. - Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stdio.h> -#include <ctype.h> -#include <string.h> -#include <stdlib.h> - -#include <linewrap.h> - -void __line_wrap_output (FILE *, int); - -/* Install our hooks into a stream. */ -static inline void -wrap_stream (FILE *stream, struct line_wrap_data *d) -{ - static __io_close_fn lwclose; - static __io_fileno_fn lwfileno; - - stream->__cookie = d; - stream->__room_funcs.__output = &__line_wrap_output; - stream->__io_funcs.__close = &lwclose; - stream->__io_funcs.__fileno = &lwfileno; - stream->__io_funcs.__seek = NULL; /* Cannot seek. */ -} - -/* Restore a stream to its original state. */ -static inline void -unwrap_stream (FILE *stream, struct line_wrap_data *d) -{ - stream->__cookie = d->cookie; - stream->__room_funcs.__output = d->output; - stream->__io_funcs.__close = d->close; - stream->__io_funcs.__fileno = d->fileno; - stream->__io_funcs.__seek = d->seek; -} - -/* If WRAPPER_COOKIE points to a 0 pointer, then STREAM is assumed to be - wrapped, and will be unwrapped, storing the wrapper cookie into - WRAPPER_COOKIE. Otherwise, nothing is done. */ -static inline void -ensure_unwrapped (FILE *stream, struct line_wrap_data **wrapper_cookie) -{ - if (*wrapper_cookie == 0) - { - *wrapper_cookie = stream->__cookie; - unwrap_stream (stream, *wrapper_cookie); - } -} - -/* If WRAPPER_COOKIE points to a non-0 pointer, then STREAM is assumed to - *have been unwrapped with ensure_unwrapped, will be wrapped with - *WRAPPER_COOKIE, and *WRAPPER_COOKIE zeroed. Otherwise, nothing is done. */ -static inline void -ensure_wrapped (FILE *stream, struct line_wrap_data **wrapper_cookie) -{ - if (*wrapper_cookie) - { - wrap_stream (stream, *wrapper_cookie); - *wrapper_cookie = 0; - } -} - -/* Cookie io functions that might get called on a wrapped stream. - Must pass the original cookie to the original functions. */ - -static int -lwclose (void *cookie) -{ - struct line_wrap_data *d = cookie; - return (*d->close) (d->cookie); -} - -static int -lwfileno (void *cookie) -{ - struct line_wrap_data *d = cookie; - return (*d->fileno) (d->cookie); -} - -/* Process STREAM's buffer so that line wrapping is done from POINT_OFFS to - the end of its buffer. If WRAPPER_COOKIE is 0, and it's necessary to - flush some data, STREAM is unwrapped, and the line wrap stdio cookie - stored in WRAPPER_COOKIE; otherwise, stream is assumed to already be - unwrapped, and WRAPPER_COOKIE to point to the line wrap data. Returns C - or EOF if C was output. */ -static inline int -lwupdate (FILE *stream, int c, struct line_wrap_data **wrapper_cookie) -{ - char *buf, *nl; - size_t len; - struct line_wrap_data *d = *wrapper_cookie ?: stream->__cookie; - - /* Scan the buffer for newlines. */ - buf = stream->__buffer + d->point_offs; - while ((buf < stream->__bufp || (c != EOF && c != '\n')) && !stream->__error) - { - size_t r; - - if (d->point_col == 0 && d->lmargin != 0) - { - /* We are starting a new line. Print spaces to the left margin. */ - const size_t pad = d->lmargin; - if (stream->__bufp + pad < stream->__put_limit) - { - /* We can fit in them in the buffer by moving the - buffer text up and filling in the beginning. */ - memmove (buf + pad, buf, stream->__bufp - buf); - stream->__bufp += pad; /* Compensate for bigger buffer. */ - memset (buf, ' ', pad); /* Fill in the spaces. */ - buf += pad; /* Don't bother searching them. */ - } - else - { - /* No buffer space for spaces. Must flush. */ - size_t i; - char *olimit; - - ensure_unwrapped (stream, wrapper_cookie); - - len = stream->__bufp - buf; - olimit = stream->__put_limit; - stream->__bufp = stream->__put_limit = buf; - for (i = 0; i < pad; ++i) - (*d->output) (stream, ' '); - stream->__put_limit = olimit; - memmove (stream->__bufp, buf, len); - stream->__bufp += len; - } - d->point_col = pad; - } - - len = stream->__bufp - buf; - nl = memchr (buf, '\n', len); - - if (d->point_col < 0) - d->point_col = 0; - - if (!nl) - { - /* The buffer ends in a partial line. */ - - if (d->point_col + len + (c != EOF && c != '\n') < d->rmargin) - { - /* The remaining buffer text is a partial line and fits - within the maximum line width. Advance point for the - characters to be written and stop scanning. */ - d->point_col += len; - break; - } - else - /* Set the end-of-line pointer for the code below to - the end of the buffer. */ - nl = stream->__bufp; - } - else if ((size_t) d->point_col + (nl - buf) < d->rmargin) - { - /* The buffer contains a full line that fits within the maximum - line width. Reset point and scan the next line. */ - d->point_col = 0; - buf = nl + 1; - continue; - } - - /* This line is too long. */ - r = d->rmargin - 1; - - if (d->wmargin < 0) - { - /* Truncate the line by overwriting the excess with the - newline and anything after it in the buffer. */ - if (nl < stream->__bufp) - { - memmove (buf + (r - d->point_col), nl, stream->__bufp - nl); - stream->__bufp -= buf + (r - d->point_col) - nl; - /* Reset point for the next line and start scanning it. */ - d->point_col = 0; - buf += r + 1; /* Skip full line plus \n. */ - } - else - { - /* The buffer ends with a partial line that is beyond the - maximum line width. Advance point for the characters - written, and discard those past the max from the buffer. */ - d->point_col += len; - stream->__bufp -= d->point_col - r; - if (c != '\n') - /* Swallow the extra character too. */ - c = EOF; - break; - } - } - else - { - /* Do word wrap. Go to the column just past the maximum line - width and scan back for the beginning of the word there. - Then insert a line break. */ - - char *p, *nextline; - int i; - - p = buf + (r + 1 - d->point_col); - while (p >= buf && !isblank (*p)) - --p; - nextline = p + 1; /* This will begin the next line. */ - - if (nextline > buf) - { - /* Swallow separating blanks. */ - do - --p; - while (isblank (*p)); - nl = p + 1; /* The newline will replace the first blank. */ - } - else - { - /* A single word that is greater than the maximum line width. - Oh well. Put it on an overlong line by itself. */ - p = buf + (r + 1 - d->point_col); - /* Find the end of the long word. */ - do - ++p; - while (p < nl && !isblank (*p)); - if (p == nl) - { - /* It already ends a line. No fussing required. */ - d->point_col = 0; - buf = nl + 1; - continue; - } - /* We will move the newline to replace the first blank. */ - nl = p; - /* Swallow separating blanks. */ - do - ++p; - while (isblank (*p)); - /* The next line will start here. */ - nextline = p; - } - - /* Temporarily reset bufp to include just the first line. */ - stream->__bufp = nl; - if (nextline - (nl + 1) < d->wmargin) - /* The margin needs more blanks than we removed. - Output the first line so we can use the space. */ - { - ensure_unwrapped (stream, wrapper_cookie); - (*d->output) (stream, '\n'); - } - else - /* We can fit the newline and blanks in before - the next word. */ - *stream->__bufp++ = '\n'; - - /* Reset the counter of what has been output this line. If wmargin - is 0, we want to avoid the lmargin getting added, so we set - point_col to a magic value of -1 in that case. */ - d->point_col = d->wmargin ? d->wmargin : -1; - - /* Add blanks up to the wrap margin column. */ - for (i = 0; i < d->wmargin; ++i) - *stream->__bufp++ = ' '; - - /* Copy the tail of the original buffer into the current buffer - position. */ - if (stream->__bufp != nextline) - memmove (stream->__bufp, nextline, buf + len - nextline); - len -= nextline - buf; - - /* Continue the scan on the remaining lines in the buffer. */ - buf = stream->__bufp; - - /* Restore bufp to include all the remaining text. */ - stream->__bufp += len; - } - } - - /* Remember that we've scanned as far as the end of the buffer. */ - d->point_offs = stream->__bufp - stream->__buffer; - - return c; -} - -/* This function is called when STREAM must be flushed. - C is EOF or a character to be appended to the buffer contents. */ -void -__line_wrap_output (FILE *stream, int c) -{ - struct line_wrap_data *d = 0; - - c = lwupdate (stream, c, &d); - - if (!stream->__error) - { - ensure_unwrapped (stream, &d); - (*d->output) (stream, c); - d->point_offs = 0; /* The buffer now holds nothing. */ - if (c == '\n') - d->point_col = 0; - else if (c != EOF) - ++d->point_col; - } - - ensure_wrapped (stream, &d); -} - -/* Modify STREAM so that it prefixes lines written on it with LMARGIN spaces - and limits them to RMARGIN columns total. If WMARGIN >= 0, words that - extend past RMARGIN are wrapped by replacing the whitespace before them - with a newline and WMARGIN spaces. Otherwise, chars beyond RMARGIN are - simply dropped until a newline. Returns STREAM after modifying it, or - NULL if there was an error. */ -FILE * -line_wrap_stream (FILE *stream, size_t lmargin, size_t rmargin, ssize_t wmargin) -{ - struct line_wrap_data *d = malloc (sizeof *d); - - if (!d) - return NULL; - - /* Ensure full setup before we start tweaking. */ - fflush (stream); - - /* Initialize our wrapping state. */ - d->point_col = 0; - d->point_offs = 0; - - /* Save the original cookie and output and close hooks. */ - d->cookie = stream->__cookie; - d->output = stream->__room_funcs.__output; - d->close = stream->__io_funcs.__close; - d->fileno = stream->__io_funcs.__fileno; - d->seek = stream->__io_funcs.__seek; - - /* Take over the stream. */ - wrap_stream (stream, d); - - /* Line-wrapping streams are normally line-buffered. This is not - required, just assumed desired. The wrapping feature should continue - to work if the stream is switched to full or no buffering. */ - stream->__linebuf = 1; - - d->lmargin = lmargin; - d->rmargin = rmargin; - d->wmargin = wmargin; - - return stream; -} - -/* Remove the hooks placed in STREAM by `line_wrap_stream'. */ -void -line_unwrap_stream (FILE *stream) -{ - struct line_wrap_data *d = stream->__cookie; - unwrap_stream (stream, d); - free (d); -} - -/* Functions on wrapped streams. */ - -/* Returns true if STREAM is line wrapped. */ -inline int -line_wrapped (FILE *stream) -{ - return (stream->__room_funcs.__output == &__line_wrap_output); -} - -/* If STREAM is not line-wrapped, return 0. Otherwise all pending text - buffered text in STREAM so that the POINT_OFFS field refers to the last - position in the stdio buffer, and return the line wrap state object for - STREAM. Since all text has been processed, this means that (1) the - POINT_COL field refers to the column at which any new text would be added, - and (2) any changes to the margin parameters will only affect new text. */ -struct line_wrap_data * -__line_wrap_update (FILE *stream) -{ - if (line_wrapped (stream)) - { - struct line_wrap_data *d = stream->__cookie, *wc = 0; - - if (stream->__linebuf_active) - /* This is an active line-buffered stream, so its put-limit is set to - the beginning of the buffer in order to force a __flshfp call on - each putc (see below). We undo this hack here (by setting the - limit to the end of the buffer) to simplify the interface with the - output-room function. */ - stream->__put_limit = stream->__buffer + stream->__bufsize; - - lwupdate (stream, EOF, &wc); - - if (stream->__linebuf) - { - /* This is a line-buffered stream, and it is now ready to do some - output. We call this an "active line-buffered stream". We set - the put_limit to the beginning of the buffer, so the next `putc' - call will force a call to flshfp. Setting the linebuf_active - flag tells the code above (on the next call) to undo this - hackery. */ - stream->__put_limit = stream->__buffer; - stream->__linebuf_active = 1; - } - - ensure_wrapped (stream, &wc); - - return d; - } - else - return 0; -} - -/* If STREAM is not line-wrapped return -1, else return its left margin. */ -inline size_t -line_wrap_lmargin (FILE *stream) -{ - if (! line_wrapped (stream)) - return -1; - return ((struct line_wrap_data *)stream->__cookie)->lmargin; -} - -/* If STREAM is not line-wrapped return -1, else set its left margin to - LMARGIN and return the old value. */ -inline size_t -line_wrap_set_lmargin (FILE *stream, size_t lmargin) -{ - struct line_wrap_data *d = __line_wrap_update (stream); - if (d) - { - size_t old = d->lmargin; - d->lmargin = lmargin; - return old; - } - else - return -1; -} - -/* If STREAM is not line-wrapped return -1, else return its left margin. */ -inline size_t -line_wrap_rmargin (FILE *stream) -{ - if (! line_wrapped (stream)) - return -1; - return ((struct line_wrap_data *)stream->__cookie)->rmargin; -} - -/* If STREAM is not line-wrapped return -1, else set its right margin to - RMARGIN and return the old value. */ -inline size_t -line_wrap_set_rmargin (FILE *stream, size_t rmargin) -{ - struct line_wrap_data *d = __line_wrap_update (stream); - if (d) - { - size_t old = d->rmargin; - d->rmargin = rmargin; - return old; - } - else - return -1; -} - -/* If STREAM is not line-wrapped return -1, else return its wrap margin. */ -inline size_t -line_wrap_wmargin (FILE *stream) -{ - if (! line_wrapped (stream)) - return -1; - return ((struct line_wrap_data *)stream->__cookie)->wmargin; -} - -/* If STREAM is not line-wrapped return -1, else set its left margin to - WMARGIN and return the old value. */ -inline size_t -line_wrap_set_wmargin (FILE *stream, size_t wmargin) -{ - struct line_wrap_data *d = __line_wrap_update (stream); - if (d) - { - size_t old = d->wmargin; - d->wmargin = wmargin; - return old; - } - else - return -1; -} - -/* If STREAM is not line-wrapped return -1, else return the column number of - the current output point. */ -inline size_t -line_wrap_point (FILE *stream) -{ - struct line_wrap_data *d = __line_wrap_update (stream); - return d ? (d->point_col >= 0 ? d->point_col : 0) : -1; -} - -#ifdef TEST -int -main (int argc, char **argv) -{ - int c; - puts ("stopme"); - line_wrap_stream (stdout, atoi (argv[1]), atoi (argv[2] ?: "-1")); - while ((c = getchar()) != EOF) putchar (c); - return 0; -} -#endif diff --git a/stdio/linewrap.h b/stdio/linewrap.h deleted file mode 100644 index 5aad9f62e2..0000000000 --- a/stdio/linewrap.h +++ /dev/null @@ -1,200 +0,0 @@ -/* Word-wrapping and line-truncating streams. - Copyright (C) 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#ifndef __LINEWRAP_H__ -#define __LINEWRAP_H__ - -#include <stdio.h> -#include <ctype.h> -#include <string.h> - -#include <features.h> - -#include <string.h> /* Need size_t. */ - -__BEGIN_DECLS - -/* We keep this data for each line-wrapping stream. */ -struct line_wrap_data - { - size_t lmargin, rmargin; /* Left and right margins. */ - ssize_t wmargin; /* Margin to wrap to, or -1 to truncate. */ - - /* Point in stdio buffer to which we've processed for wrapping, but - not output. */ - size_t point_offs; - /* Output column at POINT_OFFS, or -1 meaning 0 but don't add lmargin. */ - ssize_t point_col; - - /* Original cookie and hooks from the stream. */ - void *cookie; - void (*output) (FILE *, int); - __io_close_fn *close; - __io_fileno_fn *fileno; - __io_seek_fn *seek; - }; - -/* Modify STREAM so that it prefixes lines written on it with LMARGIN spaces - and limits them to RMARGIN columns total. If WMARGIN >= 0, words that - extend past RMARGIN are wrapped by replacing the whitespace before them - with a newline and WMARGIN spaces. Otherwise, chars beyond RMARGIN are - simply dropped until a newline. Returns STREAM after modifying it, or - NULL if there was an error. */ -FILE *line_wrap_stream (FILE *stream, - size_t lmargin, size_t rmargin, ssize_t wmargin); - -/* Remove the hooks placed in STREAM by `line_wrap_stream'. */ -void line_unwrap_stream (FILE *stream); - -/* Returns true if STREAM is line wrapped. */ -extern inline int line_wrapped (FILE *stream); - -/* If STREAM is not line-wrapped return -1, else return its left margin. */ -extern size_t line_wrap_lmargin (FILE *stream); - -/* If STREAM is not line-wrapped return -1, else set its left margin to - LMARGIN and return the old value. */ -extern size_t line_wrap_set_lmargin (FILE *stream, size_t lmargin); - -/* If STREAM is not line-wrapped return -1, else return its left margin. */ -extern size_t line_wrap_rmargin (FILE *stream); - -/* If STREAM is not line-wrapped return -1, else set its right margin to - RMARGIN and return the old value. */ -extern size_t line_wrap_set_rmargin (FILE *stream, size_t rmargin); - -/* If STREAM is not line-wrapped return -1, else return its wrap margin. */ -extern size_t line_wrap_wmargin (FILE *stream); - -/* If STREAM is not line-wrapped return -1, else set its left margin to - WMARGIN and return the old value. */ -extern size_t line_wrap_set_wmargin (FILE *stream, size_t wmargin); - -/* If STREAM is not line-wrapped return -1, else return the column number of - the current output point. */ -extern size_t line_wrap_point (FILE *stream); - -#ifdef __OPTIMIZE__ - -extern void __line_wrap_output (FILE *, int); /* private */ - -/* If STREAM is not line-wrapped, return 0. Otherwise all pending text - buffered text in STREAM so that the POINT_OFFS field refers to the last - position in the stdio buffer, and return the line wrap state object for - STREAM. Since all text has been processed, this means that (1) the - POINT_COL field refers to the column at which any new text would be added, - and (2) any changes to the margin parameters will only affect new text. */ -extern struct line_wrap_data *__line_wrap_update (FILE *stream); /* private */ - -/* Returns true if STREAM is line wrapped. */ -extern inline int -line_wrapped (FILE *stream) -{ - return (stream->__room_funcs.__output == &__line_wrap_output); -} - -/* If STREAM is not line-wrapped return -1, else return its left margin. */ -extern inline size_t -line_wrap_lmargin (FILE *stream) -{ - if (! line_wrapped (stream)) - return -1; - return ((struct line_wrap_data *)stream->__cookie)->lmargin; -} - -/* If STREAM is not line-wrapped return -1, else set its left margin to - LMARGIN and return the old value. */ -extern inline size_t -line_wrap_set_lmargin (FILE *stream, size_t lmargin) -{ - struct line_wrap_data *d = __line_wrap_update (stream); - if (d) - { - size_t old = d->lmargin; - d->lmargin = lmargin; - return old; - } - else - return -1; -} - -/* If STREAM is not line-wrapped return -1, else return its left margin. */ -extern inline size_t -line_wrap_rmargin (FILE *stream) -{ - if (! line_wrapped (stream)) - return -1; - return ((struct line_wrap_data *)stream->__cookie)->rmargin; -} - -/* If STREAM is not line-wrapped return -1, else set its right margin to - RMARGIN and return the old value. */ -extern inline size_t -line_wrap_set_rmargin (FILE *stream, size_t rmargin) -{ - struct line_wrap_data *d = __line_wrap_update (stream); - if (d) - { - size_t old = d->rmargin; - d->rmargin = rmargin; - return old; - } - else - return -1; -} - -/* If STREAM is not line-wrapped return -1, else return its wrap margin. */ -extern inline size_t -line_wrap_wmargin (FILE *stream) -{ - if (! line_wrapped (stream)) - return -1; - return ((struct line_wrap_data *)stream->__cookie)->wmargin; -} - -/* If STREAM is not line-wrapped return -1, else set its left margin to - WMARGIN and return the old value. */ -extern inline size_t -line_wrap_set_wmargin (FILE *stream, size_t wmargin) -{ - struct line_wrap_data *d = __line_wrap_update (stream); - if (d) - { - size_t old = d->wmargin; - d->wmargin = wmargin; - return old; - } - else - return -1; -} - -/* If STREAM is not line-wrapped return -1, else return the column number of - the current output point. */ -extern inline size_t -line_wrap_point (FILE *stream) -{ - struct line_wrap_data *d = __line_wrap_update (stream); - return d ? (d->point_col >= 0 ? d->point_col : 0) : -1; -} - -#endif /* Optimizing. */ - -__END_DECLS - -#endif /* __LINEWRAP_H__ */ diff --git a/stdio/memstream.c b/stdio/memstream.c deleted file mode 100644 index b400bb7d27..0000000000 --- a/stdio/memstream.c +++ /dev/null @@ -1,176 +0,0 @@ -/* Copyright (C) 1991, 92, 94, 95, 96, 97 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> - -struct memstream_info - { - char **buffer; - size_t *bufsize; - }; - -/* Enlarge STREAM's buffer. */ -static void -enlarge_buffer (register FILE *stream, int c) -{ - struct memstream_info *info = (struct memstream_info *) stream->__cookie; - size_t need; - - if (stream->__put_limit != stream->__buffer) - /* Record how much has actually been written into the buffer. */ - *info->bufsize = stream->__bufp - stream->__buffer; - - if (stream->__target != -1 - && (size_t) stream->__target > *info->bufsize) - /* Our target (where the buffer maps to) is always zero except when - the user just did a SEEK_END fseek. If he sought within the - buffer, we need do nothing and will zero the target below. If he - sought past the end of the object, grow and zero-fill the buffer - up to the target address. */ - need = stream->__target; - else - need = *info->bufsize; - - /* We always need an extra character in the buffer. Either we are - writing C, or we are flushing and need to write a NUL terminator. */ - ++need; - - if (stream->__bufsize < need) - { - /* Enlarge the buffer. */ - char *newbuf; - size_t newsize; - if (stream->__bufsize * 2 < need) - newsize = need; - else - newsize = stream->__bufsize * 2; - newbuf = (char *) realloc ((void *) stream->__buffer, newsize); - if (newbuf == NULL) - { - stream->__error = 1; - return; - } - *info->buffer = stream->__buffer = newbuf; - stream->__bufsize = newsize; - } - - stream->__target = stream->__offset = 0; - stream->__get_limit = stream->__bufp = stream->__buffer + *info->bufsize; - stream->__put_limit = stream->__buffer + stream->__bufsize; - - need -= stream->__bufp - stream->__buffer + 1; - if (need > 0) - { - /* We are extending the buffer after an fseek; zero-fill new space. */ - memset (stream->__bufp, '\0', need); - stream->__bufp += need; - } - - if (c != EOF) - *stream->__bufp++ = (unsigned char) c; - else - *stream->__bufp = '\0'; -} - -/* Seek function for memstreams. - There is no external state to munge. */ - -static int -seek (void *cookie, fpos_t *pos, int whence) -{ - switch (whence) - { - case SEEK_SET: - case SEEK_CUR: - return 0; - - case SEEK_END: - /* Return the position relative to the end of the object. - fseek has just flushed us, so the info is consistent. */ - *pos += *((struct memstream_info *) cookie)->bufsize; - return 0; - - default: - __libc_fatal ("memstream::seek called with bogus WHENCE\n"); - return -1; - } -} - -static int -free_info (void *cookie) -{ -#if 0 - struct memstream_info *info = (struct memstream_info *) cookie; - char *buf; - - buf = (char *) realloc ((PTR) *info->buffer, *info->bufsize); - if (buf != NULL) - *info->buffer = buf; -#endif - - free (cookie); - - return 0; -} - -/* Open a stream that writes into a malloc'd buffer that is expanded as - necessary. *BUFLOC and *SIZELOC are updated with the buffer's location - and the number of characters written on fflush or fclose. */ -FILE * -open_memstream (bufloc, sizeloc) - char **bufloc; - size_t *sizeloc; -{ - FILE *stream; - struct memstream_info *info; - - if (bufloc == NULL || sizeloc == NULL) - { - __set_errno (EINVAL); - return NULL; - } - - stream = fmemopen ((char *) NULL, BUFSIZ, "w+"); - if (stream == NULL) - return NULL; - - info = (struct memstream_info *) malloc (sizeof (struct memstream_info)); - if (info == NULL) - { - int save = errno; - (void) fclose (stream); - __set_errno (save); - return NULL; - } - - stream->__room_funcs.__output = enlarge_buffer; - stream->__io_funcs.__seek = seek; - stream->__io_funcs.__close = free_info; - stream->__cookie = (void *) info; - stream->__userbuf = 1; - - info->buffer = bufloc; - info->bufsize = sizeloc; - - *bufloc = stream->__buffer; - - return stream; -} diff --git a/stdio/newstream.c b/stdio/newstream.c deleted file mode 100644 index 850baf7b35..0000000000 --- a/stdio/newstream.c +++ /dev/null @@ -1,53 +0,0 @@ -/* Copyright (C) 1991, 1992, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stddef.h> -#include <stdio.h> -#include <stdlib.h> - - -/* Return a new, zeroed, stream. - You must set its cookie and io_mode. - The first operation will give it a buffer unless you do. - It will also give it the default functions unless you set the `seen' flag. - Returns NULL if a stream can't be created. */ -FILE * -__newstream (void) -{ - register FILE *stream; - - stream = __stdio_head; - while (__validfp (stream)) - stream = stream->__next; - if (stream == NULL) - { - /* None to reuse. */ - stream = (FILE *) malloc (sizeof (FILE)); - if (stream == NULL) - return NULL; - stream->__next = __stdio_head; - __stdio_head = stream; - } - - __invalidate (stream); - stream->__magic = _IOMAGIC; - stream->__offset = (fpos_t) -1; - stream->__target = (fpos_t) -1; - - return stream; -} diff --git a/stdio/obstream.c b/stdio/obstream.c deleted file mode 100644 index 06118f5416..0000000000 --- a/stdio/obstream.c +++ /dev/null @@ -1,185 +0,0 @@ -/* Copyright (C) 1992, 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stdio.h> -#include <obstack.h> -#include <stdarg.h> -#include <string.h> - -/* Output-room function for obstack streams. */ - -static void -grow (FILE *stream, int c) -{ - struct obstack *const obstack = (struct obstack *) stream->__cookie; - - /* Move the end of the object back to include only the portion - of the buffer which the user has already written into. */ - obstack_blank_fast (obstack, - (stream->__put_limit - stream->__bufp)); - - if ((size_t) stream->__target > obstack_object_size (obstack)) - { - /* Our target (where the buffer maps to) is always zero except when - the user just did a SEEK_END fseek. If he sought within the - buffer, we need do nothing and will zero the target below. If he - sought past the end of the object, grow and zero-fill the object - up to the target address. */ - - obstack_blank (obstack, - stream->__target - obstack_object_size (obstack)); - /* fseek has just flushed us, so the put limit points - to the end of the written data. */ - bzero (stream->__put_limit, - stream->__target - stream->__bufsize); - } - - if (c != EOF) - obstack_1grow (obstack, (unsigned char) c); - - /* The stream buffer always maps exactly to the object on the top - of the obstack. The start of the buffer is the start of the object. - The put limit points just past the end of the object. On fflush, the - obstack is sync'd so the end of the object points just past the last - character written to the stream. */ - - stream->__target = stream->__offset = 0; - stream->__buffer = obstack_base (obstack); - stream->__bufsize = obstack_room (obstack); - stream->__bufp = obstack_next_free (obstack); - stream->__get_limit = stream->__bufp; - - if (c == EOF) - /* This is fflush. Make the stream buffer, the object, - and the characters actually written all match. */ - stream->__put_limit = stream->__get_limit; - else - { - /* Extend the buffer (and the object) to include - the rest of the obstack chunk (which is uninitialized). - Data past bufp is undefined. */ - stream->__put_limit = stream->__buffer + stream->__bufsize; - obstack_blank_fast (obstack, stream->__put_limit - stream->__bufp); - } -} - -/* Seek function for obstack streams. - There is no external state to munge. */ - -static int -seek (void *cookie, fpos_t *pos, int whence) -{ - switch (whence) - { - case SEEK_SET: - case SEEK_CUR: - return 0; - - case SEEK_END: - /* Return the position relative to the end of the object. - fseek has just flushed us, so the obstack is consistent. */ - *pos += obstack_object_size ((struct obstack *) cookie); - return 0; - - default: - __libc_fatal ("obstream::seek called with bogus WHENCE\n"); - return -1; - } -} - -/* Input room function for obstack streams. - Only what has been written to the stream can be read back. */ - -static int -input (FILE *stream) -{ - /* Re-sync with the obstack, growing the object if necessary. */ - grow (stream, EOF); - - if (stream->__bufp < stream->__get_limit) - return (unsigned char) *stream->__bufp++; - - stream->__eof = 1; - return EOF; -} - -/* Initialize STREAM to talk to OBSTACK. */ - -static void -init_obstream (FILE *stream, struct obstack *obstack) -{ - stream->__mode.__write = 1; - stream->__mode.__read = 1; - - /* Input can read only what has been written. */ - stream->__room_funcs.__input = input; - - /* Do nothing for close. */ - stream->__io_funcs.__close = NULL; - - /* When the buffer is full, grow the obstack. */ - stream->__room_funcs.__output = grow; - - /* Seek within the object, and extend it. */ - stream->__io_funcs.__seek = seek; - stream->__target = stream->__offset = 0; - - stream->__seen = 1; - - /* Don't deallocate that buffer! */ - stream->__userbuf = 1; - - /* We don't have to initialize the buffer. - The first read attempt will call grow, which will do all the work. */ -} - -FILE * -open_obstack_stream (obstack) - struct obstack *obstack; -{ - register FILE *stream; - - stream = __newstream (); - if (stream == NULL) - return NULL; - - init_obstream (stream, obstack); - return stream; -} - -int -obstack_vprintf (obstack, format, args) - struct obstack *obstack; - const char *format; - va_list args; -{ - FILE f; - bzero (&f, sizeof (f)); - init_obstream (&f, obstack); - return vfprintf (&f, format, args); -} - -int -obstack_printf (struct obstack *obstack, const char *format, ...) -{ - int result; - va_list ap; - va_start (ap, format); - result = obstack_vprintf (obstack, format, ap); - va_end (ap); - return result; -} diff --git a/stdio/putc.c b/stdio/putc.c deleted file mode 100644 index f35f9775bf..0000000000 --- a/stdio/putc.c +++ /dev/null @@ -1,6 +0,0 @@ -#include <stdio.h> -#undef putc -#define fputc putc -#define fputc_unlocked putc_unlocked -#include <fputc.c> -weak_alias (putc, putc_unlocked) diff --git a/stdio/putchar.c b/stdio/putchar.c deleted file mode 100644 index d946d74c4c..0000000000 --- a/stdio/putchar.c +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright (C) 1991, 1997, 1998 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stdio.h> - -#undef putchar - - -/* Write the character C on stdout. */ -int -putchar (int c) -{ - return __putc (c, stdout); -} - -weak_alias (putchar, putchar_unlocked) diff --git a/stdio/puts.c b/stdio/puts.c deleted file mode 100644 index 5dc2840475..0000000000 --- a/stdio/puts.c +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright (C) 1991, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stddef.h> -#include <stdio.h> -#include <string.h> - -#undef puts - - -/* Write the string in S and a newline to stdout. */ -int -puts (const char *s) -{ - return fputs (s, stdout) || putchar ('\n') == EOF ? EOF : 0; -} diff --git a/stdio/rewind.c b/stdio/rewind.c deleted file mode 100644 index 54f8609597..0000000000 --- a/stdio/rewind.c +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright (C) 1991, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stdio.h> - -#undef rewind - - -/* Rewind STREAM to the beginning of the - file and clear its error and EOF flags. */ -void -rewind (FILE *stream) -{ - clearerr (stream); - (void) fseek (stream, 0L, SEEK_SET); - clearerr (stream); -} diff --git a/stdio/setbuf.c b/stdio/setbuf.c deleted file mode 100644 index 50ff7df4d6..0000000000 --- a/stdio/setbuf.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (C) 1991, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stddef.h> -#include <stdio.h> - - -/* If BUF is NULL, make STREAM unbuffered. - If not, make BUF, which is BUFSIZ bytes long, be its buffer. */ -void -setbuf (FILE *stream, char *buf) -{ - (void) setvbuf (stream, buf, buf != NULL ? _IOFBF : _IONBF, BUFSIZ); -} diff --git a/stdio/setbuffer.c b/stdio/setbuffer.c deleted file mode 100644 index 73fa38085e..0000000000 --- a/stdio/setbuffer.c +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (C) 1991, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stddef.h> -#include <stdio.h> - - -/* If BUF is NULL, make stream unbuffered. - If not, make BUF, which is N bytes long, be its buffer. */ -void -setbuffer (FILE *stream, char *buf, size_t n) -{ - (void) setvbuf (stream, buf, buf != NULL ? _IOFBF : _IONBF, n); -} diff --git a/stdio/setlinebuf.c b/stdio/setlinebuf.c deleted file mode 100644 index 03a80b6afa..0000000000 --- a/stdio/setlinebuf.c +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright (C) 1991, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stdio.h> - - -/* Make STREAM line buffered. */ -void -setlinebuf (FILE *stream) -{ - if (stream->__buffer != NULL || !stream->__userbuf) - stream->__linebuf = 1; -} diff --git a/stdio/setvbuf.c b/stdio/setvbuf.c deleted file mode 100644 index bfa32b53cf..0000000000 --- a/stdio/setvbuf.c +++ /dev/null @@ -1,88 +0,0 @@ -/* Copyright (C) 1991, 1993, 1995, 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stddef.h> -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> - - -/* Make STREAM use the buffering method given in MODE. - If MODE indicates full or line buffering, use BUF, - a buffer of SIZE bytes; if BUF is NULL, malloc a buffer. */ -int -setvbuf (stream, buf, mode, size) - FILE *stream; - char *buf; - int mode; - size_t size; -{ - if (!__validfp (stream)) - { - __set_errno (EINVAL); - return EOF; - } - - /* The ANSI standard says setvbuf can only be called before any I/O is done, - but we allow it to replace an old buffer, flushing it first. */ - if (stream->__buffer != NULL) - { - (void) fflush (stream); - /* Free the old buffer if it was malloc'd. */ - if (!stream->__userbuf) - free(stream->__buffer); - } - - stream->__get_limit = stream->__put_limit = NULL; - stream->__bufp = stream->__buffer = NULL; - stream->__userbuf = stream->__linebuf = stream->__linebuf_active = 0; - - switch (mode) - { - default: - __set_errno (EINVAL); - return EOF; - case _IONBF: /* Unbuffered. */ - stream->__buffer = NULL; - stream->__bufsize = 0; - stream->__userbuf = 1; - break; - case _IOLBF: /* Line buffered. */ - stream->__linebuf = 1; - case _IOFBF: /* Fully buffered. */ - if (size == 0) - { - __set_errno (EINVAL); - return EOF; - } - stream->__bufsize = size; - if (buf != NULL) - stream->__userbuf = 1; - else if ((buf = (char *) malloc (size)) == NULL) - return EOF; - stream->__buffer = buf; - break; - } - - stream->__bufp = stream->__buffer; - stream->__get_limit = stream->__buffer; - /* The next output operation will prime the stream for writing. */ - stream->__put_limit = stream->__buffer; - - return 0; -} diff --git a/stdio/stdio.h b/stdio/stdio.h deleted file mode 100644 index 3e0a79e093..0000000000 --- a/stdio/stdio.h +++ /dev/null @@ -1,832 +0,0 @@ -/* Copyright (C) 1991-1999, 2000 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* - * ISO C99 Standard: 7.19 Input/output <stdio.h> - */ - -#ifndef _STDIO_H - -#if !defined(__need_FILE) && !defined(__need___FILE) -#define _STDIO_H 1 -#include <features.h> - -__BEGIN_DECLS - -#define __need_size_t -#define __need_NULL -#include <stddef.h> - -#define __need___va_list -#include <stdarg.h> -#ifndef __GNUC_VA_LIST -#define __gnuc_va_list __ptr_t -#endif - -#include <bits/types.h> -#define __need_FILE -#define __need___FILE -#endif /* Don't need FILE. */ - - -#if !defined __FILE_defined && defined __need_FILE - -/* The opaque type of streams. */ -typedef struct __stdio_file FILE; - -#define __FILE_defined 1 -#endif /* FILE not defined. */ -#undef __need_FILE - - -#if !defined ____FILE_defined && defined __need___FILE - -/* The opaque type of streams. */ -typedef struct __stdio_file __FILE; - -#define ____FILE_defined 1 -#endif /* __FILE not defined. */ -#undef __need___FILE - - -#ifdef _STDIO_H - -/* The type of the second argument to `fgetpos' and `fsetpos'. */ -typedef __off_t fpos_t; - -/* The mode of I/O, as given in the MODE argument to fopen, etc. */ -typedef struct -{ - unsigned int __read:1; /* Open for reading. */ - unsigned int __write:1; /* Open for writing. */ - unsigned int __append:1; /* Open for appending. */ - unsigned int __binary:1; /* Opened binary. */ - unsigned int __create:1; /* Create the file. */ - unsigned int __exclusive:1; /* Error if it already exists. */ - unsigned int __truncate:1; /* Truncate the file on opening. */ -} __io_mode; - - -/* Functions to do I/O and file management for a stream. */ - -/* Read NBYTES bytes from COOKIE into a buffer pointed to by BUF. - Return number of bytes read. */ -typedef __ssize_t __io_read_fn (__ptr_t __cookie, char *__buf, - size_t __nbytes); - -/* Write N bytes pointed to by BUF to COOKIE. Write all N bytes - unless there is an error. Return number of bytes written, or -1 if - there is an error without writing anything. If the file has been - opened for append (__mode.__append set), then set the file pointer - to the end of the file and then do the write; if not, just write at - the current file pointer. */ -typedef __ssize_t __io_write_fn (__ptr_t __cookie, __const char *__buf, - size_t __n); - -/* Move COOKIE's file position to *POS bytes from the - beginning of the file (if W is SEEK_SET), - the current position (if W is SEEK_CUR), - or the end of the file (if W is SEEK_END). - Set *POS to the new file position. - Returns zero if successful, nonzero if not. */ -typedef int __io_seek_fn (__ptr_t __cookie, fpos_t *__pos, int __w); - -/* Close COOKIE. */ -typedef int __io_close_fn (__ptr_t __cookie); - -/* Return the file descriptor associated with COOKIE, - or -1 on error. There need not be any associated file descriptor. */ -typedef int __io_fileno_fn (__ptr_t __cookie); - -#ifdef __USE_GNU -/* User-visible names for the above. */ -typedef __io_read_fn cookie_read_function_t; -typedef __io_write_fn cookie_write_function_t; -typedef __io_seek_fn cookie_seek_function_t; -typedef __io_close_fn cookie_close_function_t; -typedef __io_fileno_fn cookie_fileno_function_t; -#endif - -/* Low level interface, independent of FILE representation. */ -#if defined __USE_GNU && !defined _LIBC -/* Define the user-visible type, with user-friendly member names. */ -typedef struct -{ - __io_read_fn *read; /* Read bytes. */ - __io_write_fn *write; /* Write bytes. */ - __io_seek_fn *seek; /* Seek/tell file position. */ - __io_close_fn *close; /* Close file. */ - __io_fileno_fn *fileno; /* Return file descriptor. */ -} cookie_io_functions_t; -/* This name is still used in the prototypes in this file. */ -typedef cookie_io_functions_t __io_functions; -#else -/* Stick to ANSI-safe names. */ -typedef struct -{ - __io_read_fn *__read; /* Read bytes. */ - __io_write_fn *__write; /* Write bytes. */ - __io_seek_fn *__seek; /* Seek/tell file position. */ - __io_close_fn *__close; /* Close file. */ - __io_fileno_fn *__fileno; /* Return file descriptor. */ -} __io_functions; -#endif - -/* Higher level interface, dependent on FILE representation. */ -typedef struct -{ - /* Make room in the input buffer. */ - int (*__input) (FILE *__stream); - /* Make room in the output buffer. */ - void (*__output) (FILE *__stream, int __c); -} __room_functions; - -extern __const __io_functions __default_io_functions; -extern __const __room_functions __default_room_functions; - - -/* Default close function. */ -extern __io_close_fn __stdio_close; -/* Open FILE with mode M, store cookie in *COOKIEPTR. */ -extern int __stdio_open (__const char *__file, __io_mode __m, - void **__cookieptr) __THROW; -/* Put out an error message for when stdio needs to die. */ -extern void __stdio_errmsg (__const char *__msg, size_t __len) __THROW; - - - -/* For thread safe I/O functions we need a lock in each stream. We - keep the type opaque here. */ -struct __stdio_lock; - -/* The FILE structure. */ -struct __stdio_file -{ - /* Magic number for validation. Must be negative in open streams - for the glue to Unix stdio getc/putc to work. - NOTE: stdio/glue.c has special knowledge of these first four members. */ - int __magic; -#define _IOMAGIC ((int) 0xfedabeeb) /* Magic number to fill `__magic'. */ -#define _GLUEMAGIC ((int) 0xfeedbabe) /* Magic for glued Unix streams. */ - - char *__bufp; /* Pointer into the buffer. */ - char *__get_limit; /* Reading limit. */ - char *__put_limit; /* Writing limit. */ - - char *__buffer; /* Base of buffer. */ - size_t __bufsize; /* Size of the buffer. */ - __ptr_t __cookie; /* Magic cookie. */ - __io_mode __mode; /* File access mode. */ - __io_functions __io_funcs; /* I/O functions. */ - __room_functions __room_funcs;/* I/O buffer room functions. */ - fpos_t __offset; /* Current file position. */ - fpos_t __target; /* Target file position. */ - FILE *__next; /* Next FILE in the linked list. */ - char *__pushback_bufp; /* Old bufp if char pushed back. */ - unsigned char __pushback; /* Pushed-back character. */ - unsigned int __pushed_back:1; /* A char has been pushed back. */ - unsigned int __eof:1; /* End of file encountered. */ - unsigned int __error:1; /* Error encountered. */ - unsigned int __userbuf:1; /* Buffer from user (should not be freed). */ - unsigned int __linebuf:1; /* Flush on newline. */ - unsigned int __linebuf_active:1; /* put_limit is not really in use. */ - unsigned int __seen:1; /* This stream has been seen. */ - unsigned int __ispipe:1; /* Nonzero if opened by popen. */ - struct __stdio_lock *__lock; /* Pointer to associated lock. */ -}; - - -/* All macros used internally by other macros here and by stdio functions begin - with `__'. All of these may evaluate their arguments more than once. */ - - -/* Nonzero if STREAM is a valid stream. - STREAM must be a modifiable lvalue (wow, I got to use that term). - See stdio/glue.c for what the confusing bit is about. */ -#define __validfp(stream) \ - (stream != NULL && \ - ({ if (stream->__magic == _GLUEMAGIC) \ - stream = *((struct { int __magic; FILE **__p; } *) stream)->__p; \ - stream->__magic == _IOMAGIC; })) - -/* Clear the error and EOF indicators of STREAM. */ -#define __clearerr(stream) ((stream)->__error = (stream)->__eof = 0) - -/* Nuke STREAM, making it unusable but available for reuse. */ -extern void __invalidate (FILE *__stream) __THROW; - -/* Make sure STREAM->__offset and STREAM->__target are initialized. - Returns 0 if successful, or EOF on - error (but doesn't set STREAM->__error). */ -extern int __stdio_check_offset (FILE *__stream) __THROW; - - -/* The possibilities for the third argument to `setvbuf'. */ -#define _IOFBF 0x1 /* Full buffering. */ -#define _IOLBF 0x2 /* Line buffering. */ -#define _IONBF 0x4 /* No buffering. */ - - -/* Default buffer size. */ -#define BUFSIZ 1024 - - -/* End of file character. - Some things throughout the library rely on this being -1. */ -#define EOF (-1) - - -/* The possibilities for the third argument to `fseek'. - These values should not be changed. */ -#define SEEK_SET 0 /* Seek from beginning of file. */ -#define SEEK_CUR 1 /* Seek from current position. */ -#define SEEK_END 2 /* Seek from end of file. */ - - -#ifdef __USE_SVID -/* Default path prefix for `tempnam' and `tmpnam'. */ -#define P_tmpdir "/usr/tmp" -#endif - - -/* Get the values: - L_tmpnam How long an array of chars must be to be passed to `tmpnam'. - TMP_MAX The minimum number of unique filenames generated by tmpnam - (and tempnam when it uses tmpnam's name space), - or tempnam (the two are separate). - L_ctermid How long an array to pass to `ctermid'. - L_cuserid How long an array to pass to `cuserid'. - FOPEN_MAX Minimum number of files that can be open at once. - FILENAME_MAX Maximum length of a filename. */ -#include <bits/stdio_lim.h> - - -/* All the known streams are in a linked list - linked by the `next' field of the FILE structure. */ -extern FILE *__stdio_head; /* Head of the list. */ - -/* Standard streams. */ -extern FILE *stdin, *stdout, *stderr; -#ifdef __STRICT_ANSI__ -/* ANSI says these are macros; satisfy pedants. */ -#define stdin stdin -#define stdout stdout -#define stderr stderr -#endif - - -/* Remove file FILENAME. */ -extern int remove (__const char *__filename) __THROW; -/* Rename file OLD to NEW. */ -extern int rename (__const char *__old, __const char *__new) __THROW; - - -/* Create a temporary file and open it read/write. */ -extern FILE *tmpfile (void) __THROW; -#ifdef __USE_LARGEFILE64 -extern FILE *tmpfile64 (void) __THROW; -#endif -/* Generate a temporary filename. */ -extern char *tmpnam (char *__s) __THROW; - -#ifdef __USE_REENTRANT -/* This is the reentrant variant of `tmpnam'. The only difference is - that it does not allow S to be NULL. */ -extern char *tmpnam_r (char *__s) __THROW; -#endif - - -#if defined __USE_SVID || defined __USE_XOPEN -/* Generate a unique temporary filename using up to five characters of PFX - if it is not NULL. The directory to put this file in is searched for - as follows: First the environment variable "TMPDIR" is checked. - If it contains the name of a writable directory, that directory is used. - If not and if DIR is not NULL, that value is checked. If that fails, - P_tmpdir is tried and finally "/tmp". The storage for the filename - is allocated by `malloc'. */ -extern char *tempnam (__const char *__dir, __const char *__pfx) __THROW; -#endif - - -/* This performs actual output when necessary, flushing - STREAM's buffer and optionally writing another character. */ -extern int __flshfp (FILE *__stream, int __c) __THROW; - - -/* Close STREAM. */ -extern int fclose (FILE *__stream) __THROW; -/* Flush STREAM, or all streams if STREAM is NULL. */ -extern int fflush (FILE *__stream) __THROW; - -#ifdef __USE_MISC -/* Faster versions when locking is not required. */ -extern int fflush_unlocked (FILE *__stream) __THROW; -#endif - -#ifdef __USE_GNU -/* Close all streams. */ -extern int __fcloseall (void) __THROW; -extern int fcloseall (void) __THROW; -#endif - - -/* Open a file and create a new stream for it. */ -extern FILE *fopen (__const char *__filename, __const char *__modes) __THROW; -/* Open a file, replacing an existing stream with it. */ -extern FILE *freopen (__const char *__restrict __filename, - __const char *__restrict __modes, - FILE *__restrict __stream) __THROW; - -/* Return a new, zeroed, stream. - You must set its cookie and io_mode. - The first operation will give it a buffer unless you do. - It will also give it the default functions unless you set the `seen' flag. - The offset is set to -1, meaning it will be determined by doing a - stationary seek. You can set it to avoid the initial tell call. - The target is set to -1, meaning it will be set to the offset - before the target is needed. - Returns NULL if a stream can't be created. */ -extern FILE *__newstream (void) __THROW; - -#ifdef __USE_POSIX -/* Create a new stream that refers to an existing system file descriptor. */ -extern FILE *__fdopen (int __fd, __const char *__modes) __THROW; -extern FILE *fdopen (int __fd, __const char *__modes) __THROW; -#endif - -#ifdef __USE_GNU -/* Create a new stream that refers to the given magic cookie, - and uses the given functions for input and output. */ -extern FILE *fopencookie (void *__magic_cookie, __const char *__modes, - __io_functions __io_funcs) __THROW; - -/* Create a new stream that refers to a memory buffer. */ -extern FILE *fmemopen (void *__s, size_t __len, __const char *__modes) __THROW; - -/* Open a stream that writes into a malloc'd buffer that is expanded as - necessary. *BUFLOC and *SIZELOC are updated with the buffer's location - and the number of characters written on fflush or fclose. */ -extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __THROW; -#endif - - -/* If BUF is NULL, make STREAM unbuffered. - Else make it use buffer BUF, of size BUFSIZ. */ -extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __THROW; -/* Make STREAM use buffering mode MODE. - If BUF is not NULL, use N bytes of it for buffering; - else allocate an internal buffer N bytes long. */ -extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf, - int __modes, size_t __n) __THROW; - -#ifdef __USE_BSD -/* If BUF is NULL, make STREAM unbuffered. - Else make it use SIZE bytes of BUF for buffering. */ -extern void setbuffer (FILE *__stream, char *__buf, size_t __size) __THROW; - -/* Make STREAM line-buffered. */ -extern void setlinebuf (FILE *__stream) __THROW; -#endif - - -/* Write formatted output to STREAM. */ -extern int fprintf (FILE *__restrict __stream, - __const char *__restrict __format, ...) __THROW; -/* Write formatted output to stdout. */ -extern int printf (__const char *__restrict __format, ...) __THROW; -/* Write formatted output to S. */ -extern int sprintf (char *__restrict __s, __const char *__restrict __format, - ...) __THROW; - -/* Write formatted output to S from argument list ARG. */ -extern int vfprintf (FILE *__restrict __s, __const char *__restrict __format, - __gnuc_va_list __arg) __THROW; -/* Write formatted output to stdout from argument list ARG. */ -extern int vprintf (__const char *__restrict __format, __gnuc_va_list __arg) - __THROW; -/* Write formatted output to S from argument list ARG. */ -extern int vsprintf (char *__restrict __s, __const char *__restrict __format, - __gnuc_va_list __arg) __THROW; - -#ifdef __OPTIMIZE__ -extern __inline int -vprintf (const char *__restrict __fmt, __gnuc_va_list __arg) __THROW -{ - return vfprintf (stdout, __fmt, __arg); -} -#endif /* Optimizing. */ - -#if defined __USE_BSD || defined __USE_ISOC99 -/* Maximum chars of output to write in MAXLEN. */ -extern int __snprintf (char *__s, size_t __maxlen, - __const char *__format, ...) - __THROW __attribute__ ((__format__ (__printf__, 3, 4))); -extern int snprintf (char *__s, size_t __maxlen, __const char *__format, ...) - __THROW __attribute__ ((__format__ (__printf__, 3, 4))); - -extern int __vsnprintf (char *__s, size_t __maxlen, - __const char *__format, __gnuc_va_list __arg) - __THROW __attribute__ ((__format__ (__printf__, 3, 0))); -extern int vsnprintf (char *__s, size_t __maxlen, - __const char *__format, __gnuc_va_list __arg) - __THROW __attribute__ ((__format__ (__printf__, 3, 0))); -#endif - -#ifdef __USE_GNU -/* Write formatted output to a string dynamically allocated with `malloc'. - Store the address of the string in *PTR. */ -extern int vasprintf (char **__restrict __ptr, - __const char *__restrict __f, __gnuc_va_list __arg) - __THROW __attribute__ ((__format__ (__printf__, 2, 0))); -extern int __asprintf (char **__restrict __ptr, - __const char *__restrict __fmt, ...) - __THROW __attribute__ ((__format__ (__printf__, 2, 3))); -extern int asprintf (char **__restrict __ptr, - __const char *__restrict __fmt, ...) - __THROW __attribute__ ((__format__ (__printf__, 2, 3))); - -/* Write formatted output to a file descriptor. */ -extern int vdprintf (int __fd, __const char *__restrict __fmt, - __gnuc_va_list __arg) - __THROW __attribute__ ((__format__ (__printf__, 2, 0))); -extern int dprintf (int __fd, __const char *__restrict __fmt, ...) - __THROW __attribute__ ((__format__ (__printf__, 2, 3))); -#endif - - -/* Read formatted input from STREAM. */ -extern int fscanf (FILE *__restrict __stream, - __const char *__restrict __format, ...) __THROW; -/* Read formatted input from stdin. */ -extern int scanf (__const char *__restrict __format, ...) __THROW; -/* Read formatted input from S. */ -extern int sscanf (__const char *__restrict __s, - __const char *__restrict __format, ...) __THROW; - -#ifdef __USE_ISOC99 -/* Read formatted input from S into argument list ARG. */ -extern int __vfscanf (FILE *__s, __const char *__format, - __gnuc_va_list __arg) __THROW; -extern int vfscanf (FILE *__s, __const char *__format, - __gnuc_va_list __arg) __THROW; - -/* Read formatted input from stdin into argument list ARG. */ -extern int __vscanf (__const char *__format, __gnuc_va_list __arg) __THROW; -extern int vscanf (__const char *__format, __gnuc_va_list __arg) __THROW; - -/* Read formatted input from S into argument list ARG. */ -extern int __vsscanf (__const char *__s, __const char *__format, - __gnuc_va_list __arg) __THROW; -extern int vsscanf (__const char *__s, __const char *__format, - __gnuc_va_list __arg) __THROW; - - -#ifdef __OPTIMIZE__ -extern __inline int -vfscanf (FILE *__s, const char *__fmt, __gnuc_va_list __arg) __THROW -{ - return __vfscanf (__s, __fmt, __arg); -} -extern __inline int -vscanf (const char *__fmt, __gnuc_va_list __arg) __THROW -{ - return __vfscanf (stdin, __fmt, __arg); -} -extern __inline int -vsscanf (const char *__s, const char *__fmt, __gnuc_va_list __arg) __THROW -{ - return __vsscanf (__s, __fmt, __arg); -} -#endif /* Optimizing. */ -#endif /* Use ISO C9x. */ - - -/* This does actual reading when necessary, filling STREAM's - buffer and returning the first character in it. */ -extern int __fillbf (FILE *__stream) __THROW; - - -/* Read a character from STREAM. */ -extern int fgetc (FILE *__stream) __THROW; -extern int getc (FILE *__stream) __THROW; - -/* Read a character from stdin. */ -extern int getchar (void) __THROW; - -/* The C standard explicitly says this can - re-evaluate its argument, so it does. */ -#define __getc(stream) \ - ((stream)->__bufp < (stream)->__get_limit ? \ - (int) ((unsigned char) *(stream)->__bufp++) : __fillbf(stream)) - -/* The C standard explicitly says this is a macro, - so we always do the optimization for it. */ -#define getc(stream) __getc(stream) - -#ifdef __OPTIMIZE__ -extern __inline int -getchar (void) __THROW -{ - return __getc (stdin); -} -#endif /* Optimizing. */ - -#if defined __USE_POSIX || defined __USE_MISC -/* These are defined in POSIX.1:1996. */ -extern int getc_unlocked (FILE *__stream) __THROW; -extern int getchar_unlocked (void) __THROW; - -# ifdef __OPTIMIZE__ -extern __inline int -getc_unlocked (FILE *__stream) __THROW -{ - return __getc (__stream); -} - -extern __inline int -getchar_unlocked (void) __THROW -{ - return __getc (stdin); -} -# endif /* Optimizing. */ -#endif /* Use POSIX or MISC. */ - - -/* Write a character to STREAM. */ -extern int fputc (int __c, FILE *__stream) __THROW; -extern int putc (int __c, FILE *__stream) __THROW; - -/* Write a character to stdout. */ -extern int putchar (int __c) __THROW; - - -/* The C standard explicitly says this can - re-evaluate its arguments, so it does. */ -#define __putc(c, stream) \ - ((stream)->__bufp < (stream)->__put_limit ? \ - (int) (unsigned char) (*(stream)->__bufp++ = (unsigned char) (c)) : \ - __flshfp ((stream), (unsigned char) (c))) - -/* The C standard explicitly says this can be a macro, - so we always do the optimization for it. */ -#define putc(c, stream) __putc ((c), (stream)) - -#ifdef __OPTIMIZE__ -extern __inline int -putchar (int __c) __THROW -{ - return __putc (__c, stdout); -} -#endif - -#ifdef __USE_MISC -/* Faster version when locking is not necessary. */ -extern int fputc_unlocked (int __c, FILE *__stream) __THROW; - -# ifdef __OPTIMIZE__ -extern __inline int -fputc_unlocked (int __c, FILE *__stream) __THROW -{ - return __putc (__c, __stream); -} -# endif /* Optimizing. */ -#endif /* Use MISC. */ - -#if defined __USE_POSIX || defined __USE_MISC -/* These are defined in POSIX.1:1996. */ -extern int putc_unlocked (int __c, FILE *__stream) __THROW; -extern int putchar_unlocked (int __c) __THROW; - -# ifdef __OPTIMIZE__ -extern __inline int -putc_unlocked (int __c, FILE *__stream) __THROW -{ - return __putc (__c, __stream); -} - -extern __inline int -putchar_unlocked (int __c) __THROW -{ - return __putc (__c, stdout); -} -# endif /* Optimizing. */ -#endif /* Use POSIX or MISC. */ - - -#if defined __USE_SVID || defined __USE_MISC -/* Get a word (int) from STREAM. */ -extern int getw (FILE *__stream) __THROW; - -/* Write a word (int) to STREAM. */ -extern int putw (int __w, FILE *__stream) __THROW; -#endif - - -/* Get a newline-terminated string of finite length from STREAM. */ -extern char *fgets (char *__restrict __s, int __n, - FILE *__restrict __stream) __THROW; - -#ifdef __USE_GNU -/* This function does the same as `fgets' but does not lock the stream. */ -extern char *fgets_unlocked (char *__restrict __s, int __n, - FILE *__restrict __stream) __THROW; -#endif - -/* Get a newline-terminated string from stdin, removing the newline. - DO NOT USE THIS FUNCTION!! There is no limit on how much it will read. */ -extern char *gets (char *__s) __THROW; - - -#ifdef __USE_GNU -#include <sys/types.h> - -/* Read up to (and including) a DELIMITER from STREAM into *LINEPTR - (and null-terminate it). *LINEPTR is a pointer returned from malloc (or - NULL), pointing to *N characters of space. It is realloc'd as - necessary. Returns the number of characters read (not including the - null terminator), or -1 on error or EOF. */ -ssize_t __getdelim (char **__lineptr, size_t *__n, - int __delimiter, FILE *__stream) __THROW; -ssize_t getdelim (char **__lineptr, size_t *__n, - int __delimiter, FILE *__stream) __THROW; - -/* Like `getdelim', but reads up to a newline. */ -ssize_t __getline (char **__lineptr, size_t *__n, FILE *__stream) __THROW; -ssize_t getline (char **__lineptr, size_t *__n, FILE *__stream) __THROW; - -#ifdef __OPTIMIZE__ -extern __inline ssize_t -getline (char **__lineptr, size_t *__n, FILE *__stream) __THROW -{ - return __getdelim (__lineptr, __n, '\n', __stream); -} -#endif /* Optimizing. */ -#endif - - -/* Write a string to STREAM. */ -extern int fputs (__const char *__restrict __s, FILE *__restrict __stream) - __THROW; - -#ifdef __USE_GNU -/* This function does the same as `fputs' but does not lock the stream. */ -extern int fputs_unlocked (__const char *__restrict __s, - FILE *__restrict __stream) __THROW; -#endif - -/* Write a string, followed by a newline, to stdout. */ -extern int puts (__const char *__s) __THROW; - - -/* Push a character back onto the input buffer of STREAM. */ -extern int ungetc (int __c, FILE *__stream) __THROW; - - -/* Read chunks of generic data from STREAM. */ -extern size_t fread (void *__restrict __ptr, size_t __size, - size_t __n, FILE *__restrict __stream) __THROW; -/* Write chunks of generic data to STREAM. */ -extern size_t fwrite (__const void *__restrict __ptr, size_t __size, - size_t __n, FILE *__restrict __s) __THROW; - -#ifdef __USE_MISC -/* Faster versions when locking is not necessary. */ -extern size_t fread_unlocked (void *__restrict __ptr, size_t __size, - size_t __n, FILE *__restrict __stream) __THROW; -extern size_t fwrite_unlocked (__const void *__restrict __ptr, - size_t __size, size_t __n, - FILE *__restrict __stream) __THROW; -#endif - - -/* Seek to a certain position on STREAM. */ -extern int fseek (FILE *__stream, long int __off, int __whence) __THROW; -/* Return the current position of STREAM. */ -extern long int ftell (FILE *__stream) __THROW; -/* Rewind to the beginning of STREAM. */ -extern void rewind (FILE *__stream) __THROW; - -/* Get STREAM's position. */ -extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos) - __THROW; -/* Set STREAM's position. */ -extern int fsetpos (FILE *__stream, __const fpos_t *__pos) __THROW; - - -/* Clear the error and EOF indicators for STREAM. */ -extern void clearerr (FILE *__stream) __THROW; -/* Return the EOF indicator for STREAM. */ -extern int feof (FILE *__stream) __THROW; -/* Return the error indicator for STREAM. */ -extern int ferror (FILE *__stream) __THROW; - -#ifdef __OPTIMIZE__ -#define feof(stream) ((stream)->__eof != 0) -#define ferror(stream) ((stream)->__error != 0) -#endif /* Optimizing. */ - -#ifdef __USE_MISC -/* Faster versions when locking is not required. */ -extern void clearerr_unlocked (FILE *__stream) __THROW; -extern int feof_unlocked (FILE *__stream) __THROW; -extern int ferror_unlocked (FILE *__stream) __THROW; - -# ifdef __OPTIMIZE__ -# define feof_unlocked(stream) ((stream)->__eof != 0) -# define ferror_unlocked(stream) ((stream)->__error != 0) -# endif /* Optimizing. */ -#endif - -/* Print a message describing the meaning of the value of errno. */ -extern void perror (__const char *__s) __THROW; - - -#ifdef __USE_POSIX -/* Return the system file descriptor for STREAM. */ -extern int fileno (FILE *__stream) __THROW; -#endif /* Use POSIX. */ - -#ifdef __USE_MISC -/* Faster version when locking is not required. */ -extern int fileno_unlocked (FILE *__stream) __THROW; -#endif - - -#if (defined __USE_POSIX2 || defined __USE_SVID || defined __USE_BSD || \ - defined __USE_MISC) -/* Create a new stream connected to a pipe running the given command. */ -extern FILE *popen (__const char *__command, __const char *__modes) __THROW; - -/* Close a stream opened by popen and return the status of its child. */ -extern int pclose (FILE *__stream) __THROW; -#endif - - -#ifdef __USE_POSIX -/* Return the name of the controlling terminal. */ -extern char *ctermid (char *__s) __THROW; -#endif - - -#ifdef __USE_XOPEN -/* Return the name of the current user. */ -extern char *cuserid (char *__s) __THROW; -#endif - - -#ifdef __USE_GNU -struct obstack; /* See <obstack.h>. */ - -/* Open a stream that writes to OBSTACK. */ -extern FILE *open_obstack_stream (struct obstack *__obstack) __THROW; - -/* Write formatted output to an obstack. */ -extern int obstack_printf (struct obstack *__obstack, - __const char *__format, ...) __THROW; -extern int obstack_vprintf (struct obstack *__obstack, __const char *__format, - __gnuc_va_list __args) __THROW; -#endif - - -#if defined __USE_POSIX || defined __USE_MISC -/* These are defined in POSIX.1:1996. */ - -/* Acquire ownership of STREAM. */ -extern void flockfile (FILE *__stream) __THROW; - -/* Try to acquire ownership of STREAM but do not block if it is not - possible. */ -extern int ftrylockfile (FILE *__stream) __THROW; - -/* Relinquish the ownership granted for STREAM. */ -extern void funlockfile (FILE *__stream) __THROW; -#endif /* POSIX || misc */ - -#if defined __USE_XOPEN && !defined __USE_GNU -/* The X/Open standard requires some functions and variables to be - declared here which do not belong into this header. But we have to - follow. In GNU mode we don't do this nonsense. */ -# define __need_getopt -# include <getopt.h> -#endif - -__END_DECLS - -#endif /* <stdio.h> included. */ - -#endif /* stdio.h */ diff --git a/stdio/ungetc.c b/stdio/ungetc.c deleted file mode 100644 index 34304aa3fd..0000000000 --- a/stdio/ungetc.c +++ /dev/null @@ -1,59 +0,0 @@ -/* Copyright (C) 1991, 1993, 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <stdio.h> - - -/* Push the character C back onto the input stream of STREAM. */ -int -ungetc (c, stream) - int c; - FILE *stream; -{ - if (!__validfp (stream) || !stream->__mode.__read) - { - __set_errno (EINVAL); - return EOF; - } - - if (c == EOF) - return EOF; - - if (stream->__pushed_back) - /* There is already a char pushed back. */ - return EOF; - - if ((stream->__linebuf_active || stream->__put_limit > stream->__buffer) && - /* This is a read-write stream with something in its buffer. - Flush the stream. */ - __flshfp (stream, EOF) == EOF) - return EOF; - - stream->__pushback = (unsigned char) c; - /* Tell __fillbf we've pushed back a char. */ - stream->__pushed_back = 1; - stream->__pushback_bufp = stream->__bufp; - /* Make the next getc call __fillbf. It will return C. */ - stream->__bufp = stream->__get_limit; - - /* We just gave it another character to read, so it's not at EOF. */ - stream->__eof = 0; - - return stream->__pushback; -} diff --git a/stdio/vasprintf.c b/stdio/vasprintf.c deleted file mode 100644 index 8da6f02cf2..0000000000 --- a/stdio/vasprintf.c +++ /dev/null @@ -1,85 +0,0 @@ -/* Copyright (C) 1991, 1992, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stddef.h> -#include <stdarg.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - - - -/* Enlarge STREAM's buffer. */ -static void -enlarge_buffer (FILE *stream, int c) -{ - ptrdiff_t bufp_offset = stream->__bufp - stream->__buffer; - char *newbuf; - - stream->__bufsize += 100; - newbuf = (char *) realloc ((void *) stream->__buffer, stream->__bufsize); - if (newbuf == NULL) - { - free ((void *) stream->__buffer); - stream->__buffer = stream->__bufp - = stream->__put_limit = stream->__get_limit = NULL; - stream->__error = 1; - } - else - { - stream->__buffer = newbuf; - stream->__bufp = stream->__buffer + bufp_offset; - stream->__get_limit = stream->__put_limit; - stream->__put_limit = stream->__buffer + stream->__bufsize; - if (c != EOF) - *stream->__bufp++ = (unsigned char) c; - } -} - -/* Write formatted output from FORMAT to a string which is - allocated with malloc and stored in *STRING_PTR. */ -int -vasprintf (char **string_ptr, - const char *format, - va_list args) -{ - FILE f; - int done; - - memset ((void *) &f, 0, sizeof (f)); - f.__magic = _IOMAGIC; - f.__bufsize = 100; - f.__buffer = (char *) malloc (f.__bufsize); - if (f.__buffer == NULL) - return -1; - f.__bufp = f.__buffer; - f.__put_limit = f.__buffer + f.__bufsize; - f.__mode.__write = 1; - f.__room_funcs.__output = enlarge_buffer; - f.__seen = 1; - - done = vfprintf (&f, format, args); - if (done < 0) - return done; - - *string_ptr = realloc (f.__buffer, (f.__bufp - f.__buffer) + 1); - if (*string_ptr == NULL) - *string_ptr = f.__buffer; - (*string_ptr)[f.__bufp - f.__buffer] = '\0'; - return done; -} diff --git a/stdio/vscanf.c b/stdio/vscanf.c deleted file mode 100644 index 655f282d7c..0000000000 --- a/stdio/vscanf.c +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright (C) 1991, 1992, 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stdarg.h> -#include <stdio.h> - -#undef vscanf - - -/* Read formatted input from stdin according to the format - string in FORMAT, using the argument list in ARG. */ -int -__vscanf (const char *format, va_list arg) -{ - return vfscanf (stdin, format, arg); -} -weak_alias (__vscanf, vscanf) diff --git a/stdio/vsnprintf.c b/stdio/vsnprintf.c deleted file mode 100644 index 83271834e2..0000000000 --- a/stdio/vsnprintf.c +++ /dev/null @@ -1,59 +0,0 @@ -/* Copyright (C) 1991, 1992, 1995, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <stdarg.h> -#include <stdio.h> -#include <string.h> - - -/* - * Write formatted output to S according to the format string - * FORMAT, using the argument list in ARG, writing no more - * than MAXLEN characters. - */ -int -__vsnprintf (char *s, size_t maxlen, const char *format, va_list arg) -{ - int done; - FILE f; - - /* We have to handle the case of MAXLEN == 0 special. */ - if (maxlen == 0) - return 0; - - memset ((void *) &f, 0, sizeof (f)); - f.__magic = _IOMAGIC; - f.__mode.__write = 1; - /* The buffer size is one less than MAXLEN - so we have space for the null terminator. */ - f.__bufp = f.__buffer = (char *) s; - f.__bufsize = maxlen - 1; - f.__put_limit = f.__buffer + f.__bufsize; - f.__get_limit = f.__buffer; - /* After the buffer is full (MAXLEN characters have been written), - any more characters written will go to the bit bucket. */ - f.__room_funcs = __default_room_functions; - f.__io_funcs.__write = NULL; - f.__seen = 1; - - done = vfprintf (&f, format, arg); - *f.__bufp = '\0'; - - return done; -} -weak_alias (__vsnprintf, vsnprintf) diff --git a/stdio/vsprintf.c b/stdio/vsprintf.c deleted file mode 100644 index bd34ec2a4a..0000000000 --- a/stdio/vsprintf.c +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright (C) 1991, 1992, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <limits.h> -#include <stdarg.h> -#include <stdio.h> -#include <string.h> - - -/* Write formatted output to S according to the format string - FORMAT, using the argument list in ARG. */ -int -vsprintf (s, format, arg) - char *s; - const char *format; - va_list arg; -{ - int done; - FILE f; - - memset ((void *) &f, 0, sizeof (f)); - f.__magic = _IOMAGIC; - f.__mode.__write = 1; - f.__bufp = f.__buffer = (char *) s; - f.__put_limit = (char *) ULONG_MAX; - f.__bufsize = (size_t) (f.__put_limit - f.__bufp); - f.__get_limit = f.__buffer; - f.__room_funcs.__output = NULL; - f.__seen = 1; - - done = vfprintf (&f, format, arg); - *f.__bufp = '\0'; - - return done; -} diff --git a/stdio/vsscanf.c b/stdio/vsscanf.c deleted file mode 100644 index e037f8c92d..0000000000 --- a/stdio/vsscanf.c +++ /dev/null @@ -1,59 +0,0 @@ -/* Copyright (C) 1991, 1992, 1995, 1996, 1997 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <stdarg.h> -#include <stdio.h> -#include <string.h> - -#undef vsscanf - - -/* Read formatted input from S according to the format - string FORMAT, using the argument list in ARG. */ -int -__vsscanf (s, format, arg) - const char *s; - const char *format; - va_list arg; -{ - FILE f; - - if (s == NULL) - { - __set_errno (EINVAL); - return -1; - } - - memset ((void *) &f, 0, sizeof (f)); - f.__magic = _IOMAGIC; - f.__mode.__read = 1; - f.__bufp = f.__buffer = (char *) s; - f.__bufsize = strlen(s); - f.__get_limit = f.__buffer + f.__bufsize; - f.__put_limit = f.__buffer; - /* After the buffer is empty (strlen(S) characters have been read), - any more read attempts will get EOF. */ - f.__room_funcs.__input = NULL; - f.__seen = 1; - - return __vfscanf (&f, format, arg); -} - - -weak_alias (__vsscanf, vsscanf) |