예제 #1
0
파일: iofsetpos.c 프로젝트: bminor/glibc
int
_IO_new_fsetpos (FILE *fp, const __fpos_t *posp)
{
  int result;
  CHECK_FILE (fp, EOF);
  _IO_acquire_lock (fp);
  if (_IO_seekpos_unlocked (fp, posp->__pos, _IOS_INPUT|_IOS_OUTPUT)
      == _IO_pos_BAD)
    {
      /* ANSI explicitly requires setting errno to a positive value on
	 failure.  */
      if (errno == 0)
	__set_errno (EIO);
      result = EOF;
    }
  else
    {
      result = 0;
      if (fp->_mode > 0 && __libio_codecvt_encoding (fp->_codecvt) < 0)
	/* This is a stateful encoding, restore the state.  */
	fp->_wide_data->_IO_state = posp->__state;
    }
  _IO_release_lock (fp);
  return result;
}
예제 #2
0
char *
__fgets_chk (char *buf, size_t size, int n, _IO_FILE *fp)
{
  _IO_size_t count;
  char *result;
  CHECK_FILE (fp, NULL);
  if (n <= 0)
    return NULL;
  _IO_acquire_lock (fp);
  /* This is very tricky since a file descriptor may be in the
     non-blocking mode. The error flag doesn't mean much in this
     case. We return an error only when there is a new error. */
  int old_error = fp->_IO_file_flags & _IO_ERR_SEEN;
  fp->_IO_file_flags &= ~_IO_ERR_SEEN;
  count = _IO_getline (fp, buf, MIN ((size_t) n - 1, size), '\n', 1);
  /* If we read in some bytes and errno is EAGAIN, that error will
     be reported for next read. */
  if (count == 0 || ((fp->_IO_file_flags & _IO_ERR_SEEN)
		     && errno != EAGAIN))
    result = NULL;
  else if (count >= size)
    __chk_fail ();
  else
    {
      buf[count] = '\0';
      result = buf;
    }
  fp->_IO_file_flags |= old_error;
  _IO_release_lock (fp);
  return result;
}
예제 #3
0
long int
_IO_ftell (_IO_FILE *fp)
{
    _IO_off64_t pos;
    CHECK_FILE (fp, -1L);
    _IO_acquire_lock (fp);
    pos = _IO_seekoff_unlocked (fp, 0, _IO_seek_cur, 0);
    if (_IO_in_backup (fp) && pos != _IO_pos_BAD)
    {
        if (_IO_vtable_offset (fp) != 0 || fp->_mode <= 0)
            pos -= fp->_IO_save_end - fp->_IO_save_base;
    }
    _IO_release_lock (fp);
    if (pos == _IO_pos_BAD)
    {
#ifdef EIO
        if (errno == 0)
            __set_errno (EIO);
#endif
        return -1L;
    }
    if ((_IO_off64_t) (long int) pos != pos)
    {
#ifdef EOVERFLOW
        __set_errno (EOVERFLOW);
#endif
        return -1L;
    }
    return pos;
}
예제 #4
0
파일: iofgetpos64.c 프로젝트: bminor/glibc
int
_IO_new_fgetpos64 (FILE *fp, __fpos64_t *posp)
{
  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.  */
      if (errno == 0)
	__set_errno (EIO);
      result = EOF;
    }
  else
    {
      posp->__pos = pos;
      if (fp->_mode > 0 && __libio_codecvt_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;
}
예제 #5
0
int
attribute_compat_text_section
_IO_old_fclose (_IO_FILE *fp)
{
  int status;

  CHECK_FILE(fp, EOF);

  /* We desperately try to help programs which are using streams in a
     strange way and mix old and new functions.  Detect new streams
     here.  */
  if (fp->_vtable_offset == 0)
    return _IO_new_fclose (fp);

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

  _IO_acquire_lock (fp);
  if (fp->_IO_file_flags & _IO_IS_FILEBUF)
    status = _IO_old_file_close_it (fp);
  else
    status = fp->_flags & _IO_ERR_SEEN ? -1 : 0;
  _IO_release_lock (fp);
  _IO_FINISH (fp);
  if (_IO_have_backup (fp))
    _IO_free_backup_area (fp);
  if (fp != _IO_stdin && fp != _IO_stdout && fp != _IO_stderr)
    {
      fp->_IO_file_flags = 0;
      free(fp);
    }

  return status;
}
예제 #6
0
int
getchar (void)
{
  int result;
  _IO_acquire_lock (_IO_stdin);
  result = _IO_getc_unlocked (_IO_stdin);
  _IO_release_lock (_IO_stdin);
  return result;
}
예제 #7
0
파일: putwc.c 프로젝트: bminor/glibc
wint_t
putwc (wchar_t wc, FILE *fp)
{
  wint_t result;
  CHECK_FILE (fp, WEOF);
  _IO_acquire_lock (fp);
  result = _IO_putwc_unlocked (wc, fp);
  _IO_release_lock (fp);
  return result;
}
예제 #8
0
파일: fseeko.c 프로젝트: RobbenBasten/glibc
int
fseeko (_IO_FILE *fp, off_t offset, int whence)
{
  int result;
  CHECK_FILE (fp, -1);
  _IO_acquire_lock (fp);
  result = _IO_fseek (fp, offset, whence);
  _IO_release_lock (fp);
  return result;
}
예제 #9
0
_IO_off64_t
_IO_seekpos (_IO_FILE *fp, _IO_off64_t pos, int mode)
{
  _IO_off64_t retval;

  _IO_acquire_lock (fp);
  retval = _IO_seekpos_unlocked (fp, pos, mode);
  _IO_release_lock (fp);
  return retval;
}
예제 #10
0
wint_t
_IO_getwc (FILE *fp)
{
  wint_t result;
  CHECK_FILE (fp, WEOF);
  _IO_acquire_lock (fp);
  result = _IO_getwc_unlocked (fp);
  _IO_release_lock (fp);
  return result;
}
예제 #11
0
int
_IO_getc (FILE *fp)
{
    int result;
    CHECK_FILE (fp, EOF);
    _IO_acquire_lock (fp);
    result = _IO_getc_unlocked (fp);
    _IO_release_lock (fp);
    return result;
}
예제 #12
0
파일: fputc.c 프로젝트: RobbenBasten/glibc
int
fputc (int c, _IO_FILE *fp)
{
  int result;
  CHECK_FILE (fp, EOF);
  _IO_acquire_lock (fp);
  result = _IO_putc_unlocked (c, fp);
  _IO_release_lock (fp);
  return result;
}
예제 #13
0
/* VARARGS2 */
int
__isoc99_vfscanf (FILE *stream, const char *format, _IO_va_list args)
{
  int done;

  _IO_acquire_lock_clear_flags2 (stream);
  stream->_flags2 |= _IO_FLAGS2_SCANF_STD;
  done = _IO_vfscanf (stream, format, args, NULL);
  _IO_release_lock (stream);
  return done;
}
예제 #14
0
/* VARARGS2 */
int
__isoc99_vwscanf (const wchar_t *format, _IO_va_list args)
{
  int done;

  _IO_acquire_lock_clear_flags2 (stdin);
  stdin->_flags2 |= _IO_FLAGS2_SCANF_STD;
  done = _IO_vfwscanf (stdin, format, args, NULL);
  _IO_release_lock (stdin);
  return done;
}
예제 #15
0
int
_IO_new_fclose (_IO_FILE *fp)
{
  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)
    _IO_un_link ((struct _IO_FILE_plus *) fp);

  _IO_acquire_lock (fp);
  if (fp->_IO_file_flags & _IO_IS_FILEBUF)
    status = _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))
	_IO_free_backup_area (fp);
    }
  if (fp != _IO_stdin && fp != _IO_stdout && fp != _IO_stderr)
    {
      fp->_IO_file_flags = 0;
      free(fp);
    }

  return status;
}
예제 #16
0
파일: iofputs.c 프로젝트: siddhesh/glibc
int
_IO_fputs (const char *str, _IO_FILE *fp)
{
  _IO_size_t len = strlen (str);
  int result = EOF;
  CHECK_FILE (fp, EOF);
  _IO_acquire_lock (fp);
  if ((_IO_vtable_offset (fp) != 0 || _IO_fwide (fp, -1) == -1)
      && _IO_sputn (fp, str, len) == len)
    result = 1;
  _IO_release_lock (fp);
  return result;
}
예제 #17
0
int
_IO_ungetc (int c, _IO_FILE *fp)
{
  int result;
  CHECK_FILE (fp, EOF);
  if (c == EOF)
    return EOF;
  if (!_IO_need_lock (fp))
    return _IO_sputbackc (fp, (unsigned char) c);
  _IO_acquire_lock (fp);
  result = _IO_sputbackc (fp, (unsigned char) c);
  _IO_release_lock (fp);
  return result;
}
예제 #18
0
/* VARARGS2 */
int
__isoc99_fscanf (FILE *stream, const char *format, ...)
{
  va_list arg;
  int done;

  _IO_acquire_lock_clear_flags2 (stream);
  stream->_flags2 |= _IO_FLAGS2_SCANF_STD;

  va_start (arg, format);
  done = _IO_vfscanf (stream, format, arg, NULL);
  va_end (arg);

  _IO_release_lock (stream);
  return done;
}
예제 #19
0
/* VARARGS1 */
int
__isoc99_wscanf (const wchar_t *format, ...)
{
  va_list arg;
  int done;

  _IO_acquire_lock_clear_flags2 (stdin);
  stdin->_flags2 |= _IO_FLAGS2_SCANF_STD;

  va_start (arg, format);
  done = _IO_vfwscanf (stdin, format, arg, NULL);
  va_end (arg);

  _IO_release_lock (stdin);
  return done;
}
예제 #20
0
파일: vprintf_chk.c 프로젝트: lattera/glibc
/* Write formatted output to stdout from the format string FORMAT.  */
int
___vprintf_chk (int flag, const char *format, va_list ap)
{
  int done;

  _IO_acquire_lock_clear_flags2 (stdout);
  if (flag > 0)
    stdout->_flags2 |= _IO_FLAGS2_FORTIFY;

  done = vfprintf (stdout, format, ap);

  if (flag > 0)
    stdout->_flags2 &= ~_IO_FLAGS2_FORTIFY;
  _IO_release_lock (stdout);

  return done;
}
예제 #21
0
/* Write formatted output to FP from the format string FORMAT.  */
int
___vfprintf_chk (FILE *fp, int flag, const char *format, va_list ap)
{
  int done;

  _IO_acquire_lock_clear_flags2 (fp);
  if (flag > 0)
    fp->_flags2 |= _IO_FLAGS2_FORTIFY;

  done = vfprintf (fp, format, ap);

  if (flag > 0)
    fp->_flags2 &= ~_IO_FLAGS2_FORTIFY;
  _IO_release_lock (fp);

  return done;
}
예제 #22
0
파일: gets_chk.c 프로젝트: bminor/glibc
char *
__gets_chk (char *buf, size_t size)
{
  size_t count;
  int ch;
  char *retval;

  if (size == 0)
    __chk_fail ();

  _IO_acquire_lock (stdin);
  ch = _IO_getc_unlocked (stdin);
  if (ch == EOF)
    {
      retval = NULL;
      goto unlock_return;
    }
  if (ch == '\n')
    count = 0;
  else
    {
      /* This is very tricky since a file descriptor may be in the
	 non-blocking mode. The error flag doesn't mean much in this
	 case. We return an error only when there is a new error. */
      int old_error = stdin->_flags & _IO_ERR_SEEN;
      stdin->_flags &= ~_IO_ERR_SEEN;
      buf[0] = (char) ch;
      count = _IO_getline (stdin, buf + 1, size - 1, '\n', 0) + 1;
      if (stdin->_flags & _IO_ERR_SEEN)
	{
	  retval = NULL;
	  goto unlock_return;
	}
      else
	stdin->_flags |= old_error;
    }
  if (count >= size)
    __chk_fail ();
  buf[count] = 0;
  retval = buf;
unlock_return:
  _IO_release_lock (stdin);
  return retval;
}
예제 #23
0
파일: fwide.c 프로젝트: riscv/riscv-glibc
int
fwide (_IO_FILE *fp, int mode)
{
  int result;

  /* Normalize the value.  */
  mode = mode < 0 ? -1 : (mode == 0 ? 0 : 1);

  if (mode == 0 || fp->_mode != 0)
    /* The caller simply wants to know about the current orientation
       or the orientation already has been determined.  */
    return fp->_mode;

  _IO_acquire_lock (fp);
  result = _IO_fwide (fp, mode);
  _IO_release_lock (fp);

  return result;
}
예제 #24
0
int
_IO_new_fgetpos (_IO_FILE *fp, _IO_fpos_t *posp)
{
  _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;
}
예제 #25
0
/* VARARGS1 */
int
__isoc99_scanf (const char *format, ...)
{
  va_list arg;
  int done;

#ifdef _IO_MTSAFE_IO
  _IO_acquire_lock_clear_flags2 (stdin);
#endif
  stdin->_flags2 |= _IO_FLAGS2_SCANF_STD;

  va_start (arg, format);
  done = _IO_vfscanf (stdin, format, arg, NULL);
  va_end (arg);

#ifdef _IO_MTSAFE_IO
  _IO_release_lock (stdin);
#endif
  return done;
}
예제 #26
0
/* Write formatted output to FP from the format string FORMAT.  */
int
__fprintf_chk (FILE *fp, int flag, const char *format, ...)
{
  va_list ap;
  int done;

  _IO_acquire_lock (fp);
  if (flag > 0)
    fp->_flags2 |= _IO_FLAGS2_FORTIFY;

  va_start (ap, format);
  done = vfprintf (fp, format, ap);
  va_end (ap);

  if (flag > 0)
    fp->_flags2 &= ~_IO_FLAGS2_FORTIFY;
  _IO_release_lock (fp);

  return done;
}
예제 #27
0
/* Write formatted output to stdout from the format string FORMAT.  */
int
___printf_chk (int flag, const char *format, ...)
{
  va_list ap;
  int done;

  _IO_acquire_lock_clear_flags2 (stdout);
  if (flag > 0)
    stdout->_flags2 |= _IO_FLAGS2_FORTIFY;

  va_start (ap, format);
  done = vfprintf (stdout, format, ap);
  va_end (ap);

  if (flag > 0)
    stdout->_flags2 &= ~_IO_FLAGS2_FORTIFY;
  _IO_release_lock (stdout);

  return done;
}
예제 #28
0
_IO_size_t
_IO_fwrite (const void *buf, _IO_size_t size, _IO_size_t count, _IO_FILE *fp)
{
  _IO_size_t request = size * count;
  _IO_size_t written = 0;
  CHECK_FILE (fp, 0);
  if (request == 0)
    return 0;
  _IO_acquire_lock (fp);
  if (_IO_vtable_offset (fp) != 0 || _IO_fwide (fp, -1) == -1)
    written = _IO_sputn (fp, (const char *) buf, request);
  _IO_release_lock (fp);
  /* We have written all of the input in case the return value indicates
     this or EOF is returned.  The latter is a special case where we
     simply did not manage to flush the buffer.  But the data is in the
     buffer and therefore written as far as fwrite is concerned.  */
  if (written == request || written == EOF)
    return count;
  else
    return written / size;
}
예제 #29
0
char *
_IO_gets (char *buf)
{
  _IO_size_t count;
  int ch;
  char *retval;

  _IO_acquire_lock (_IO_stdin);
  ch = _IO_getc_unlocked (_IO_stdin);
  if (ch == EOF)
    {
      retval = NULL;
      goto unlock_return;
    }
  if (ch == '\n')
    count = 0;
  else
    {
      /* This is very tricky since a file descriptor may be in the
	 non-blocking mode. The error flag doesn't mean much in this
	 case. We return an error only when there is a new error. */
      int old_error = _IO_stdin->_IO_file_flags & _IO_ERR_SEEN;
      _IO_stdin->_IO_file_flags &= ~_IO_ERR_SEEN;
      buf[0] = (char) ch;
      count = _IO_getline (_IO_stdin, buf + 1, INT_MAX, '\n', 0) + 1;
      if (_IO_stdin->_IO_file_flags & _IO_ERR_SEEN)
	{
	  retval = NULL;
	  goto unlock_return;
	}
      else
	_IO_stdin->_IO_file_flags |= old_error;
    }
  buf[count] = 0;
  retval = buf;
unlock_return:
  _IO_release_lock (_IO_stdin);
  return retval;
}
예제 #30
0
파일: ftello64.c 프로젝트: siddhesh/glibc
off64_t
ftello64 (_IO_FILE *fp)
{
  _IO_off64_t pos;
  CHECK_FILE (fp, -1L);
  _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;
    }
  _IO_release_lock (fp);
  if (pos == _IO_pos_BAD)
    {
#ifdef EIO
      if (errno == 0)
	__set_errno (EIO);
#endif
      return -1L;
    }
  return pos;
}