This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 1/6 v2] Reformat libio files
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Richard Henderson <rth at twiddle dot net>
- Cc: libc-alpha at sourceware dot org
- Date: Mon, 3 Jun 2013 18:12:59 +0200
- Subject: Re: [PATCH 1/6 v2] Reformat libio files
- References: <1370099488-13916-1-git-send-email-neleai at seznam dot cz> <1370099488-13916-2-git-send-email-neleai at seznam dot cz> <51ACAD3E dot 7000409 at twiddle dot net>
On Mon, Jun 03, 2013 at 07:50:38AM -0700, Richard Henderson wrote:
> On 06/01/2013 08:11 AM, Ondrej Bilka wrote:
> > void
> > _IO_new_file_init (fp)
> > - struct _IO_FILE_plus *fp;
> > +struct _IO_FILE_plus *fp;
> > {
>
> The indentation was correct formatting for K&R C.
> If you change anything at all, move to ISO C:
>
> void
> _IO_new_file_init (struct _IO_FILE_plus *fp)
> {
>
I updated my formatter to handle this and other. Here is v2
Ondra
* libio/fileops.c: Reformat.
* libio/fmemopen.c: Likewise.
* libio/iofdopen.c: Likewise.
* libio/iofopen.c: Likewise.
---
libio/fileops.c | 428 +++++++++++++++++++++++-------------------------------
libio/fmemopen.c | 6 +-
libio/iofdopen.c | 36 +++--
libio/iofopen.c | 18 +--
4 files changed, 209 insertions(+), 279 deletions(-)
diff --git a/libio/fileops.c b/libio/fileops.c
index 61b61b3..f015211 100644
--- a/libio/fileops.c
+++ b/libio/fileops.c
@@ -130,15 +130,14 @@ extern struct __gconv_trans_data __libio_translit attribute_hidden;
UNBUFFERED STREAMS:
If a filebuf is unbuffered(), the _shortbuf[1] is used as the buffer.
-*/
+ */
-#define CLOSED_FILEBUF_FLAGS \
- (_IO_IS_FILEBUF+_IO_NO_READS+_IO_NO_WRITES+_IO_TIED_PUT_GET)
+#define CLOSED_FILEBUF_FLAGS \
+ (_IO_IS_FILEBUF + _IO_NO_READS + _IO_NO_WRITES + _IO_TIED_PUT_GET)
void
-_IO_new_file_init (fp)
- struct _IO_FILE_plus *fp;
+_IO_new_file_init (struct _IO_FILE_plus *fp)
{
/* POSIX.1 allows another file handle to be used to change the position
of our file descriptor. Hence we actually don't know the actual
@@ -152,8 +151,7 @@ _IO_new_file_init (fp)
libc_hidden_ver (_IO_new_file_init, _IO_file_init)
int
-_IO_new_file_close_it (fp)
- _IO_FILE *fp;
+_IO_new_file_close_it (_IO_FILE *fp)
{
int write_status;
if (!_IO_file_is_open (fp))
@@ -186,7 +184,7 @@ _IO_new_file_close_it (fp)
_IO_setp (fp, NULL, NULL);
_IO_un_link ((struct _IO_FILE_plus *) fp);
- fp->_flags = _IO_MAGIC|CLOSED_FILEBUF_FLAGS;
+ fp->_flags = _IO_MAGIC | CLOSED_FILEBUF_FLAGS;
fp->_fileno = -1;
fp->_offset = _IO_pos_BAD;
@@ -195,9 +193,7 @@ _IO_new_file_close_it (fp)
libc_hidden_ver (_IO_new_file_close_it, _IO_file_close_it)
void
-_IO_new_file_finish (fp, dummy)
- _IO_FILE *fp;
- int dummy;
+_IO_new_file_finish (_IO_FILE *fp, int dummy)
{
if (_IO_file_is_open (fp))
{
@@ -210,17 +206,13 @@ _IO_new_file_finish (fp, dummy)
libc_hidden_ver (_IO_new_file_finish, _IO_file_finish)
_IO_FILE *
-_IO_file_open (fp, filename, posix_mode, prot, read_write, is32not64)
- _IO_FILE *fp;
- const char *filename;
- int posix_mode;
- int prot;
- int read_write;
- int is32not64;
+_IO_file_open (_IO_FILE * fp, const char *filename, int posix_mode, int prot,
+ int read_write,
+ int is32not64)
{
int fdesc;
#ifdef _LIBC
- if (__builtin_expect (fp->_flags2 & _IO_FLAGS2_NOTCANCEL, 0))
+ if (__glibc_unlikely (fp->_flags2 & _IO_FLAGS2_NOTCANCEL))
fdesc = open_not_cancel (filename,
posix_mode | (is32not64 ? 0 : O_LARGEFILE), prot);
else
@@ -231,9 +223,11 @@ _IO_file_open (fp, filename, posix_mode, prot, read_write, is32not64)
if (fdesc < 0)
return NULL;
fp->_fileno = fdesc;
- _IO_mask_flags (fp, read_write,_IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING);
+ _IO_mask_flags (fp, read_write,
+ _IO_NO_READS + _IO_NO_WRITES + _IO_IS_APPENDING);
if ((read_write & _IO_IS_APPENDING) && (read_write & _IO_NO_READS))
- if (_IO_SEEKOFF (fp, (_IO_off64_t)0, _IO_seek_end, _IOS_INPUT|_IOS_OUTPUT)
+ if (_IO_SEEKOFF (fp, (_IO_off64_t) 0, _IO_seek_end, _IOS_INPUT |
+ _IOS_OUTPUT)
== _IO_pos_BAD && errno != ESPIPE)
{
close_not_cancel (fdesc);
@@ -245,11 +239,8 @@ _IO_file_open (fp, filename, posix_mode, prot, read_write, is32not64)
libc_hidden_def (_IO_file_open)
_IO_FILE *
-_IO_new_file_fopen (fp, filename, mode, is32not64)
- _IO_FILE *fp;
- const char *filename;
- const char *mode;
- int is32not64;
+_IO_new_file_fopen (_IO_FILE * fp, const char *filename, const char *mode,
+ int is32not64)
{
int oflags = 0, omode;
int read_write;
@@ -271,13 +262,13 @@ _IO_new_file_fopen (fp, filename, mode, is32not64)
break;
case 'w':
omode = O_WRONLY;
- oflags = O_CREAT|O_TRUNC;
+ oflags = O_CREAT | O_TRUNC;
read_write = _IO_NO_READS;
break;
case 'a':
omode = O_WRONLY;
- oflags = O_CREAT|O_APPEND;
- read_write = _IO_NO_READS|_IO_IS_APPENDING;
+ oflags = O_CREAT | O_APPEND;
+ read_write = _IO_NO_READS | _IO_IS_APPENDING;
break;
default:
__set_errno (EINVAL);
@@ -329,7 +320,7 @@ _IO_new_file_fopen (fp, filename, mode, is32not64)
break;
}
- result = _IO_file_open (fp, filename, omode|oflags, oprot, read_write,
+ result = _IO_file_open (fp, filename, omode | oflags, oprot, read_write,
is32not64);
if (result != NULL)
@@ -366,8 +357,8 @@ _IO_new_file_fopen (fp, filename, mode, is32not64)
? upstr (ccs, cs + 5) : ccs) != 0)
{
/* Something went wrong, we cannot load the conversion modules.
- This means we cannot proceed since the user explicitly asked
- for these. */
+ This means we cannot proceed since the user explicitly asked
+ for these. */
(void) _IO_file_close_it (fp);
__set_errno (EINVAL);
return NULL;
@@ -424,20 +415,18 @@ _IO_new_file_fopen (fp, filename, mode, is32not64)
libc_hidden_ver (_IO_new_file_fopen, _IO_file_fopen)
_IO_FILE *
-_IO_new_file_attach (fp, fd)
- _IO_FILE *fp;
- int fd;
+_IO_new_file_attach (_IO_FILE * fp, int fd)
{
if (_IO_file_is_open (fp))
return NULL;
fp->_fileno = fd;
- fp->_flags &= ~(_IO_NO_READS+_IO_NO_WRITES);
+ fp->_flags &= ~(_IO_NO_READS + _IO_NO_WRITES);
fp->_flags |= _IO_DELETE_DONT_CLOSE;
/* Get the current position of the file. */
/* We have to do that since that may be junk. */
fp->_offset = _IO_pos_BAD;
int save_errno = errno;
- if (_IO_SEEKOFF (fp, (_IO_off64_t)0, _IO_seek_cur, _IOS_INPUT|_IOS_OUTPUT)
+ if (_IO_SEEKOFF (fp, (_IO_off64_t) 0, _IO_seek_cur, _IOS_INPUT | _IOS_OUTPUT)
== _IO_pos_BAD && errno != ESPIPE)
return NULL;
__set_errno (save_errno);
@@ -446,16 +435,13 @@ _IO_new_file_attach (fp, fd)
libc_hidden_ver (_IO_new_file_attach, _IO_file_attach)
_IO_FILE *
-_IO_new_file_setbuf (fp, p, len)
- _IO_FILE *fp;
- char *p;
- _IO_ssize_t len;
+_IO_new_file_setbuf (_IO_FILE * fp, char *p, _IO_ssize_t len)
{
if (_IO_default_setbuf (fp, p, len) == NULL)
return NULL;
fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_write_end
- = fp->_IO_buf_base;
+ = fp->_IO_buf_base;
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
return fp;
@@ -464,10 +450,7 @@ libc_hidden_ver (_IO_new_file_setbuf, _IO_file_setbuf)
_IO_FILE *
-_IO_file_setbuf_mmap (fp, p, len)
- _IO_FILE *fp;
- char *p;
- _IO_ssize_t len;
+_IO_file_setbuf_mmap (_IO_FILE * fp, char *p, _IO_ssize_t len)
{
_IO_FILE *result;
@@ -488,16 +471,14 @@ _IO_file_setbuf_mmap (fp, p, len)
return result;
}
-static _IO_size_t new_do_write (_IO_FILE *, const char *, _IO_size_t);
+static _IO_size_t
+new_do_write (_IO_FILE *, const char *, _IO_size_t);
/* Write TO_DO bytes from DATA to FP.
Then mark FP as having empty buffers. */
int
-_IO_new_do_write (fp, data, to_do)
- _IO_FILE *fp;
- const char *data;
- _IO_size_t to_do;
+_IO_new_do_write (_IO_FILE *fp, const char *data, _IO_size_t to_do)
{
return (to_do == 0
|| (_IO_size_t) new_do_write (fp, data, to_do) == to_do) ? 0 : EOF;
@@ -506,10 +487,7 @@ libc_hidden_ver (_IO_new_do_write, _IO_do_write)
static
_IO_size_t
-new_do_write (fp, data, to_do)
- _IO_FILE *fp;
- const char *data;
- _IO_size_t to_do;
+new_do_write (_IO_FILE *fp, const char *data, _IO_size_t to_do)
{
_IO_size_t count;
if (fp->_flags & _IO_IS_APPENDING)
@@ -533,14 +511,13 @@ new_do_write (fp, data, to_do)
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_buf_base;
fp->_IO_write_end = (fp->_mode <= 0
- && (fp->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
+ && (fp->_flags & (_IO_LINE_BUF + _IO_UNBUFFERED))
? fp->_IO_buf_base : fp->_IO_buf_end);
return count;
}
int
-_IO_new_file_underflow (fp)
- _IO_FILE *fp;
+_IO_new_file_underflow (_IO_FILE *fp)
{
_IO_ssize_t count;
#if 0
@@ -571,16 +548,16 @@ _IO_new_file_underflow (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 (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
- not be line buffered. So we do just that here
- explicitly. --drepper */
+ required by any standard. My recollection is that
+ traditional Unix systems did this for stdout. stderr better
+ not be line buffered. So we do just that here
+ explicitly. --drepper */
_IO_acquire_lock (_IO_stdout);
if ((_IO_stdout->_flags & (_IO_LINKED | _IO_NO_WRITES | _IO_LINE_BUF))
@@ -600,7 +577,7 @@ _IO_new_file_underflow (fp)
fp->_IO_read_base = fp->_IO_read_ptr = fp->_IO_buf_base;
fp->_IO_read_end = fp->_IO_buf_base;
fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_write_end
- = fp->_IO_buf_base;
+ = fp->_IO_buf_base;
count = _IO_SYSREAD (fp, fp->_IO_buf_base,
fp->_IO_buf_end - fp->_IO_buf_base);
@@ -610,7 +587,7 @@ _IO_new_file_underflow (fp)
fp->_flags |= _IO_EOF_SEEN;
else
fp->_flags |= _IO_ERR_SEEN, count = 0;
- }
+ }
fp->_IO_read_end += count;
if (count == 0)
return EOF;
@@ -632,10 +609,10 @@ mmap_remap_check (_IO_FILE *fp)
if (_IO_SYSSTAT (fp, &st) == 0
&& S_ISREG (st.st_mode) && st.st_size != 0
/* Limit the file size to 1MB for 32-bit machines. */
- && (sizeof (ptrdiff_t) > 4 || st.st_size < 1*1024*1024))
+ && (sizeof (ptrdiff_t) > 4 || st.st_size < 1 * 1024 * 1024))
{
const size_t pagesize = __getpagesize ();
-# define ROUNDED(x) (((x) + pagesize - 1) & ~(pagesize - 1))
+#define ROUNDED(x) (((x) + pagesize - 1) & ~(pagesize - 1))
if (ROUNDED (st.st_size) < ROUNDED (fp->_IO_buf_end
- fp->_IO_buf_base))
{
@@ -672,11 +649,10 @@ mmap_remap_check (_IO_FILE *fp)
fp->_IO_buf_end = fp->_IO_buf_base + st.st_size;
}
else
- {
- /* The number of pages didn't change. */
- fp->_IO_buf_end = fp->_IO_buf_base + st.st_size;
- }
-# undef ROUNDED
+ /* The number of pages didn't change. */
+ fp->_IO_buf_end = fp->_IO_buf_base + st.st_size;
+
+#undef ROUNDED
fp->_offset -= fp->_IO_read_end - fp->_IO_read_ptr;
_IO_setg (fp, fp->_IO_buf_base,
@@ -685,9 +661,9 @@ mmap_remap_check (_IO_FILE *fp)
fp->_IO_buf_end);
/* If we are already positioned at or past the end of the file, don't
- change the current offset. If not, seek past what we have mapped,
- mimicking the position left by a normal underflow reading into its
- buffer until EOF. */
+ change the current offset. If not, seek past what we have mapped,
+ mimicking the position left by a normal underflow reading into its
+ buffer until EOF. */
if (fp->_offset < fp->_IO_buf_end - fp->_IO_buf_base)
{
@@ -706,7 +682,7 @@ mmap_remap_check (_IO_FILE *fp)
/* Life is no longer good for mmap. Punt it. */
(void) __munmap (fp->_IO_buf_base,
fp->_IO_buf_end - fp->_IO_buf_base);
- punt:
+punt:
fp->_IO_buf_base = fp->_IO_buf_end = NULL;
_IO_setg (fp, NULL, NULL, NULL);
if (fp->_mode <= 0)
@@ -726,7 +702,7 @@ _IO_file_underflow_mmap (_IO_FILE *fp)
if (fp->_IO_read_ptr < fp->_IO_read_end)
return *(unsigned char *) fp->_IO_read_ptr;
- if (__builtin_expect (mmap_remap_check (fp), 0))
+ if (__glibc_unlikely (mmap_remap_check (fp)))
/* We punted to the regular file functions. */
return _IO_UNDERFLOW (fp);
@@ -750,7 +726,7 @@ decide_maybe_mmap (_IO_FILE *fp)
if (_IO_SYSSTAT (fp, &st) == 0
&& S_ISREG (st.st_mode) && st.st_size != 0
/* Limit the file size to 1MB for 32-bit machines. */
- && (sizeof (ptrdiff_t) > 4 || st.st_size < 1*1024*1024)
+ && (sizeof (ptrdiff_t) > 4 || st.st_size < 1 * 1024 * 1024)
/* Sanity check. */
&& (fp->_offset == _IO_pos_BAD || fp->_offset <= st.st_size))
{
@@ -780,9 +756,9 @@ decide_maybe_mmap (_IO_FILE *fp)
fp->_offset = st.st_size;
if (fp->_mode <= 0)
- _IO_JUMPS ((struct _IO_FILE_plus *)fp) = &_IO_file_jumps_mmap;
+ _IO_JUMPS ((struct _IO_FILE_plus *) fp) = &_IO_file_jumps_mmap;
else
- _IO_JUMPS ((struct _IO_FILE_plus *)fp) = &_IO_wfile_jumps_mmap;
+ _IO_JUMPS ((struct _IO_FILE_plus *) fp) = &_IO_wfile_jumps_mmap;
fp->_wide_data->_wide_vtable = &_IO_wfile_jumps_mmap;
return;
@@ -810,9 +786,7 @@ _IO_file_underflow_maybe_mmap (_IO_FILE *fp)
int
-_IO_new_file_overflow (f, ch)
- _IO_FILE *f;
- int ch;
+_IO_new_file_overflow (_IO_FILE *f, int ch)
{
if (f->_flags & _IO_NO_WRITES) /* SET ERROR */
{
@@ -830,13 +804,13 @@ _IO_new_file_overflow (f, ch)
_IO_setg (f, f->_IO_buf_base, f->_IO_buf_base, f->_IO_buf_base);
}
/* Otherwise must be currently reading.
- If _IO_read_ptr (and hence also _IO_read_end) is at the buffer end,
- logically slide the buffer forwards one block (by setting the
- read pointers to all point at the beginning of the block). This
- makes room for subsequent output.
- Otherwise, set the read pointers to _IO_read_end (leaving that
- alone, so it can continue to correspond to the external position). */
- if (__builtin_expect (_IO_in_backup (f), 0))
+ If _IO_read_ptr (and hence also _IO_read_end) is at the buffer end,
+ logically slide the buffer forwards one block (by setting the
+ read pointers to all point at the beginning of the block). This
+ makes room for subsequent output.
+ Otherwise, set the read pointers to _IO_read_end (leaving that
+ alone, so it can continue to correspond to the external position). */
+ if (__glibc_unlikely (_IO_in_backup (f)))
{
size_t nbackup = f->_IO_read_end - f->_IO_read_ptr;
_IO_free_backup_area (f);
@@ -853,13 +827,13 @@ _IO_new_file_overflow (f, ch)
f->_IO_read_base = f->_IO_read_ptr = f->_IO_read_end;
f->_flags |= _IO_CURRENTLY_PUTTING;
- if (f->_mode <= 0 && f->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
+ if (f->_mode <= 0 && f->_flags & (_IO_LINE_BUF + _IO_UNBUFFERED))
f->_IO_write_end = f->_IO_write_ptr;
}
if (ch == EOF)
return _IO_do_write (f, f->_IO_write_base,
f->_IO_write_ptr - f->_IO_write_base);
- if (f->_IO_write_ptr == f->_IO_buf_end ) /* Buffer is really full */
+ if (f->_IO_write_ptr == f->_IO_buf_end) /* Buffer is really full */
if (_IO_do_flush (f) == EOF)
return EOF;
*f->_IO_write_ptr++ = ch;
@@ -873,15 +847,15 @@ _IO_new_file_overflow (f, ch)
libc_hidden_ver (_IO_new_file_overflow, _IO_file_overflow)
int
-_IO_new_file_sync (fp)
- _IO_FILE *fp;
+_IO_new_file_sync (_IO_FILE *fp)
{
_IO_ssize_t delta;
int retval = 0;
/* char* ptr = cur_ptr(); */
if (fp->_IO_write_ptr > fp->_IO_write_base)
- if (_IO_do_flush(fp)) return EOF;
+ if (_IO_do_flush (fp))
+ return EOF;
delta = fp->_IO_read_ptr - fp->_IO_read_end;
if (delta != 0)
{
@@ -894,7 +868,7 @@ _IO_new_file_sync (fp)
fp->_IO_read_end = fp->_IO_read_ptr;
#ifdef ESPIPE
else if (errno == ESPIPE)
- ; /* Ignore error from unseekable devices. */
+ ; /* Ignore error from unseekable devices. */
#endif
else
retval = EOF;
@@ -931,11 +905,7 @@ _IO_file_sync_mmap (_IO_FILE *fp)
_IO_off64_t
-_IO_new_file_seekoff (fp, offset, dir, mode)
- _IO_FILE *fp;
- _IO_off64_t offset;
- int dir;
- int mode;
+_IO_new_file_seekoff (_IO_FILE *fp, _IO_off64_t offset, int dir, int mode)
{
_IO_off64_t result;
_IO_off64_t delta, new_offset;
@@ -949,7 +919,7 @@ _IO_new_file_seekoff (fp, offset, dir, mode)
|| _IO_in_put_mode (fp));
if (mode == 0)
- dir = _IO_seek_cur, offset = 0; /* Don't move any pointers. */
+ dir = _IO_seek_cur, offset = 0; /* Don't move any pointers. */
/* Flush unwritten characters.
(This may do an unneeded write if we seek within the buffer.
@@ -981,13 +951,11 @@ _IO_new_file_seekoff (fp, offset, dir, mode)
if (mode != 0 || !was_writing)
offset -= fp->_IO_read_end - fp->_IO_read_ptr;
else
- {
- /* _IO_read_end coincides with fp._offset, so the actual file position
- is fp._offset - (_IO_read_end - new_write_ptr). This is fine
- even if fp._offset is not set, since fp->_IO_read_end is then at
- _IO_buf_base and this adjustment is for unbuffered output. */
- offset -= fp->_IO_read_end - fp->_IO_write_ptr;
- }
+ /* _IO_read_end coincides with fp._offset, so the actual file position
+ is fp._offset - (_IO_read_end - new_write_ptr). This is fine
+ even if fp._offset is not set, since fp->_IO_read_end is then at
+ _IO_buf_base and this adjustment is for unbuffered output. */
+ offset -= fp->_IO_read_end - fp->_IO_write_ptr;
if (fp->_offset == _IO_pos_BAD)
{
@@ -1015,16 +983,16 @@ _IO_new_file_seekoff (fp, offset, dir, mode)
case _IO_seek_set:
break;
case _IO_seek_end:
- {
- struct stat64 st;
- if (_IO_SYSSTAT (fp, &st) == 0 && S_ISREG (st.st_mode))
- {
- offset += st.st_size;
- dir = _IO_seek_set;
- }
- else
- goto dumb;
- }
+ {
+ struct stat64 st;
+ if (_IO_SYSSTAT (fp, &st) == 0 && S_ISREG (st.st_mode))
+ {
+ offset += st.st_size;
+ dir = _IO_seek_set;
+ }
+ else
+ goto dumb;
+ }
}
/* At this point, dir==_IO_seek_set. */
@@ -1074,7 +1042,7 @@ _IO_new_file_seekoff (fp, offset, dir, mode)
if (count < delta)
{
/* We weren't allowed to read, but try to seek the remainder. */
- offset = count == EOF ? delta : delta-count;
+ offset = count == EOF ? delta : delta - count;
dir = _IO_seek_cur;
goto dumb;
}
@@ -1085,7 +1053,7 @@ _IO_new_file_seekoff (fp, offset, dir, mode)
fp->_offset = result + count;
_IO_mask_flags (fp, 0, _IO_EOF_SEEN);
return offset;
- dumb:
+dumb:
_IO_unsave_markers (fp);
result = _IO_SYSSEEK (fp, offset, dir);
@@ -1111,11 +1079,7 @@ resync:
libc_hidden_ver (_IO_new_file_seekoff, _IO_file_seekoff)
_IO_off64_t
-_IO_file_seekoff_mmap (fp, offset, dir, mode)
- _IO_FILE *fp;
- _IO_off64_t offset;
- int dir;
- int mode;
+_IO_file_seekoff_mmap (_IO_FILE *fp, _IO_off64_t offset, int dir, int mode)
{
_IO_off64_t result;
@@ -1186,39 +1150,30 @@ _IO_file_seekoff_maybe_mmap (_IO_FILE *fp, _IO_off64_t offset, int dir,
}
_IO_ssize_t
-_IO_file_read (fp, buf, size)
- _IO_FILE *fp;
- void *buf;
- _IO_ssize_t size;
+_IO_file_read (_IO_FILE *fp, void *buf, _IO_ssize_t size)
{
- return (__builtin_expect (fp->_flags2 & _IO_FLAGS2_NOTCANCEL, 0)
+ return (__glibc_unlikely (fp->_flags2 & _IO_FLAGS2_NOTCANCEL)
? read_not_cancel (fp->_fileno, buf, size)
: read (fp->_fileno, buf, size));
}
libc_hidden_def (_IO_file_read)
_IO_off64_t
-_IO_file_seek (fp, offset, dir)
- _IO_FILE *fp;
- _IO_off64_t offset;
- int dir;
+_IO_file_seek (_IO_FILE *fp, _IO_off64_t offset, int dir)
{
return __lseek64 (fp->_fileno, offset, dir);
}
libc_hidden_def (_IO_file_seek)
int
-_IO_file_stat (fp, st)
- _IO_FILE *fp;
- void *st;
+_IO_file_stat (_IO_FILE *fp, void *st)
{
return __fxstat64 (_STAT_VER, fp->_fileno, (struct stat64 *) st);
}
libc_hidden_def (_IO_file_stat)
int
-_IO_file_close_mmap (fp)
- _IO_FILE *fp;
+_IO_file_close_mmap (_IO_FILE *fp)
{
/* In addition to closing the file descriptor we have to unmap the file. */
(void) __munmap (fp->_IO_buf_base, fp->_IO_buf_end - fp->_IO_buf_base);
@@ -1229,8 +1184,7 @@ _IO_file_close_mmap (fp)
}
int
-_IO_file_close (fp)
- _IO_FILE *fp;
+_IO_file_close (_IO_FILE *fp)
{
/* Cancelling close should be avoided if possible since it leaves an
unrecoverable state behind. */
@@ -1239,17 +1193,13 @@ _IO_file_close (fp)
libc_hidden_def (_IO_file_close)
_IO_ssize_t
-_IO_new_file_write (f, data, n)
- _IO_FILE *f;
- const void *data;
- _IO_ssize_t n;
+_IO_new_file_write (_IO_FILE *f, const void *data, _IO_ssize_t n)
{
_IO_ssize_t to_do = n;
_IO_ssize_t count = 0;
while (to_do > 0)
{
- count = (__builtin_expect (f->_flags2
- & _IO_FLAGS2_NOTCANCEL, 0)
+ count = (__glibc_unlikely (f->_flags2 & _IO_FLAGS2_NOTCANCEL)
? write_not_cancel (f->_fileno, data, to_do)
: write (f->_fileno, data, to_do));
if (count < 0)
@@ -1267,12 +1217,9 @@ _IO_new_file_write (f, data, n)
}
_IO_size_t
-_IO_new_file_xsputn (f, data, n)
- _IO_FILE *f;
- const void *data;
- _IO_size_t n;
+_IO_new_file_xsputn (_IO_FILE *f, const void *data, _IO_size_t n)
{
- register const char *s = (const char *) data;
+ const char *s = (const char *) data;
_IO_size_t to_do = n;
int must_flush = 0;
_IO_size_t count = 0;
@@ -1289,20 +1236,18 @@ _IO_new_file_xsputn (f, data, n)
count = f->_IO_buf_end - f->_IO_write_ptr;
if (count >= n)
{
- register const char *p;
+ const char *p;
for (p = s + n; p > s; )
- {
- if (*--p == '\n')
- {
- count = p - s + 1;
- must_flush = 1;
- break;
- }
- }
+ if (*--p == '\n')
+ {
+ count = p - s + 1;
+ must_flush = 1;
+ break;
+ }
}
}
else if (f->_IO_write_end > f->_IO_write_ptr)
- count = f->_IO_write_end - f->_IO_write_ptr; /* Space available. */
+ count = f->_IO_write_end - f->_IO_write_ptr; /* Space available. */
/* Then fill the buffer. */
if (count > 0)
@@ -1329,7 +1274,7 @@ _IO_new_file_xsputn (f, data, n)
return (to_do == 0 || to_do == n) ? EOF : n - to_do;
/* Try to maintain alignment: write a whole number of blocks.
- dont_write is what gets left over. */
+ dont_write is what gets left over. */
block_size = f->_IO_buf_end - f->_IO_buf_base;
do_write = to_do - (block_size >= 128 ? to_do % block_size : 0);
@@ -1342,24 +1287,21 @@ _IO_new_file_xsputn (f, data, n)
}
/* Now write out the remainder. Normally, this will fit in the
- buffer, but it's somewhat messier for line-buffered files,
- so we let _IO_default_xsputn handle the general case. */
+ buffer, but it's somewhat messier for line-buffered files,
+ so we let _IO_default_xsputn handle the general case. */
if (to_do)
- to_do -= _IO_default_xsputn (f, s+do_write, to_do);
+ to_do -= _IO_default_xsputn (f, s + do_write, to_do);
}
return n - to_do;
}
libc_hidden_ver (_IO_new_file_xsputn, _IO_file_xsputn)
_IO_size_t
-_IO_file_xsgetn (fp, data, n)
- _IO_FILE *fp;
- void *data;
- _IO_size_t n;
+_IO_file_xsgetn (_IO_FILE *fp, void *data, _IO_size_t n)
{
- register _IO_size_t want, have;
- register _IO_ssize_t count;
- register char *s = data;
+ _IO_size_t want, have;
+ _IO_ssize_t count;
+ char *s = data;
want = n;
@@ -1452,22 +1394,20 @@ _IO_file_xsgetn (fp, data, n)
}
libc_hidden_def (_IO_file_xsgetn)
-static _IO_size_t _IO_file_xsgetn_mmap (_IO_FILE *, void *, _IO_size_t);
static _IO_size_t
-_IO_file_xsgetn_mmap (fp, data, n)
- _IO_FILE *fp;
- void *data;
- _IO_size_t n;
+_IO_file_xsgetn_mmap (_IO_FILE *, void *, _IO_size_t);
+static _IO_size_t
+_IO_file_xsgetn_mmap (_IO_FILE *fp, void *data, _IO_size_t n)
{
- register _IO_size_t have;
+ _IO_size_t have;
char *read_ptr = fp->_IO_read_ptr;
- register char *s = (char *) data;
+ char *s = (char *) data;
have = fp->_IO_read_end - fp->_IO_read_ptr;
if (have < n)
{
- if (__builtin_expect (_IO_in_backup (fp), 0))
+ if (__glibc_unlikely (_IO_in_backup (fp)))
{
#ifdef _LIBC
s = __mempcpy (s, read_ptr, have);
@@ -1484,7 +1424,7 @@ _IO_file_xsgetn_mmap (fp, data, n)
if (have < n)
{
/* Check that we are mapping all of the file, in case it grew. */
- if (__builtin_expect (mmap_remap_check (fp), 0))
+ if (__glibc_unlikely (mmap_remap_check (fp)))
/* We punted mmap, so complete with the vanilla code. */
return s - (char *) data + _IO_XSGETN (fp, data, n);
@@ -1511,12 +1451,10 @@ _IO_file_xsgetn_mmap (fp, data, n)
return s - (char *) data;
}
-static _IO_size_t _IO_file_xsgetn_maybe_mmap (_IO_FILE *, void *, _IO_size_t);
static _IO_size_t
-_IO_file_xsgetn_maybe_mmap (fp, data, n)
- _IO_FILE *fp;
- void *data;
- _IO_size_t n;
+_IO_file_xsgetn_maybe_mmap (_IO_FILE *, void *, _IO_size_t);
+static _IO_size_t
+_IO_file_xsgetn_maybe_mmap (_IO_FILE *fp, void *data, _IO_size_t n)
{
/* We only get here if this is the first attempt to read something.
Decide which operations to use and then punt to the chosen one. */
@@ -1544,72 +1482,72 @@ versioned_symbol (libc, _IO_new_file_xsputn, _IO_file_xsputn, GLIBC_2_1);
const struct _IO_jump_t _IO_file_jumps =
{
JUMP_INIT_DUMMY,
- JUMP_INIT(finish, _IO_file_finish),
- JUMP_INIT(overflow, _IO_file_overflow),
- JUMP_INIT(underflow, _IO_file_underflow),
- JUMP_INIT(uflow, _IO_default_uflow),
- JUMP_INIT(pbackfail, _IO_default_pbackfail),
- JUMP_INIT(xsputn, _IO_file_xsputn),
- JUMP_INIT(xsgetn, _IO_file_xsgetn),
- JUMP_INIT(seekoff, _IO_new_file_seekoff),
- JUMP_INIT(seekpos, _IO_default_seekpos),
- JUMP_INIT(setbuf, _IO_new_file_setbuf),
- JUMP_INIT(sync, _IO_new_file_sync),
- JUMP_INIT(doallocate, _IO_file_doallocate),
- JUMP_INIT(read, _IO_file_read),
- JUMP_INIT(write, _IO_new_file_write),
- JUMP_INIT(seek, _IO_file_seek),
- JUMP_INIT(close, _IO_file_close),
- JUMP_INIT(stat, _IO_file_stat),
- JUMP_INIT(showmanyc, _IO_default_showmanyc),
- JUMP_INIT(imbue, _IO_default_imbue)
+ JUMP_INIT (finish, _IO_file_finish),
+ JUMP_INIT (overflow, _IO_file_overflow),
+ JUMP_INIT (underflow, _IO_file_underflow),
+ JUMP_INIT (uflow, _IO_default_uflow),
+ JUMP_INIT (pbackfail, _IO_default_pbackfail),
+ JUMP_INIT (xsputn, _IO_file_xsputn),
+ JUMP_INIT (xsgetn, _IO_file_xsgetn),
+ JUMP_INIT (seekoff, _IO_new_file_seekoff),
+ JUMP_INIT (seekpos, _IO_default_seekpos),
+ JUMP_INIT (setbuf, _IO_new_file_setbuf),
+ JUMP_INIT (sync, _IO_new_file_sync),
+ JUMP_INIT (doallocate, _IO_file_doallocate),
+ JUMP_INIT (read, _IO_file_read),
+ JUMP_INIT (write, _IO_new_file_write),
+ JUMP_INIT (seek, _IO_file_seek),
+ JUMP_INIT (close, _IO_file_close),
+ JUMP_INIT (stat, _IO_file_stat),
+ JUMP_INIT (showmanyc, _IO_default_showmanyc),
+ JUMP_INIT (imbue, _IO_default_imbue)
};
libc_hidden_data_def (_IO_file_jumps)
const struct _IO_jump_t _IO_file_jumps_mmap =
{
JUMP_INIT_DUMMY,
- JUMP_INIT(finish, _IO_file_finish),
- JUMP_INIT(overflow, _IO_file_overflow),
- JUMP_INIT(underflow, _IO_file_underflow_mmap),
- JUMP_INIT(uflow, _IO_default_uflow),
- JUMP_INIT(pbackfail, _IO_default_pbackfail),
- JUMP_INIT(xsputn, _IO_new_file_xsputn),
- JUMP_INIT(xsgetn, _IO_file_xsgetn_mmap),
- JUMP_INIT(seekoff, _IO_file_seekoff_mmap),
- JUMP_INIT(seekpos, _IO_default_seekpos),
- JUMP_INIT(setbuf, (_IO_setbuf_t) _IO_file_setbuf_mmap),
- JUMP_INIT(sync, _IO_file_sync_mmap),
- JUMP_INIT(doallocate, _IO_file_doallocate),
- JUMP_INIT(read, _IO_file_read),
- JUMP_INIT(write, _IO_new_file_write),
- JUMP_INIT(seek, _IO_file_seek),
- JUMP_INIT(close, _IO_file_close_mmap),
- JUMP_INIT(stat, _IO_file_stat),
- JUMP_INIT(showmanyc, _IO_default_showmanyc),
- JUMP_INIT(imbue, _IO_default_imbue)
+ JUMP_INIT (finish, _IO_file_finish),
+ JUMP_INIT (overflow, _IO_file_overflow),
+ JUMP_INIT (underflow, _IO_file_underflow_mmap),
+ JUMP_INIT (uflow, _IO_default_uflow),
+ JUMP_INIT (pbackfail, _IO_default_pbackfail),
+ JUMP_INIT (xsputn, _IO_new_file_xsputn),
+ JUMP_INIT (xsgetn, _IO_file_xsgetn_mmap),
+ JUMP_INIT (seekoff, _IO_file_seekoff_mmap),
+ JUMP_INIT (seekpos, _IO_default_seekpos),
+ JUMP_INIT (setbuf, (_IO_setbuf_t) _IO_file_setbuf_mmap),
+ JUMP_INIT (sync, _IO_file_sync_mmap),
+ JUMP_INIT (doallocate, _IO_file_doallocate),
+ JUMP_INIT (read, _IO_file_read),
+ JUMP_INIT (write, _IO_new_file_write),
+ JUMP_INIT (seek, _IO_file_seek),
+ JUMP_INIT (close, _IO_file_close_mmap),
+ JUMP_INIT (stat, _IO_file_stat),
+ JUMP_INIT (showmanyc, _IO_default_showmanyc),
+ JUMP_INIT (imbue, _IO_default_imbue)
};
const struct _IO_jump_t _IO_file_jumps_maybe_mmap =
{
JUMP_INIT_DUMMY,
- JUMP_INIT(finish, _IO_file_finish),
- JUMP_INIT(overflow, _IO_file_overflow),
- JUMP_INIT(underflow, _IO_file_underflow_maybe_mmap),
- JUMP_INIT(uflow, _IO_default_uflow),
- JUMP_INIT(pbackfail, _IO_default_pbackfail),
- JUMP_INIT(xsputn, _IO_new_file_xsputn),
- JUMP_INIT(xsgetn, _IO_file_xsgetn_maybe_mmap),
- JUMP_INIT(seekoff, _IO_file_seekoff_maybe_mmap),
- JUMP_INIT(seekpos, _IO_default_seekpos),
- JUMP_INIT(setbuf, (_IO_setbuf_t) _IO_file_setbuf_mmap),
- JUMP_INIT(sync, _IO_new_file_sync),
- JUMP_INIT(doallocate, _IO_file_doallocate),
- JUMP_INIT(read, _IO_file_read),
- JUMP_INIT(write, _IO_new_file_write),
- JUMP_INIT(seek, _IO_file_seek),
- JUMP_INIT(close, _IO_file_close),
- JUMP_INIT(stat, _IO_file_stat),
- JUMP_INIT(showmanyc, _IO_default_showmanyc),
- JUMP_INIT(imbue, _IO_default_imbue)
+ JUMP_INIT (finish, _IO_file_finish),
+ JUMP_INIT (overflow, _IO_file_overflow),
+ JUMP_INIT (underflow, _IO_file_underflow_maybe_mmap),
+ JUMP_INIT (uflow, _IO_default_uflow),
+ JUMP_INIT (pbackfail, _IO_default_pbackfail),
+ JUMP_INIT (xsputn, _IO_new_file_xsputn),
+ JUMP_INIT (xsgetn, _IO_file_xsgetn_maybe_mmap),
+ JUMP_INIT (seekoff, _IO_file_seekoff_maybe_mmap),
+ JUMP_INIT (seekpos, _IO_default_seekpos),
+ JUMP_INIT (setbuf, (_IO_setbuf_t) _IO_file_setbuf_mmap),
+ JUMP_INIT (sync, _IO_new_file_sync),
+ JUMP_INIT (doallocate, _IO_file_doallocate),
+ JUMP_INIT (read, _IO_file_read),
+ JUMP_INIT (write, _IO_new_file_write),
+ JUMP_INIT (seek, _IO_file_seek),
+ JUMP_INIT (close, _IO_file_close),
+ JUMP_INIT (stat, _IO_file_stat),
+ JUMP_INIT (showmanyc, _IO_default_showmanyc),
+ JUMP_INIT (imbue, _IO_default_imbue)
};
diff --git a/libio/fmemopen.c b/libio/fmemopen.c
index 02c764f..f0942ac 100644
--- a/libio/fmemopen.c
+++ b/libio/fmemopen.c
@@ -202,9 +202,9 @@ fmemopen (void *buf, size_t len, const char *mode)
cookie_io_functions_t iof;
fmemopen_cookie_t *c;
- if (__builtin_expect (len == 0, 0))
+ if (__glibc_unlikely (len == 0))
{
- einval:
+einval:
__set_errno (EINVAL);
return NULL;
}
@@ -228,7 +228,7 @@ fmemopen (void *buf, size_t len, const char *mode)
}
else
{
- if (__builtin_expect ((uintptr_t) len > -(uintptr_t) buf, 0))
+ if (__glibc_unlikely ((uintptr_t) len > -(uintptr_t) buf))
{
free (c);
goto einval;
diff --git a/libio/iofdopen.c b/libio/iofdopen.c
index a65a5a6..4fe143c 100644
--- a/libio/iofdopen.c
+++ b/libio/iofdopen.c
@@ -33,17 +33,15 @@
#endif
#ifndef _IO_fcntl
-#ifdef _LIBC
-#define _IO_fcntl __fcntl
-#else
-#define _IO_fcntl fcntl
-#endif
+# ifdef _LIBC
+# define _IO_fcntl __fcntl
+# else
+# define _IO_fcntl fcntl
+# endif
#endif
_IO_FILE *
-_IO_new_fdopen (fd, mode)
- int fd;
- const char *mode;
+_IO_new_fdopen (int fd, const char *mode)
{
int read_write;
int posix_mode = 0;
@@ -69,12 +67,12 @@ _IO_new_fdopen (fd, mode)
break;
case 'a':
posix_mode = O_APPEND;
- read_write = _IO_NO_READS|_IO_IS_APPENDING;
+ read_write = _IO_NO_READS | _IO_IS_APPENDING;
break;
default:
MAYBE_SET_EINVAL;
return NULL;
- }
+ }
for (i = 1; i < 5; ++i)
{
switch (*++mode)
@@ -97,9 +95,9 @@ _IO_new_fdopen (fd, mode)
}
#ifdef F_GETFL
fd_flags = _IO_fcntl (fd, F_GETFL);
-#ifndef O_ACCMODE
-#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
-#endif
+# ifndef O_ACCMODE
+# define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
+# endif
if (fd_flags == -1)
return NULL;
@@ -125,13 +123,13 @@ _IO_new_fdopen (fd, mode)
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
+# ifdef F_SETFL
if (_IO_fcntl (fd, F_SETFL, fd_flags | O_APPEND) == -1)
-#endif
- return NULL;
+# endif
+ return NULL;
}
#endif
@@ -154,7 +152,7 @@ _IO_new_fdopen (fd, mode)
#ifdef _G_HAVE_MMAP
(use_mmap && (read_write & _IO_NO_WRITES)) ? &_IO_file_jumps_maybe_mmap :
#endif
- &_IO_file_jumps;
+ &_IO_file_jumps;
_IO_file_init (&new_f->fp);
#if !_IO_UNIFIED_JUMPTABLES
new_f->fp.vtable = NULL;
@@ -169,7 +167,7 @@ _IO_new_fdopen (fd, mode)
new_f->fp.file._flags &= ~_IO_DELETE_DONT_CLOSE;
_IO_mask_flags (&new_f->fp.file, read_write,
- _IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING);
+ _IO_NO_READS + _IO_NO_WRITES + _IO_IS_APPENDING);
return &new_f->fp.file;
}
diff --git a/libio/iofopen.c b/libio/iofopen.c
index 5a859c6..152226b 100644
--- a/libio/iofopen.c
+++ b/libio/iofopen.c
@@ -35,16 +35,15 @@
#endif
_IO_FILE *
-__fopen_maybe_mmap (fp)
- _IO_FILE *fp;
+__fopen_maybe_mmap (_IO_FILE *fp)
{
#ifdef _G_HAVE_MMAP
if ((fp->_flags2 & _IO_FLAGS2_MMAP) && (fp->_flags & _IO_NO_WRITES))
{
/* Since this is read-only, we might be able to mmap the contents
- directly. We delay the decision until the first read attempt by
- giving it a jump table containing functions that choose mmap or
- vanilla file operations and reset the jump table accordingly. */
+ directly. We delay the decision until the first read attempt by
+ giving it a jump table containing functions that choose mmap or
+ vanilla file operations and reset the jump table accordingly. */
if (fp->_mode <= 0)
_IO_JUMPS ((struct _IO_FILE_plus *) fp) = &_IO_file_jumps_maybe_mmap;
@@ -58,10 +57,7 @@ __fopen_maybe_mmap (fp)
_IO_FILE *
-__fopen_internal (filename, mode, is32)
- const char *filename;
- const char *mode;
- int is32;
+__fopen_internal (const char *filename, const char *mode, int is32)
{
struct locked_FILE
{
@@ -96,9 +92,7 @@ __fopen_internal (filename, mode, is32)
}
_IO_FILE *
-_IO_new_fopen (filename, mode)
- const char *filename;
- const char *mode;
+_IO_new_fopen (const char *filename, const char *mode)
{
return __fopen_internal (filename, mode, 1);
}
--
1.7.10.4