2018-02-21 Zack Weinberg <zackw@panix.com>
+ * libio/libio.h (_IO_pos_BAD, _IO_pos_0, _IO_pos_adjust):
+ Define here, unconditionally.
+ * libio/iolibio.h (_IO_pos_BAD): Don't define here.
+ * libio/libioP.h: Remove #if 0 blocks.
+ (_IO_pos_BAD, _IO_pos_0, _IO_pos_adjust): Don't define here.
+ (_IO_va_start, COERCE_FILE, MAYBE_SET_EINVAL): Don't define.
+ (CHECK_FILE): Don't use MAYBE_SET_EINVAL or COERCE_FILE. Fix style.
+
+ * libio/clearerr.c, libio/fputc.c, libio/getchar.c:
+ Assume weak_alias is always defined.
+
+ * libio/fileops.c, libio/genops.c, libio/oldfileops.c
+ * libio/oldpclose.c, libio/pclose.c, libio/wfileops.c:
+ Remove #if 0 and #ifdef TODO blocks.
+ Assume text_set_element is always defined.
+
+ * libio/iofdopen.c, libio/iogetdelim.c, libio/oldiofdopen.c
+ Use __set_errno (EINVAL) instead of MAYBE_SET_EINVAL.
+ * libio/tst-mmap-eofsync.c: Make #if 1 block unconditional.
+
* libio/libio.h (_IOS_ATEND, _IOS_APPEND, _IOS_TRUNC)
(_IOS_NOCREATE, _IOS_NOREPLACE, _IOS_BIN, _OLD_STDIO_MAGIC)
(_IO_SKIPWS, _IO_LEFT, _IO_RIGHT, _IO_INTERNAL, _IO_DEC)
_IO_funlockfile (fp);
}
-#if defined weak_alias && !defined _IO_MTSAFE_IO
+#ifndef _IO_MTSAFE_IO
weak_alias (clearerr, clearerr_unlocked)
#endif
_IO_doallocbuf (fp);
}
- /* Flush all line buffered files before reading. */
/* FIXME This can/should be moved to genops ?? */
if (fp->_flags & (_IO_LINE_BUF|_IO_UNBUFFERED))
{
-#if 0
- _IO_flush_all_linebuffered ();
-#else
/* We used to flush all line-buffered stream. This really isn't
required by any standard. My recollection is that
traditional Unix systems did this for stdout. stderr better
_IO_OVERFLOW (_IO_stdout, EOF);
_IO_release_lock (_IO_stdout);
-#endif
}
_IO_switch_to_get_mode (fp);
delta = fp->_IO_read_ptr - fp->_IO_read_end;
if (delta != 0)
{
-#ifdef TODO
- if (_IO_in_backup (fp))
- delta -= eGptr () - Gbase ();
-#endif
off64_t new_pos = _IO_SYSSEEK (fp, delta, 1);
if (new_pos != (off64_t) EOF)
fp->_IO_read_end = fp->_IO_read_ptr;
{
if (fp->_IO_read_ptr != fp->_IO_read_end)
{
-#ifdef TODO
- if (_IO_in_backup (fp))
- delta -= eGptr () - Gbase ();
-#endif
if (__lseek64 (fp->_fileno, fp->_IO_read_ptr - fp->_IO_buf_base,
SEEK_SET)
!= fp->_IO_read_ptr - fp->_IO_buf_base)
return result;
}
-#if defined weak_alias && !defined _IO_MTSAFE_IO
+#ifndef _IO_MTSAFE_IO
#undef fputc_unlocked
weak_alias (fputc, fputc_unlocked)
#endif
}
libc_hidden_def (_IO_free_backup_area)
-#if 0
-int
-_IO_switch_to_put_mode (FILE *fp)
-{
- fp->_IO_write_base = fp->_IO_read_ptr;
- fp->_IO_write_ptr = fp->_IO_read_ptr;
- /* Following is wrong if line- or un-buffered? */
- fp->_IO_write_end = (fp->_flags & _IO_IN_BACKUP
- ? fp->_IO_read_end : fp->_IO_buf_end);
-
- fp->_IO_read_ptr = fp->_IO_read_end;
- fp->_IO_read_base = fp->_IO_read_end;
-
- fp->_flags |= _IO_CURRENTLY_PUTTING;
- return 0;
-}
-#endif
-
int
__overflow (FILE *f, int ch)
{
}
libc_hidden_def (_IO_default_xsgetn)
-#if 0
-/* Seems not to be needed. --drepper */
-int
-_IO_sync (FILE *fp)
-{
- return 0;
-}
-#endif
-
FILE *
_IO_default_setbuf (FILE *fp, char *p, ssize_t len)
{
return result;
}
-#if 0 /* Work in progress */
-/* Seems not to be needed. */
-#if 0
-void
-_IO_set_column (FILE *fp, int c)
-{
- if (c == -1)
- fp->_column = -1;
- else
- fp->_column = c - (fp->_IO_write_ptr - fp->_IO_write_base);
-}
-#else
-int
-_IO_set_column (FILE *fp, int i)
-{
- fp->_cur_column = i + 1;
- return 0;
-}
-#endif
-#endif
-
-
unsigned
_IO_adjust_column (unsigned start, const char *line, int count)
{
}
libc_hidden_def (_IO_adjust_column)
-#if 0
-/* Seems not to be needed. --drepper */
-int
-_IO_get_column (FILE *fp)
-{
- if (fp->_cur_column)
- return _IO_adjust_column (fp->_cur_column - 1,
- fp->_IO_write_base,
- fp->_IO_write_ptr - fp->_IO_write_base);
- return -1;
-}
-#endif
-
-
int
_IO_flush_all_lockp (int do_lock)
{
return;
}
}
-#if 0
- if _sbuf has a backup area that is no longer needed, should we delete
- it now, or wait until the next underflow?
-#endif
+ /* FIXME: if _sbuf has a backup area that is no longer needed,
+ should we delete it now, or wait until the next underflow? */
}
#define BAD_DELTA EOF
struct _IO_marker *mark = fp->_markers;
if (mark)
{
-#ifdef TODO
- streampos offset = seekoff (0, ios::cur, ios::in);
- if (offset != EOF)
- {
- offset += eGptr () - Gbase ();
- for ( ; mark != NULL; mark = mark->_next)
- mark->set_streampos (mark->_pos + offset);
- }
- else
- {
- for ( ; mark != NULL; mark = mark->_next)
- mark->set_streampos (EOF);
- }
-#endif
fp->_markers = 0;
}
}
libc_hidden_def (_IO_unsave_markers)
-#if 0
-/* Seems not to be needed. --drepper */
-int
-_IO_nobackup_pbackfail (FILE *fp, int c)
-{
- if (fp->_IO_read_ptr > fp->_IO_read_base)
- fp->_IO_read_ptr--;
- if (c != EOF && *fp->_IO_read_ptr != c)
- *fp->_IO_read_ptr = c;
- return (unsigned char) c;
-}
-#endif
-
int
_IO_default_pbackfail (FILE *fp, int c)
{
}
libc_hidden_def (_IO_list_resetlock)
-
-#ifdef TODO
-#if defined(linux)
-#define IO_CLEANUP ;
-#endif
-
-#ifdef IO_CLEANUP
- IO_CLEANUP
-#else
-struct __io_defs {
- __io_defs() { }
- ~__io_defs() { _IO_cleanup (); }
-};
-__io_defs io_defs__;
-#endif
-
-#endif /* TODO */
-
-#ifdef text_set_element
text_set_element(__libc_atexit, _IO_cleanup);
-#endif
return result;
}
-#if defined weak_alias && !defined _IO_MTSAFE_IO
+#ifndef _IO_MTSAFE_IO
#undef getchar_unlocked
weak_alias (getchar, getchar_unlocked)
#endif
read_write = _IO_NO_READS|_IO_IS_APPENDING;
break;
default:
- MAYBE_SET_EINVAL;
+ __set_errno (EINVAL);
return NULL;
}
for (i = 1; i < 5; ++i)
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;
+ __set_errno (EINVAL);
return NULL;
}
if (lineptr == NULL || n == NULL)
{
- MAYBE_SET_EINVAL;
+ __set_errno (EINVAL);
return -1;
}
CHECK_FILE (fp, -1);
extern int _IO_obstack_vprintf (struct obstack *, const char *, __gnuc_va_list)
__THROW;
extern int _IO_obstack_printf (struct obstack *, const char *, ...) __THROW;
-#ifndef _IO_pos_BAD
-#define _IO_pos_BAD ((off64_t)(-1))
-#endif
#define _IO_clearerr(FP) ((FP)->_flags &= ~(_IO_ERR_SEEN|_IO_EOF_SEEN))
#define _IO_fseek(__fp, __offset, __whence) \
(_IO_seekoff_unlocked (__fp, __offset, __whence, _IOS_INPUT|_IOS_OUTPUT) \
#define _IO_FLAGS2_CLOEXEC 64
#define _IO_FLAGS2_NEED_LOCK 128
+/* _IO_pos_BAD is an off64_t value indicating error, unknown, or EOF. */
+#define _IO_pos_BAD ((off64_t) -1)
+
+/* _IO_pos_adjust adjusts an off64_t by some number of bytes. */
+#define _IO_pos_adjust(pos, delta) ((pos) += (delta))
+
+/* _IO_pos_0 is an off64_t value indicating beginning of file. */
+#define _IO_pos_0 ((off64_t) 0)
struct _IO_jump_t;
JUMP_FIELD(_IO_stat_t, __stat);
JUMP_FIELD(_IO_showmanyc_t, __showmanyc);
JUMP_FIELD(_IO_imbue_t, __imbue);
-#if 0
- get_column;
- set_column;
-#endif
};
/* We always allocate an extra word following an _IO_FILE.
extern int _IO_vscanf (const char *, va_list) __THROW;
-/* _IO_pos_BAD is an off64_t value indicating error, unknown, or EOF. */
-#ifndef _IO_pos_BAD
-# define _IO_pos_BAD ((off64_t) -1)
-#endif
-/* _IO_pos_adjust adjust an off64_t by some number of bytes. */
-#ifndef _IO_pos_adjust
-# define _IO_pos_adjust(pos, delta) ((pos) += (delta))
-#endif
-/* _IO_pos_0 is an off64_t value indicating beginning of file. */
-#ifndef _IO_pos_0
-# define _IO_pos_0 ((off64_t) 0)
-#endif
-
#ifdef _IO_MTSAFE_IO
/* check following! */
# ifdef _IO_USE_OLD_IO_FILE
# endif
#endif
-#define _IO_va_start(args, last) va_start(args, last)
-
extern struct _IO_fake_stdiobuf _IO_stdin_buf, _IO_stdout_buf, _IO_stderr_buf;
-#if 1
-# define COERCE_FILE(FILE) /* Nothing */
-#else
-/* This is part of the kludge for binary compatibility with old stdio. */
-# define COERCE_FILE(FILE) \
- (((FILE)->_flags & _IO_MAGIC_MASK) == _OLD_MAGIC_MASK \
- && (FILE) = *(FILE**)&((int*)fp)[1])
-#endif
-
-#ifdef EINVAL
-# define MAYBE_SET_EINVAL __set_errno (EINVAL)
-#else
-# define MAYBE_SET_EINVAL /* nothing */
-#endif
-
#ifdef IO_DEBUG
-# define CHECK_FILE(FILE, RET) \
- if ((FILE) == NULL) { MAYBE_SET_EINVAL; return RET; } \
- else { COERCE_FILE(FILE); \
- if (((FILE)->_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
- { MAYBE_SET_EINVAL; return RET; }}
+# define CHECK_FILE(FILE, RET) do { \
+ if ((FILE) == NULL || \
+ ((FILE)->_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
+ { \
+ __set_errno (EINVAL); \
+ return RET; \
+ } \
+ } while (0)
#else
-# define CHECK_FILE(FILE, RET) COERCE_FILE (FILE)
+# define CHECK_FILE(FILE, RET) do { } while (0)
#endif
static inline void
+ (fp->_IO_read_end - fp->_IO_read_base));
if (rel_offset >= 0)
{
-#if 0
- if (_IO_in_backup (fp))
- _IO_switch_to_main_get_area (fp);
-#endif
if (rel_offset <= fp->_IO_read_end - fp->_IO_read_base)
{
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base + rel_offset,
read_write = _IO_NO_READS|_IO_IS_APPENDING;
break;
default:
- MAYBE_SET_EINVAL;
+ __set_errno (EINVAL);
return NULL;
}
if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+'))
#include "stdio.h"
#include <errno.h>
+/* POSIX does not require us to check that a stream passed to pclose()
+ was created by popen(). Instead we rely on _IO_SYSCLOSE to call
+ _proc_close when appropriate. */
int
attribute_compat_text_section
__old_pclose (FILE *fp)
{
-#if 0
- /* Does not actually test that stream was created by popen(). Instead,
- it depends on the filebuf::sys_close() virtual to Do The Right Thing. */
- if (fp is not a proc_file)
- return -1;
-#endif
return _IO_old_fclose (fp);
}
#include <errno.h>
#include <shlib-compat.h>
+/* POSIX does not require us to check that a stream passed to pclose()
+ was created by popen(). Instead we rely on _IO_SYSCLOSE to call
+ _proc_close when appropriate. */
int
__new_pclose (FILE *fp)
{
-#if 0
- /* Does not actually test that stream was created by popen(). Instead,
- it depends on the filebuf::sys_close() virtual to Do The Right Thing. */
- if (fp is not a proc_file)
- return -1;
-#endif
return _IO_new_fclose (fp);
}
printf ("feof = %d, ferror = %d immediately after fgets\n",
feof (f), ferror (f));
-#if 1
c = fgetc (f);
if (c == EOF)
printf ("fgetc -> EOF (feof = %d, ferror = %d)\n",
c, feof (f), ferror (f));
result = 1;
}
-#endif
c = write (temp_fd, text2, sizeof text2 - 1);
if (c == sizeof text2 - 1)
_IO_wdoallocbuf (fp);
}
- /* Flush all line buffered files before reading. */
/* FIXME This can/should be moved to genops ?? */
if (fp->_flags & (_IO_LINE_BUF | _IO_UNBUFFERED))
{
-#if 0
- _IO_flush_all_linebuffered ();
-#else
/* We used to flush all line-buffered stream. This really isn't
required by any standard. My recollection is that
traditional Unix systems did this for stdout. stderr better
_IO_OVERFLOW (_IO_stdout, EOF);
_IO_release_lock (_IO_stdout);
-#endif
}
_IO_switch_to_get_mode (fp);
}
libc_hidden_def (_IO_free_wbackup_area)
-#if 0
-int
-_IO_switch_to_wput_mode (FILE *fp)
-{
- fp->_wide_data->_IO_write_base = fp->_wide_data->_IO_read_ptr;
- fp->_wide_data->_IO_write_ptr = fp->_wide_data->_IO_read_ptr;
- /* Following is wrong if line- or un-buffered? */
- fp->_wide_data->_IO_write_end = (fp->_flags & _IO_IN_BACKUP
- ? fp->_wide_data->_IO_read_end
- : fp->_wide_data->_IO_buf_end);
-
- fp->_wide_data->_IO_read_ptr = fp->_wide_data->_IO_read_end;
- fp->_wide_data->_IO_read_base = fp->_wide_data->_IO_read_end;
-
- fp->_flags |= _IO_CURRENTLY_PUTTING;
- return 0;
-}
-#endif
-
-
static int
save_for_wbackup (FILE *fp, wchar_t *end_p)
{
struct _IO_marker *mark = fp->_markers;
if (mark)
{
-#ifdef TODO
- streampos offset = seekoff (0, ios::cur, ios::in);
- if (offset != EOF)
- {
- offset += eGptr () - Gbase ();
- for ( ; mark != NULL; mark = mark->_next)
- mark->set_streampos (mark->_pos + offset);
- }
- else
- {
- for ( ; mark != NULL; mark = mark->_next)
- mark->set_streampos (EOF);
- }
-#endif
fp->_markers = 0;
}
} \
if (Format == NULL) \
{ \
- MAYBE_SET_EINVAL; \
+ __set_errno (EINVAL); \
return -1; \
} \
} while (0)
} \
else if (format == NULL) \
{ \
- MAYBE_SET_EINVAL; \
+ __set_errno (EINVAL); \
return EOF; \
} \
} while (0)