Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
libio: Clean up _IO_file_doallocate and _IO_wfile_doallocate
No functional changes.
  • Loading branch information
Florian Weimer committed Mar 7, 2016
1 parent 3c0f740 commit abc40bb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 50 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
@@ -1,3 +1,11 @@
2016-03-07 Florian Weimer <fweimer@redhat.com>

* libio/filedoalloc.c (isatty): Remove.
(local_isatty): Add comment. Call __isatty directly.
(_IO_file_doallocate): Update comment. Assume _LIBC.
* libio/wfiledoalloc.c (isatty): Remove.
(_IO_wfile_doallocate): Update comment.

2016-03-07 Florian Weimer <fweimer@redhat.com> 2016-03-07 Florian Weimer <fweimer@redhat.com>


[BZ #19269] [BZ #19269]
Expand Down
36 changes: 5 additions & 31 deletions libio/filedoalloc.c
Expand Up @@ -55,57 +55,31 @@


/* Modified for GNU iostream by Per Bothner 1991, 1992. */ /* Modified for GNU iostream by Per Bothner 1991, 1992. */


#ifndef _POSIX_SOURCE
# define _POSIX_SOURCE
#endif
#include "libioP.h" #include "libioP.h"
#include <sys/types.h> #include <device-nrs.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>


#ifdef _LIBC /* Return the result of isatty, without changing errno. */
# undef isatty
# define isatty(Fd) __isatty (Fd)

# include <device-nrs.h>
#endif


static int static int
local_isatty (int fd) local_isatty (int fd)
{ {
int save_errno = errno; int save_errno = errno;
int res = isatty (fd); int res = __isatty (fd);
__set_errno (save_errno); __set_errno (save_errno);
return res; return res;
} }



/* Allocate a file buffer, or switch to unbuffered I/O. Streams for
/* TTY devices default to line buffered. */
* Allocate a file buffer, or switch to unbuffered I/O.
* Per the ANSI C standard, ALL tty devices default to line buffered.
*
* As a side effect, we set __SOPT or __SNPT (en/dis-able fseek
* optimisation) right after the _fstat() that finds the buffer size.
*/

int int
_IO_file_doallocate (_IO_FILE *fp) _IO_file_doallocate (_IO_FILE *fp)
{ {
_IO_size_t size; _IO_size_t size;
char *p; char *p;
struct stat64 st; struct stat64 st;


#ifndef _LIBC
/* If _IO_cleanup_registration_needed is non-zero, we should call the
function it points to. This is to make sure _IO_cleanup gets called
on exit. We call it from _IO_file_doallocate, since that is likely
to get called by any program that does buffered I/O. */
if (__glibc_unlikely (_IO_cleanup_registration_needed != NULL))
(*_IO_cleanup_registration_needed) ();
#endif

size = _IO_BUFSIZ; size = _IO_BUFSIZ;
if (fp->_fileno >= 0 && __builtin_expect (_IO_SYSSTAT (fp, &st), 0) >= 0) if (fp->_fileno >= 0 && __builtin_expect (_IO_SYSSTAT (fp, &st), 0) >= 0)
{ {
Expand Down
20 changes: 1 addition & 19 deletions libio/wfiledoalloc.c
Expand Up @@ -55,28 +55,10 @@


/* Modified for GNU iostream by Per Bothner 1991, 1992. */ /* Modified for GNU iostream by Per Bothner 1991, 1992. */


#ifndef _POSIX_SOURCE
# define _POSIX_SOURCE
#endif
#include "libioP.h" #include "libioP.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>

#ifdef _LIBC
# undef isatty
# define isatty(Fd) __isatty (Fd)
#endif

/*
* Allocate a file buffer, or switch to unbuffered I/O.
* Per the ANSI C standard, ALL tty devices default to line buffered.
*
* As a side effect, we set __SOPT or __SNPT (en/dis-able fseek
* optimisation) right after the _fstat() that finds the buffer size.
*/


/* Allocate a file buffer, or switch to unbuffered I/O. */
int int
_IO_wfile_doallocate (_IO_FILE *fp) _IO_wfile_doallocate (_IO_FILE *fp)
{ {
Expand Down

0 comments on commit abc40bb

Please sign in to comment.