Back to index

glibc  2.9
Defines | Functions | Variables
stdio.h File Reference
#include <libio/stdio.h>
#include <stddef.h>

Go to the source code of this file.

Defines

#define __need_size_t
#define __GT_FILE   0 /* create a file */
#define __GT_DIR   1 /* create a directory */
#define __GT_NOCREATE   2 /* just find a name not currently in use */
#define __asprintf(ptr, fmt, args...)   INTUSE(__asprintf) (ptr, fmt, ##args)
#define fopen(fname, mode)   _IO_new_fopen (fname, mode)
#define fdopen(fd, mode)   _IO_new_fdopen (fd, mode)
#define fclose(fp)   _IO_new_fclose (fp)
#define fputs(str, fp)   _IO_fputs (str, fp)
#define fsetpos(fp, posp)   _IO_new_fsetpos (fp, posp)
#define fgetpos(fp, posp)   _IO_new_fgetpos (fp, posp)

Functions

int __fcloseall (void)
int __snprintf (char *__restrict __s, size_t __maxlen, __const char *__restrict __format,...) __attribute__((__format__(__printf__
int int __vsnprintf (char *__restrict __s, size_t __maxlen, __const char *__restrict __format, _G_va_list __arg) __attribute__((__format__(__printf__
int int int __vfscanf (FILE *__restrict __s, __const char *__restrict __format, _G_va_list __arg) __attribute__((__format__(__scanf__
int int int libc_hidden_proto (__vfscanf) extern int __vscanf(__const char *__restrict __format
int int int _G_va_list __arg __attribute__ ((__format__(__scanf__, 1, 0)))
_IO_ssize_t __getline (char **__lineptr, size_t *__n, FILE *__stream)
int __vsscanf (__const char *__restrict __s, __const char *__restrict __format, _G_va_list __arg) __attribute__((__format__(__scanf__
int int __sprintf_chk (char *, int, size_t, const char *,...) __THROW
int __snprintf_chk (char *, size_t, int, size_t, const char *,...) __THROW
int __vsprintf_chk (char *, int, size_t, const char *, _G_va_list) __THROW
int __vsnprintf_chk (char *, size_t, int, size_t, const char *, _G_va_list) __THROW
int __printf_chk (int, const char *,...)
int __fprintf_chk (FILE *, int, const char *,...)
int __vprintf_chk (int, const char *, _G_va_list)
int __vfprintf_chk (FILE *, int, const char *, _G_va_list)
char * __fgets_unlocked_chk (char *buf, size_t size, int n, FILE *fp)
char * __fgets_chk (char *buf, size_t size, int n, FILE *fp)
int __asprintf_chk (char **, int, const char *,...) __THROW
int __vasprintf_chk (char **, int, const char *, _G_va_list) __THROW
int __dprintf_chk (int, int, const char *,...)
int __vdprintf_chk (int, int, const char *, _G_va_list)
int __obstack_printf_chk (struct obstack *, int, const char *,...) __THROW
int __obstack_vprintf_chk (struct obstack *, int, const char *, _G_va_list) __THROW
int __isoc99_fscanf (FILE *__restrict __stream, __const char *__restrict __format,...) __wur
int __isoc99_scanf (__const char *__restrict __format,...) __wur
int __isoc99_sscanf (__const char *__restrict __s, __const char *__restrict __format,...) __THROW
int __isoc99_vfscanf (FILE *__restrict __s, __const char *__restrict __format, _G_va_list __arg) __wur
int __isoc99_vscanf (__const char *__restrict __format, _G_va_list __arg) __wur
int __isoc99_vsscanf (__const char *__restrict __s, __const char *__restrict __format, _G_va_list __arg) __THROW
 libc_hidden_proto (__isoc99_vsscanf) libc_hidden_proto(__isoc99_vfscanf) extern FILE *__new_tmpfile(void)
FILE__old_tmpfile (void)
int __path_search (char *__tmpl, size_t __tmpl_len, __const char *__dir, __const char *__pfx, int __try_tempdir)
int __gen_tempname (char *__tmpl, int __flags, int __kind)
void __libc_fatal (__const char *__message) __attribute__((__noreturn__))
void __libc_message (int do_abort, __const char *__fnt,...)
void __fortify_fail (const char *msg) __attribute__((noreturn))
 libc_hidden_proto (__fortify_fail) extern void __flockfile(FILE *__stream)
void __funlockfile (FILE *__stream)
int __ftrylockfile (FILE *__stream)
int __getc_unlocked (FILE *__fp)
wint_t __getwc_unlocked (FILE *__fp)
int __fxprintf (FILE *__fp, const char *__fmt,...) __attribute__((__format__(__printf__
int __asprintf_internal (char **__restrict __ptr, __const char *__restrict __fmt,...) attribute_hidden __attribute__((__format__(__printf__
_IO_FILE_IO_new_fopen (const char *, const char *)
_IO_FILE_IO_new_fdopen (int, const char *)
int _IO_new_fclose (_IO_FILE *)
int _IO_fputs (const char *, _IO_FILE *)
 libc_hidden_proto (_IO_fputs) extern int _IO_new_fsetpos(_IO_FILE *
int _IO_new_fgetpos (_IO_FILE *, _IO_fpos_t *)

Variables

int __const char *__const
_sys_errlist_internal[] 
attribute_hidden

Define Documentation

#define __asprintf (   ptr,
  fmt,
  args... 
)    INTUSE(__asprintf) (ptr, fmt, ##args)

Definition at line 119 of file stdio.h.

#define __GT_DIR   1 /* create a directory */

Definition at line 86 of file stdio.h.

#define __GT_FILE   0 /* create a file */

Definition at line 85 of file stdio.h.

#define __GT_NOCREATE   2 /* just find a name not currently in use */

Definition at line 87 of file stdio.h.

#define __need_size_t

Definition at line 76 of file stdio.h.

#define fclose (   fp)    _IO_new_fclose (fp)

Definition at line 127 of file stdio.h.

#define fdopen (   fd,
  mode 
)    _IO_new_fdopen (fd, mode)

Definition at line 125 of file stdio.h.

#define fgetpos (   fp,
  posp 
)    _IO_new_fgetpos (fp, posp)

Definition at line 134 of file stdio.h.

#define fopen (   fname,
  mode 
)    _IO_new_fopen (fname, mode)

Definition at line 123 of file stdio.h.

#define fputs (   str,
  fp 
)    _IO_fputs (str, fp)
#define fsetpos (   fp,
  posp 
)    _IO_new_fsetpos (fp, posp)

Definition at line 132 of file stdio.h.


Function Documentation

int __asprintf_chk ( char **  ,
int  ,
const char *  ,
  ... 
)

Definition at line 28 of file asprintf_chk.c.

{
  va_list arg;
  int done;

  va_start (arg, format);
  done = __vasprintf_chk (result_ptr, flags, format, arg);
  va_end (arg);

  return done;
}

Here is the call graph for this function:

int __asprintf_internal ( char **__restrict  __ptr,
__const char *__restrict  __fmt,
  ... 
)
int int int _G_va_list __arg __attribute__ ( (__format__(__scanf__, 1, 0))  )
int __dprintf_chk ( int  ,
int  ,
const char *  ,
  ... 
)

Definition at line 27 of file dprintf_chk.c.

{
  va_list arg;
  int done;

  va_start (arg, format);
  done = __vdprintf_chk (d, flags, format, arg);
  va_end (arg);

  return done;
}

Here is the call graph for this function:

int __fcloseall ( void  )

Definition at line 32 of file fcloseall.c.

{
  /* Close all streams.  */
  return _IO_cleanup ();
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* __fgets_chk ( char *  buf,
size_t  size,
int  n,
FILE fp 
)
char* __fgets_unlocked_chk ( char *  buf,
size_t  size,
int  n,
FILE fp 
)
void __fortify_fail ( const char *  msg)

Here is the caller graph for this function:

int __fprintf_chk ( FILE ,
int  ,
const char *  ,
  ... 
)

Definition at line 5 of file nldbl-fprintf_chk.c.

{
  va_list arg;
  int done;

  va_start (arg, fmt);
  done = __nldbl___vfprintf_chk (stream, flag, fmt, arg);
  va_end (arg);

  return done;
}

Here is the call graph for this function:

int __ftrylockfile ( FILE __stream)

Definition at line 27 of file ftrylockfile.c.

{
  return _IO_lock_trylock (*stream->_lock);
}
void __funlockfile ( FILE __stream)

Definition at line 27 of file funlockfile.c.

{
  _IO_lock_unlock (*stream->_lock);
}
int __fxprintf ( FILE __fp,
const char *  __fmt,
  ... 
)
int __gen_tempname ( char *  __tmpl,
int  __flags,
int  __kind 
)

Definition at line 226 of file tempname.c.

{
  int len;
  char *XXXXXX;
  static uint64_t value;
  uint64_t random_time_bits;
  unsigned int count;
  int fd = -1;
  int save_errno = errno;
  struct_stat64 st;

  /* A lower bound on the number of temporary files to attempt to
     generate.  The maximum total number of temporary file names that
     can exist for a given template is 62**6.  It should never be
     necessary to try all these combinations.  Instead if a reasonable
     number of names is tried (we define reasonable as 62**3) fail to
     give the system administrator the chance to remove the problems.  */
#define ATTEMPTS_MIN (62 * 62 * 62)

  /* The number of times to attempt to generate a temporary file.  To
     conform to POSIX, this must be no smaller than TMP_MAX.  */
#if ATTEMPTS_MIN < TMP_MAX
  unsigned int attempts = TMP_MAX;
#else
  unsigned int attempts = ATTEMPTS_MIN;
#endif

  len = strlen (tmpl);
  if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX"))
    {
      __set_errno (EINVAL);
      return -1;
    }

  /* This is where the Xs start.  */
  XXXXXX = &tmpl[len - 6];

  /* Get some more or less random data.  */
#ifdef RANDOM_BITS
  RANDOM_BITS (random_time_bits);
#else
# if HAVE_GETTIMEOFDAY || _LIBC
  {
    struct timeval tv;
    __gettimeofday (&tv, NULL);
    random_time_bits = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec;
  }
# else
  random_time_bits = time (NULL);
# endif
#endif
  value += random_time_bits ^ __getpid ();

  for (count = 0; count < attempts; value += 7777, ++count)
    {
      uint64_t v = value;

      /* Fill in the random bits.  */
      XXXXXX[0] = letters[v % 62];
      v /= 62;
      XXXXXX[1] = letters[v % 62];
      v /= 62;
      XXXXXX[2] = letters[v % 62];
      v /= 62;
      XXXXXX[3] = letters[v % 62];
      v /= 62;
      XXXXXX[4] = letters[v % 62];
      v /= 62;
      XXXXXX[5] = letters[v % 62];

      switch (kind)
       {
       case __GT_FILE:
         fd = __open (tmpl,
                     (flags & ~O_ACCMODE)
                     | O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
         break;

       case __GT_DIR:
         fd = __mkdir (tmpl, S_IRUSR | S_IWUSR | S_IXUSR);
         break;

       case __GT_NOCREATE:
         /* This case is backward from the other three.  __gen_tempname
            succeeds if __xstat fails because the name does not exist.
            Note the continue to bypass the common logic at the bottom
            of the loop.  */
         if (__lxstat64 (_STAT_VER, tmpl, &st) < 0)
           {
             if (errno == ENOENT)
              {
                __set_errno (save_errno);
                return 0;
              }
             else
              /* Give up now. */
              return -1;
           }
         continue;

       default:
         assert (! "invalid KIND in __gen_tempname");
       }

      if (fd >= 0)
       {
         __set_errno (save_errno);
         return fd;
       }
      else if (errno != EEXIST)
       return -1;
    }

  /* We got out of the loop because we ran out of combinations to try.  */
  __set_errno (EEXIST);
  return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int __getc_unlocked ( FILE __fp)

Definition at line 34 of file getc_u.c.

{
  CHECK_FILE (fp, EOF);
  return _IO_getc_unlocked (fp);
}
_IO_ssize_t __getline ( char **  __lineptr,
size_t __n,
FILE __stream 
)

Definition at line 67 of file tst-rfc3484-2.c.

{
  *lineptr = NULL;
  *n = 0;
  return 0;
}

Definition at line 34 of file getwc_u.c.

{
  CHECK_FILE (fp, WEOF);
  return _IO_getwc_unlocked (fp);
}
int __isoc99_fscanf ( FILE *__restrict  __stream,
__const char *__restrict  __format,
  ... 
)
int __isoc99_scanf ( __const char *__restrict  __format,
  ... 
)
int __isoc99_sscanf ( __const char *__restrict  __s,
__const char *__restrict  __format,
  ... 
)
int __isoc99_vfscanf ( FILE *__restrict  __s,
__const char *__restrict  __format,
_G_va_list  __arg 
)

Here is the caller graph for this function:

int __isoc99_vscanf ( __const char *__restrict  __format,
_G_va_list  __arg 
)
int __isoc99_vsscanf ( __const char *__restrict  __s,
__const char *__restrict  __format,
_G_va_list  __arg 
)

Here is the caller graph for this function:

void __libc_fatal ( __const char *  __message)

Here is the caller graph for this function:

void __libc_message ( int  do_abort,
__const char *  __fnt,
  ... 
)

Here is the caller graph for this function:

int __obstack_printf_chk ( struct obstack ,
int  ,
const char *  ,
  ... 
)

Definition at line 5 of file nldbl-obstack_printf_chk.c.

{
  int result;
  va_list ap;
  va_start (ap, fmt);
  result = __nldbl___obstack_vprintf_chk (obstack, flag, fmt, ap);
  va_end (ap);
  return result;
}

Here is the call graph for this function:

int __obstack_vprintf_chk ( struct obstack ,
int  ,
const char *  ,
_G_va_list   
)
FILE* __old_tmpfile ( void  )
int __path_search ( char *  __tmpl,
size_t  __tmpl_len,
__const char *  __dir,
__const char *  __pfx,
int  __try_tempdir 
)

Here is the caller graph for this function:

int __printf_chk ( int  ,
const char *  ,
  ... 
)

Definition at line 5 of file nldbl-printf_chk.c.

{
  va_list arg;
  int done;

  va_start (arg, fmt);
  done = __nldbl___vfprintf_chk (stdout, flag, fmt, arg);
  va_end (arg);

  return done;
}

Here is the call graph for this function:

int __snprintf ( char *__restrict  __s,
size_t  __maxlen,
__const char *__restrict  __format,
  ... 
)

Here is the caller graph for this function:

int __snprintf_chk ( char *  ,
size_t  ,
int  ,
size_t  ,
const char *  ,
  ... 
)

Definition at line 5 of file nldbl-snprintf_chk.c.

{
  va_list arg;
  int done;

  va_start (arg, fmt);
  done = __nldbl___vsnprintf_chk (s, maxlen, flag, slen, fmt, arg);
  va_end (arg);

  return done;
}

Here is the call graph for this function:

int int __sprintf_chk ( char *  ,
int  ,
size_t  ,
const char *  ,
  ... 
)

Definition at line 5 of file nldbl-sprintf_chk.c.

{
  va_list arg;
  int done;

  va_start (arg, fmt);
  done = __nldbl___vsprintf_chk (s, flag, slen, fmt, arg);
  va_end (arg);

  return done;
}

Here is the call graph for this function:

int __vasprintf_chk ( char **  ,
int  ,
const char *  ,
_G_va_list   
)
int __vdprintf_chk ( int  ,
int  ,
const char *  ,
_G_va_list   
)
int __vfprintf_chk ( FILE ,
int  ,
const char *  ,
_G_va_list   
)

Here is the caller graph for this function:

int int int __vfscanf ( FILE *__restrict  __s,
__const char *__restrict  __format,
_G_va_list  __arg 
)

Here is the caller graph for this function:

int __vprintf_chk ( int  ,
const char *  ,
_G_va_list   
)
int int __vsnprintf ( char *__restrict  __s,
size_t  __maxlen,
__const char *__restrict  __format,
_G_va_list  __arg 
)

Here is the caller graph for this function:

int __vsnprintf_chk ( char *  ,
size_t  ,
int  ,
size_t  ,
const char *  ,
_G_va_list   
)

Here is the caller graph for this function:

int __vsprintf_chk ( char *  ,
int  ,
size_t  ,
const char *  ,
_G_va_list   
)

Here is the caller graph for this function:

int __vsscanf ( __const char *__restrict  __s,
__const char *__restrict  __format,
_G_va_list  __arg 
)
int _IO_fputs ( const char *  ,
_IO_FILE  
)

Definition at line 41 of file iofclose.c.

{
  int status;

  CHECK_FILE(fp, EOF);

#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
  /* We desperately try to help programs which are using streams in a
     strange way and mix old and new functions.  Detect old streams
     here.  */
  if (_IO_vtable_offset (fp) != 0)
    return _IO_old_fclose (fp);
#endif

  /* First unlink the stream.  */
  if (fp->_IO_file_flags & _IO_IS_FILEBUF)
    INTUSE(_IO_un_link) ((struct _IO_FILE_plus *) fp);

  _IO_acquire_lock (fp);
  if (fp->_IO_file_flags & _IO_IS_FILEBUF)
    status = INTUSE(_IO_file_close_it) (fp);
  else
    status = fp->_flags & _IO_ERR_SEEN ? -1 : 0;
  _IO_release_lock (fp);
  _IO_FINISH (fp);
  if (fp->_mode > 0)
    {
#if _LIBC
      /* This stream has a wide orientation.  This means we have to free
        the conversion functions.  */
      struct _IO_codecvt *cc = fp->_codecvt;

      __libc_lock_lock (__gconv_lock);
      __gconv_release_step (cc->__cd_in.__cd.__steps);
      __gconv_release_step (cc->__cd_out.__cd.__steps);
      __libc_lock_unlock (__gconv_lock);
#endif
    }
  else
    {
      if (_IO_have_backup (fp))
       INTUSE(_IO_free_backup_area) (fp);
    }
  if (fp != _IO_stdin && fp != _IO_stdout && fp != _IO_stderr)
    {
      fp->_IO_file_flags = 0;
      free(fp);
    }

  return status;
}
_IO_FILE* _IO_new_fdopen ( int  ,
const char *   
)

Definition at line 48 of file iofdopen.c.

{
  int read_write;
  int posix_mode = 0;
  struct locked_FILE
  {
    struct _IO_FILE_plus fp;
#ifdef _IO_MTSAFE_IO
    _IO_lock_t lock;
#endif
    struct _IO_wide_data wd;
  } *new_f;
  int fd_flags;
  int i;
  int use_mmap = 0;

  switch (*mode)
    {
    case 'r':
      read_write = _IO_NO_WRITES;
      break;
    case 'w':
      read_write = _IO_NO_READS;
      break;
    case 'a':
      posix_mode = O_APPEND;
      read_write = _IO_NO_READS|_IO_IS_APPENDING;
      break;
    default:
      MAYBE_SET_EINVAL;
      return NULL;
  }
  for (i = 1; i < 5; ++i)
    {
      switch (*++mode)
       {
       case '\0':
         break;
       case '+':
         read_write &= _IO_IS_APPENDING;
         break;
       case 'm':
         use_mmap = 1;
         continue;
       case 'x':
       case 'b':
       default:
         /* Ignore */
         continue;
       }
      break;
    }
#ifdef F_GETFL
  fd_flags = _IO_fcntl (fd, F_GETFL);
#ifndef O_ACCMODE
#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
#endif
  if (fd_flags == -1)
    return NULL;

  if (((fd_flags & O_ACCMODE) == O_RDONLY && !(read_write & _IO_NO_WRITES))
      || ((fd_flags & O_ACCMODE) == O_WRONLY && !(read_write & _IO_NO_READS)))
    {
      MAYBE_SET_EINVAL;
      return NULL;
    }

  /* The May 93 draft of P1003.4/D14.1 (redesignated as 1003.1b)
     [System Application Program Interface (API) Amendment 1:
     Realtime Extensions], Rationale B.8.3.3
     Open a Stream on a File Descriptor says:

         Although not explicitly required by POSIX.1, a good
         implementation of append ("a") mode would cause the
         O_APPEND flag to be set.

     (Historical implementations [such as Solaris2] do a one-time
     seek in fdopen.)

     However, we do not turn O_APPEND off if the mode is "w" (even
     though that would seem consistent) because that would be more
     likely to break historical programs.
     */
  if ((posix_mode & O_APPEND) && !(fd_flags & O_APPEND))
    {
#ifdef F_SETFL
      if (_IO_fcntl (fd, F_SETFL, fd_flags | O_APPEND) == -1)
#endif
       return NULL;
    }
#endif

  new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE));
  if (new_f == NULL)
    return NULL;
#ifdef _IO_MTSAFE_IO
  new_f->fp.file._lock = &new_f->lock;
#endif
  /* Set up initially to use the `maybe_mmap' jump tables rather than using
     __fopen_maybe_mmap to do it, because we need them in place before we
     call _IO_file_attach or else it will allocate a buffer immediately.  */
  _IO_no_init (&new_f->fp.file, 0, 0, &new_f->wd,
#ifdef _G_HAVE_MMAP
              (use_mmap && (read_write & _IO_NO_WRITES))
              ? &_IO_wfile_jumps_maybe_mmap :
#endif
              &_IO_wfile_jumps);
  _IO_JUMPS (&new_f->fp) =
#ifdef _G_HAVE_MMAP
    (use_mmap && (read_write & _IO_NO_WRITES)) ? &_IO_file_jumps_maybe_mmap :
#endif
      &_IO_file_jumps;
  INTUSE(_IO_file_init) (&new_f->fp);
#if  !_IO_UNIFIED_JUMPTABLES
  new_f->fp.vtable = NULL;
#endif
  if (INTUSE(_IO_file_attach) ((_IO_FILE *) &new_f->fp, fd) == NULL)
    {
      INTUSE(_IO_setb) (&new_f->fp.file, NULL, NULL, 0);
      INTUSE(_IO_un_link) (&new_f->fp);
      free (new_f);
      return NULL;
    }
  new_f->fp.file._flags &= ~_IO_DELETE_DONT_CLOSE;

  new_f->fp.file._IO_file_flags =
    _IO_mask_flags (&new_f->fp.file, read_write,
                  _IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING);

  return &new_f->fp.file;
}

Definition at line 35 of file iofgetpos.c.

{
  _IO_off64_t pos;
  int result = 0;
  CHECK_FILE (fp, EOF);
  _IO_acquire_lock (fp);
  pos = _IO_seekoff_unlocked (fp, 0, _IO_seek_cur, 0);
  if (_IO_in_backup (fp) && pos != _IO_pos_BAD)
    {
      if (fp->_mode <= 0)
       pos -= fp->_IO_save_end - fp->_IO_save_base;
    }
  if (pos == _IO_pos_BAD)
    {
      /* ANSI explicitly requires setting errno to a positive value on
        failure.  */
#ifdef EIO
      if (errno == 0)
       __set_errno (EIO);
#endif
      result = EOF;
    }
  else if ((_IO_off64_t) (__typeof (posp->__pos)) pos != pos)
    {
#ifdef EOVERFLOW
      __set_errno (EOVERFLOW);
#endif
      result = EOF;
    }
  else
    {
      posp->__pos = pos;
      if (fp->_mode > 0
         && (*fp->_codecvt->__codecvt_do_encoding) (fp->_codecvt) < 0)
       /* This is a stateful encoding, safe the state.  */
       posp->__state = fp->_wide_data->_IO_state;
    }

  _IO_release_lock (fp);
  return result;
}
_IO_FILE* _IO_new_fopen ( const char *  ,
const char *   
)

Variable Documentation

Definition at line 113 of file stdio.h.