Update.
[platform/upstream/glibc.git] / stdio / stdio.h
index 8072625..2631d83 100644 (file)
@@ -1,23 +1,23 @@
-/* Copyright (C) 1991, 92, 93, 94, 95, 96 Free Software Foundation, Inc.
-This file is part of the GNU C Library.
+/* 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 Library General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 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
-Library General Public License for more details.
+   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
+   Library General Public License for more details.
 
-You should have received a copy of the GNU Library General Public
-License along with the GNU C Library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA.  */
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
 
 /*
- *     ANSI Standard: 4.9 INPUT/OUTPUT <stdio.h>
+ *     ISO C Standard: 4.9 INPUT/OUTPUT        <stdio.h>
  */
 
 #ifndef        _STDIO_H
@@ -38,7 +38,7 @@ __BEGIN_DECLS
 #define        __gnuc_va_list  __ptr_t
 #endif
 
-#include <gnu/types.h>
+#include <bits/types.h>
 #endif /* Don't need FILE.  */
 #undef __need_FILE
 
@@ -111,7 +111,7 @@ typedef __io_fileno_fn cookie_fileno_function_t;
 #endif
 
 /* Low level interface, independent of FILE representation.  */
-#if defined (__USE_GNU) && !defined (_LIBC)
+#if defined __USE_GNU && !defined _LIBC
 /* Define the user-visible type, with user-friendly member names.  */
 typedef struct
 {
@@ -161,7 +161,8 @@ extern char *__stdio_gen_tempname __P ((char *__buf, size_t __bufsize,
                                        __const char *__pfx,
                                        int __dir_search,
                                        size_t *__lenptr,
-                                       FILE **__streamptr));
+                                       FILE **__streamptr,
+                                       int __large_file));
 
 
 /* Print out MESSAGE on the error output and abort.  */
@@ -169,6 +170,10 @@ extern void __libc_fatal __P ((__const char *__message))
      __attribute__ ((__noreturn__));
 
 
+/* 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
 {
@@ -176,8 +181,8 @@ struct __stdio_file
      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        0xfedabeeb      /* Magic number to fill `__magic'.  */
-#define        _GLUEMAGIC      0xfeedbabe      /* Magic for glued Unix streams.  */
+#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.  */
@@ -202,6 +207,7 @@ struct __stdio_file
   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.  */
 };
 
 
@@ -265,9 +271,9 @@ extern int __stdio_check_offset __P ((FILE *__stream));
                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   Mininum number of files that can be open at once.
+   FOPEN_MAX   Minimum number of files that can be open at once.
    FILENAME_MAX        Maximum length of a filename.  */
-#include <stdio_lim.h>
+#include <bits/stdio_lim.h>
 
 
 /* All the known streams are in a linked list
@@ -292,6 +298,9 @@ extern int rename __P ((__const char *__old, __const char *__new));
 
 /* Create a temporary file and open it read/write.  */
 extern FILE *tmpfile __P ((void));
+#ifdef __USE_LARGEFILE64
+extern FILE *tmpfile64 __P ((void));
+#endif
 /* Generate a temporary filename.  */
 extern char *tmpnam __P ((char *__s));
 
@@ -302,7 +311,7 @@ extern char *tmpnam_r __P ((char *__s));
 #endif
 
 
-#ifdef __USE_SVID
+#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.
@@ -319,17 +328,24 @@ extern char *tempnam __P ((__const char *__dir, __const char *__pfx));
 extern int __flshfp __P ((FILE *__stream, int __c));
 
 
-/* Close STREAM, or all streams if STREAM is NULL.  */
+/* Close STREAM.  */
 extern int fclose __P ((FILE *__stream));
 /* Flush STREAM, or all streams if STREAM is NULL.  */
 extern int fflush __P ((FILE *__stream));
 
+#ifdef __USE_GNU
+/* Close all streams.  */
+extern int __fcloseall __P ((void));
+extern int fcloseall __P ((void));
+#endif
+
 
 /* Open a file and create a new stream for it.  */
 extern FILE *fopen __P ((__const char *__filename, __const char *__modes));
 /* Open a file, replacing an existing stream with it. */
-extern FILE *freopen __P ((__const char *__filename,
-                          __const char *__modes, FILE *__stream));
+extern FILE *freopen __P ((__const char *__restrict __filename,
+                          __const char *__restrict __modes,
+                          FILE *__restrict __stream));
 
 /* Return a new, zeroed, stream.
    You must set its cookie and io_mode.
@@ -365,11 +381,11 @@ extern FILE *open_memstream __P ((char **__bufloc, size_t *__sizeloc));
 
 /* If BUF is NULL, make STREAM unbuffered.
    Else make it use buffer BUF, of size BUFSIZ.  */
