libsa: cstyle cleanup for open/close/read/write sources

This commit is contained in:
Toomas Soome 2018-06-14 08:58:10 +00:00
parent 19668eb2bf
commit f03b083204
4 changed files with 178 additions and 175 deletions

View File

@ -76,8 +76,8 @@ o_gethandle(void)
for (fd = 0; fd < SOPEN_MAX; fd++)
if (files[fd].f_flags == 0)
return(fd);
return(-1);
return (fd);
return (-1);
}
static void
@ -98,7 +98,7 @@ open(const char *fname, int mode)
if ((fd = o_gethandle()) == -1) {
errno = EMFILE;
return(-1);
return (-1);
}
f = &files[fd];
@ -146,12 +146,12 @@ open(const char *fname, int mode)
if (error)
devclose(f);
err:
err:
f->f_flags = 0;
errno = error;
return (-1);
ok:
ok:
f->f_ops = fs;
o_rainit(f);
return (fd);

View File

@ -89,8 +89,8 @@ read(int fd, void *dest, size_t bcount)
/*
* Optimise reads from regular files using a readahead buffer.
* If the request can't be satisfied from the current buffer contents,
* check to see if it should be bypassed, or refill the buffer and complete
* the request.
* check to see if it should be bypassed, or refill the buffer and
* complete the request.
*/
resid = bcount;
for (;;) {
@ -103,25 +103,31 @@ read(int fd, void *dest, size_t bcount)
f->f_ralen -= ccount;
resid -= ccount;
if (resid == 0)
return(bcount);
return (bcount);
dest = (char *)dest + ccount;
}
/* will filling the readahead buffer again not help? */
if (resid >= SOPEN_RASIZE) {
/* bypass the rest of the request and leave the buffer empty */
if ((errno = (f->f_ops->fo_read)(f, dest, resid, &cresid)))
/*
* bypass the rest of the request and leave the
* buffer empty
*/
errno = (f->f_ops->fo_read)(f, dest, resid, &cresid);
if (errno != 0)
return (-1);
return(bcount - cresid);
return (bcount - cresid);
}
/* fetch more data */
if ((errno = (f->f_ops->fo_read)(f, f->f_rabuf, SOPEN_RASIZE, &cresid)))
errno = (f->f_ops->fo_read)(f, f->f_rabuf, SOPEN_RASIZE,
&cresid);
if (errno != 0)
return (-1);
f->f_raoffset = 0;
f->f_ralen = SOPEN_RASIZE - cresid;
/* no more data, return what we had */
if (f->f_ralen == 0)
return(bcount - resid);
return (bcount - resid);
}
}

View File

@ -67,10 +67,7 @@ __FBSDID("$FreeBSD$");
#include "stand.h"
ssize_t
write(fd, dest, bcount)
int fd;
const void *dest;
size_t bcount;
write(int fd, const void *dest, size_t bcount)
{
struct open_file *f = &files[fd];
size_t resid;