improve readability of stdio: fix indentation and remove trailing spaces
Change-Id: Ic51e58a7c75d20bf770dc0ebd7f97a338fbe0036 Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>
This commit is contained in:
parent
1297428e89
commit
a910abcd19
@ -63,12 +63,12 @@ fgets(char *buf, int n, FILE *fp)
|
|||||||
/* EOF/error: stop with partial or no line */
|
/* EOF/error: stop with partial or no line */
|
||||||
if (s == buf)
|
if (s == buf)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
len = fp->_r;
|
len = fp->_r;
|
||||||
p = fp->_p;
|
p = fp->_p;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Scan through at most n bytes of the current buffer,
|
* Scan through at most n bytes of the current buffer,
|
||||||
* looking for '\n'. If found, copy up to and including
|
* looking for '\n'. If found, copy up to and including
|
||||||
|
@ -50,7 +50,7 @@ int __sdidinit;
|
|||||||
/* p r w flags file _bf z cookie close read seek write
|
/* p r w flags file _bf z cookie close read seek write
|
||||||
ext */
|
ext */
|
||||||
|
|
||||||
/* the usual - (stdin + stdout + stderr) */
|
/* the usual - (stdin + stdout + stderr) */
|
||||||
static FILE usual[FOPEN_MAX - 3];
|
static FILE usual[FOPEN_MAX - 3];
|
||||||
static struct __sfileext usualext[FOPEN_MAX - 3];
|
static struct __sfileext usualext[FOPEN_MAX - 3];
|
||||||
static struct glue uglue = { 0, FOPEN_MAX - 3, usual };
|
static struct glue uglue = { 0, FOPEN_MAX - 3, usual };
|
||||||
|
@ -53,7 +53,7 @@ fopen(const char *file, const char *mode)
|
|||||||
if ((f = open(file, oflags, DEFFILEMODE)) < 0) {
|
if ((f = open(file, oflags, DEFFILEMODE)) < 0) {
|
||||||
fp->_flags = 0; /* release */
|
fp->_flags = 0; /* release */
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
fp->_file = f;
|
fp->_file = f;
|
||||||
fp->_flags = flags;
|
fp->_flags = flags;
|
||||||
fp->_cookie = fp;
|
fp->_cookie = fp;
|
||||||
|
@ -38,10 +38,10 @@ int
|
|||||||
fprintf(FILE *fp, const char *fmt, ...)
|
fprintf(FILE *fp, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
ret = vfprintf(fp, fmt, ap);
|
ret = vfprintf(fp, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
@ -48,29 +48,29 @@ lflush(FILE *fp)
|
|||||||
size_t
|
size_t
|
||||||
fread(void *buf, size_t size, size_t count, FILE *fp)
|
fread(void *buf, size_t size, size_t count, FILE *fp)
|
||||||
{
|
{
|
||||||
size_t resid;
|
size_t resid;
|
||||||
char *p;
|
char *p;
|
||||||
int r;
|
int r;
|
||||||
size_t total;
|
size_t total;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The ANSI standard requires a return value of 0 for a count
|
* The ANSI standard requires a return value of 0 for a count
|
||||||
* or a size of 0. Peculiarily, it imposes no such requirements
|
* or a size of 0. Peculiarily, it imposes no such requirements
|
||||||
* on fwrite; it only requires fread to be broken.
|
* on fwrite; it only requires fread to be broken.
|
||||||
*/
|
*/
|
||||||
if ((resid = count * size) == 0)
|
if ((resid = count * size) == 0)
|
||||||
return (0);
|
return (0);
|
||||||
if (fp->_r < 0)
|
if (fp->_r < 0)
|
||||||
fp->_r = 0;
|
fp->_r = 0;
|
||||||
total = resid;
|
total = resid;
|
||||||
p = buf;
|
p = buf;
|
||||||
|
|
||||||
#if 1 /* BIONIC: optimize unbuffered reads */
|
#if 1 /* BIONIC: optimize unbuffered reads */
|
||||||
if (fp->_flags & __SNBF && fp->_ur == 0)
|
if (fp->_flags & __SNBF && fp->_ur == 0)
|
||||||
{
|
{
|
||||||
/* the following comes mainly from __srefill(), with slight
|
/* the following comes mainly from __srefill(), with slight
|
||||||
* modifications
|
* modifications
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* make sure stdio is set up */
|
/* make sure stdio is set up */
|
||||||
if (!__sdidinit)
|
if (!__sdidinit)
|
||||||
@ -99,22 +99,22 @@ fread(void *buf, size_t size, size_t count, FILE *fp)
|
|||||||
}
|
}
|
||||||
fp->_flags |= __SRD;
|
fp->_flags |= __SRD;
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* We were reading. If there is an ungetc buffer,
|
* We were reading. If there is an ungetc buffer,
|
||||||
* we must have been reading from that. Drop it,
|
* we must have been reading from that. Drop it,
|
||||||
* restoring the previous buffer (if any). If there
|
* restoring the previous buffer (if any). If there
|
||||||
* is anything in that buffer, return.
|
* is anything in that buffer, return.
|
||||||
*/
|
*/
|
||||||
if (HASUB(fp)) {
|
if (HASUB(fp)) {
|
||||||
FREEUB(fp);
|
FREEUB(fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Before reading from a line buffered or unbuffered file,
|
* Before reading from a line buffered or unbuffered file,
|
||||||
* flush all line buffered output files, per the ANSI C
|
* flush all line buffered output files, per the ANSI C
|
||||||
* standard.
|
* standard.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (fp->_flags & (__SLBF|__SNBF))
|
if (fp->_flags & (__SLBF|__SNBF))
|
||||||
(void) _fwalk(lflush);
|
(void) _fwalk(lflush);
|
||||||
@ -151,8 +151,8 @@ fread(void *buf, size_t size, size_t count, FILE *fp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)memcpy((void *)p, (void *)fp->_p, resid);
|
(void)memcpy((void *)p, (void *)fp->_p, resid);
|
||||||
fp->_r -= resid;
|
fp->_r -= resid;
|
||||||
fp->_p += resid;
|
fp->_p += resid;
|
||||||
return (count);
|
return (count);
|
||||||
}
|
}
|
||||||
|
@ -40,8 +40,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "local.h"
|
#include "local.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Re-direct an existing, open (probably) file to some other file.
|
* Re-direct an existing, open (probably) file to some other file.
|
||||||
* ANSI is written such that the original file gets closed if at
|
* ANSI is written such that the original file gets closed if at
|
||||||
* all possible, no matter what.
|
* all possible, no matter what.
|
||||||
*/
|
*/
|
||||||
|
@ -204,7 +204,7 @@ fseeko(FILE *fp, off_t offset, int whence)
|
|||||||
if ((*seekfn)(fp->_cookie, curoff, SEEK_SET) == POS_ERR)
|
if ((*seekfn)(fp->_cookie, curoff, SEEK_SET) == POS_ERR)
|
||||||
goto dumb;
|
goto dumb;
|
||||||
fp->_r = 0;
|
fp->_r = 0;
|
||||||
fp->_p = fp->_bf._base;
|
fp->_p = fp->_bf._base;
|
||||||
if (HASUB(fp))
|
if (HASUB(fp))
|
||||||
FREEUB(fp);
|
FREEUB(fp);
|
||||||
fp->_flags &= ~__SEOF;
|
fp->_flags &= ~__SEOF;
|
||||||
|
@ -83,7 +83,7 @@ __sfvwrite(FILE *fp, struct __suio *uio)
|
|||||||
do {
|
do {
|
||||||
GETIOV(;);
|
GETIOV(;);
|
||||||
#if 1 /* BIONIC: don't limit to 1KB writes */
|
#if 1 /* BIONIC: don't limit to 1KB writes */
|
||||||
w = (*fp->_write)(fp->_cookie, p, len);
|
w = (*fp->_write)(fp->_cookie, p, len);
|
||||||
#else
|
#else
|
||||||
w = (*fp->_write)(fp->_cookie, p, MIN(len, BUFSIZ2));
|
w = (*fp->_write)(fp->_cookie, p, MIN(len, BUFSIZ2));
|
||||||
#endif
|
#endif
|
||||||
@ -183,7 +183,7 @@ __sfvwrite(FILE *fp, struct __suio *uio)
|
|||||||
} else if (s >= (w = fp->_bf._size)) {
|
} else if (s >= (w = fp->_bf._size)) {
|
||||||
w = (*fp->_write)(fp->_cookie, p, w);
|
w = (*fp->_write)(fp->_cookie, p, w);
|
||||||
if (w <= 0)
|
if (w <= 0)
|
||||||
goto err;
|
goto err;
|
||||||
} else {
|
} else {
|
||||||
w = s;
|
w = s;
|
||||||
COPY(w);
|
COPY(w);
|
||||||
|
@ -38,10 +38,10 @@ int
|
|||||||
printf(const char *fmt, ...)
|
printf(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
ret = vfprintf(stdout, fmt, ap);
|
ret = vfprintf(stdout, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ putchar_unlocked(int c)
|
|||||||
{
|
{
|
||||||
FILE *so = stdout;
|
FILE *so = stdout;
|
||||||
|
|
||||||
return (putc_unlocked(c,so));
|
return (putc_unlocked(c, so));
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef putchar
|
#undef putchar
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
int
|
int
|
||||||
snprintf(char *str, size_t n, const char *fmt, ...)
|
snprintf(char *str, size_t n, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int ret;
|
int ret;
|
||||||
char dummy;
|
char dummy;
|
||||||
FILE f;
|
FILE f;
|
||||||
@ -61,7 +61,7 @@ snprintf(char *str, size_t n, const char *fmt, ...)
|
|||||||
f._bf._size = f._w = n - 1;
|
f._bf._size = f._w = n - 1;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
ret = vfprintf(&f, fmt, ap);
|
ret = vfprintf(&f, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
*f._p = '\0';
|
*f._p = '\0';
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ int
|
|||||||
sprintf(char *str, const char *fmt, ...)
|
sprintf(char *str, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
FILE f;
|
FILE f;
|
||||||
struct __sfileext fext;
|
struct __sfileext fext;
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ sprintf(char *str, const char *fmt, ...)
|
|||||||
f._bf._size = f._w = INT_MAX;
|
f._bf._size = f._w = INT_MAX;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
ret = vfprintf(&f, fmt, ap);
|
ret = vfprintf(&f, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
*f._p = '\0';
|
*f._p = '\0';
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ int
|
|||||||
sscanf(const char *str, const char *fmt, ...)
|
sscanf(const char *str, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
FILE f;
|
FILE f;
|
||||||
struct __sfileext fext;
|
struct __sfileext fext;
|
||||||
|
|
||||||
@ -60,6 +60,6 @@ sscanf(const char *str, const char *fmt, ...)
|
|||||||
f._lb._base = NULL;
|
f._lb._base = NULL;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
ret = vfscanf(&f, fmt, ap);
|
ret = vfscanf(&f, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ __sread(void *cookie, char *buf, int n)
|
|||||||
{
|
{
|
||||||
FILE *fp = cookie;
|
FILE *fp = cookie;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = read(fp->_file, buf, n);
|
ret = read(fp->_file, buf, n);
|
||||||
/* if the read succeeded, update the current offset */
|
/* if the read succeeded, update the current offset */
|
||||||
if (ret >= 0)
|
if (ret >= 0)
|
||||||
@ -71,7 +71,7 @@ __sseek(void *cookie, fpos_t offset, int whence)
|
|||||||
{
|
{
|
||||||
FILE *fp = cookie;
|
FILE *fp = cookie;
|
||||||
off_t ret;
|
off_t ret;
|
||||||
|
|
||||||
ret = lseek(fp->_file, (off_t)offset, whence);
|
ret = lseek(fp->_file, (off_t)offset, whence);
|
||||||
if (ret == (off_t)-1)
|
if (ret == (off_t)-1)
|
||||||
fp->_flags &= ~__SOFF;
|
fp->_flags &= ~__SOFF;
|
||||||
|
@ -39,7 +39,6 @@
|
|||||||
static int
|
static int
|
||||||
eofread(void *cookie, char *buf, int len)
|
eofread(void *cookie, char *buf, int len)
|
||||||
{
|
{
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user