-extern void setbuf __P ((FILE *__stream, char *__buf));
+extern void setbuf __P ((FILE *__restrict __stream, char *__restrict __buf));
 /* 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 __P ((FILE *__stream, char *__buf,
+extern int setvbuf __P ((FILE *__restrict __stream, char *__restrict __buf,
                         int __modes, size_t __n));
 
 #ifdef __USE_BSD
@@ -383,60 +399,77 @@ extern void setlinebuf __P ((FILE *__stream));
 
 
 /* Write formatted output to STREAM.  */
-extern int fprintf __P ((FILE *__stream, __const char *__format, ...));
+extern int fprintf __P ((FILE *__restrict __stream,
+                        __const char *__restrict __format, ...));
 /* Write formatted output to stdout.  */
-extern int printf __P ((__const char *__format, ...));
+extern int printf __P ((__const char *__restrict __format, ...));
 /* Write formatted output to S.  */
-extern int sprintf __P ((char *__s, __const char *__format, ...));
+extern int sprintf __P ((char *__restrict __s,
+                        __const char *__restrict __format, ...));
 
 /* Write formatted output to S from argument list ARG.  */
-extern int vfprintf __P ((FILE *__s, __const char *__format,
+extern int vfprintf __P ((FILE *__restrict __s,
+                         __const char *__restrict __format,
                          __gnuc_va_list __arg));
 /* Write formatted output to stdout from argument list ARG.  */
-extern int vprintf __P ((__const char *__format, __gnuc_va_list __arg));
+extern int vprintf __P ((__const char *__restrict __format,
+                        __gnuc_va_list __arg));
 /* Write formatted output to S from argument list ARG.  */
-extern int vsprintf __P ((char *__s, __const char *__format,
+extern int vsprintf __P ((char *__restrict __s,
+                         __const char *__restrict __format,
                          __gnuc_va_list __arg));
 
 #ifdef __OPTIMIZE__
 extern __inline int
-vprintf (const char *__fmt, __gnuc_va_list __arg)
+vprintf (const char *__restrict __fmt, __gnuc_va_list __arg)
 {
   return vfprintf (stdout, __fmt, __arg);
 }
 #endif /* Optimizing.  */
 
-#ifdef __USE_GNU
+#if defined __USE_BSD || defined __USE_ISOC9X
 /* Maximum chars of output to write in MAXLEN.  */
 extern int __snprintf __P ((char *__s, size_t __maxlen,
-                           __const char *__format, ...));
+                           __const char *__format, ...))
+     __attribute__ ((__format__ (__printf__, 3, 4)));
 extern int snprintf __P ((char *__s, size_t __maxlen,
-                         __const char *__format, ...));
+                         __const char *__format, ...))
+     __attribute__ ((__format__ (__printf__, 3, 4)));
 
 extern int __vsnprintf __P ((char *__s, size_t __maxlen,
-                            __const char *__format, __gnuc_va_list __arg));
+                            __const char *__format, __gnuc_va_list __arg))
+     __attribute__ ((__format__ (__printf__, 3, 0)));
 extern int vsnprintf __P ((char *__s, size_t __maxlen,
-                          __const char *__format, __gnuc_va_list __arg));
+                          __const char *__format, __gnuc_va_list __arg))
+     __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 __P ((char **__ptr, __const char *__f,
-                          __gnuc_va_list __arg));
-extern int asprintf __P ((char **__ptr, __const char *__fmt, ...));
+                          __gnuc_va_list __arg))
+     __attribute__ ((__format__ (__printf__, 2, 0)));
+extern int asprintf __P ((char **__ptr, __const char *__fmt, ...))
+     __attribute__ ((__format__ (__printf__, 2, 0)));
 
 /* Write formatted output to a file descriptor.  */
 extern int vdprintf __P ((int __fd, __const char *__fmt,
-                         __gnuc_va_list __arg));
-extern int dprintf __P ((int __fd, __const char *__fmt, ...));
+                         __gnuc_va_list __arg))
+     __attribute__ ((__format__ (__printf__, 2, 0)));
+extern int dprintf __P ((int __fd, __const char *__fmt, ...))
+     __attribute__ ((__format__ (__printf__, 2, 0)));
 #endif
 
 
 /* Read formatted input from STREAM.  */
-extern int fscanf __P ((FILE *__stream, __const char *__format, ...));
+extern int fscanf __P ((FILE *__restrict __stream,
+                       __const char *__restrict __format, ...));
 /* Read formatted input from stdin.  */
-extern int scanf __P ((__const char *__format, ...));
+extern int scanf __P ((__const char *__restrict __format, ...));
 /* Read formatted input from S.  */
-extern int sscanf __P ((__const char *__s, __const char *__format, ...));
+extern int sscanf __P ((__const char *__restrict __s,
+                       __const char *__restrict __format, ...));
 
 #ifdef __USE_GNU
 /* Read formatted input from S into argument list ARG.  */
@@ -535,7 +568,7 @@ putchar (int __c)
 #endif
 
 
-#if defined(__USE_SVID) || defined(__USE_MISC)
+#if defined __USE_SVID || defined __USE_MISC
 /* Get a word (int) from STREAM.  */
 extern int getw __P ((FILE *__stream));
 
@@ -545,7 +578,8 @@ extern int putw __P ((int __w, FILE *__stream));
 
 
 /* Get a newline-terminated string of finite length from STREAM.  */
-extern char *fgets __P ((char *__s, int __n, FILE *__stream));
+extern char *fgets __P ((char *__restrict __s, int __n,
+                        FILE *__restrict __stream));
 
 /* 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.  */
@@ -571,27 +605,17 @@ ssize_t getline __P ((char **__lineptr, size_t *__n, FILE *__stream));
 
 #ifdef __OPTIMIZE__
 extern __inline ssize_t
-__getline (char **__lineptr, size_t *__n, FILE *__stream)
-{
-  return __getdelim (__lineptr, __n, '\n', __stream);
-}
-
-extern __inline ssize_t
-getdelim (char **__lineptr, size_t *__n, int __delimiter, FILE *__stream)
-{
-  return __getdelim (__lineptr, __n, __delimiter, __stream);
-}
-extern __inline ssize_t
 getline (char **__lineptr, size_t *__n, FILE *__stream)
 {
-  return __getline (__lineptr, __n, __stream);
+  return __getdelim (__lineptr, __n, '\n', __stream);
 }
 #endif /* Optimizing.  */
 #endif
 
 
 /* Write a string to STREAM.  */
-extern int fputs __P ((__const char *__s, FILE *__stream));
+extern int fputs __P ((__const char *__restrict __s,
+                      FILE *__restrict __stream));
 /* Write a string, followed by a newline, to stdout.  */
 extern int puts __P ((__const char *__s));
 
@@ -601,11 +625,11 @@ extern int ungetc __P ((int __c, FILE *__stream));
 
 
 /* Read chunks of generic data from STREAM.  */
-extern size_t fread __P ((__ptr_t __ptr, size_t __size,
-                         size_t __n, FILE *__stream));
+extern size_t fread __P ((__ptr_t __restrict __ptr, size_t __size,
+                         size_t __n, FILE *__restrict __stream));
 /* Write chunks of generic data to STREAM.  */
-extern size_t fwrite __P ((__const __ptr_t __ptr, size_t __size,
-                          size_t __n, FILE *__s));
+extern size_t fwrite __P ((__const __ptr_t __restrict __ptr, size_t __size,
+                          size_t __n, FILE *__restrict __s));
 
 
 /* Seek to a certain position on STREAM.  */
@@ -616,7 +640,7 @@ extern long int ftell __P ((FILE *__stream));
 extern void rewind __P ((FILE *__stream));
 
 /* Get STREAM's position.  */
-extern int fgetpos __P ((FILE *__stream, fpos_t *__pos));
+extern int fgetpos __P ((FILE *__restrict __stream, fpos_t *__restrict __pos));
 /* Set STREAM's position.  */
 extern int fsetpos __P ((FILE *__stream, __const fpos_t *__pos));
 
@@ -653,8 +677,8 @@ extern int fileno __P ((FILE *__stream));
 #endif /* Use POSIX.  */
 
 
-#if (defined (__USE_POSIX2) || defined(__USE_SVID) || defined(__USE_BSD) || \
-     defined(__USE_MISC))
+#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 __P ((__const char *__command, __const char *__modes));
 
@@ -666,6 +690,10 @@ extern int pclose __P ((FILE *__stream));
 #ifdef __USE_POSIX
 /* Return the name of the controlling terminal.  */
 extern char *ctermid __P ((char *__s));
+#endif
+
+
+#ifdef __USE_XOPEN
 /* Return the name of the current user.  */
 extern char *cuserid __P ((char *__s));
 #endif