diff options
Diffstat (limited to 'bin/ksh/shf.c')
-rw-r--r-- | bin/ksh/shf.c | 93 |
1 files changed, 24 insertions, 69 deletions
diff --git a/bin/ksh/shf.c b/bin/ksh/shf.c index 335e55fb65d..fd8969a98d7 100644 --- a/bin/ksh/shf.c +++ b/bin/ksh/shf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: shf.c,v 1.10 2004/12/18 22:35:41 millert Exp $ */ +/* $OpenBSD: shf.c,v 1.11 2004/12/20 11:34:26 otto Exp $ */ /* * Shell file I/O routines @@ -19,19 +19,15 @@ * file descriptors. */ -static int shf_fillbuf(struct shf *shf); -static int shf_emptybuf(struct shf *shf, int flags); +static int shf_fillbuf(struct shf *); +static int shf_emptybuf(struct shf *, int); /* Open a file. First three args are for open(), last arg is flags for * this package. Returns NULL if file could not be opened, or if a dup * fails. */ struct shf * -shf_open(name, oflags, mode, sflags) - const char *name; - int oflags; - int mode; - int sflags; +shf_open(const char *name, int oflags, int mode, int sflags) { struct shf *shf; int bsize = sflags & SHF_UNBUF ? (sflags & SHF_RD ? 1 : 0) : SHF_BSIZE; @@ -71,10 +67,7 @@ shf_open(name, oflags, mode, sflags) /* Set up the shf structure for a file descriptor. Doesn't fail. */ struct shf * -shf_fdopen(fd, sflags, shf) - int fd; - int sflags; - struct shf *shf; +shf_fdopen(int fd, int sflags, struct shf *shf) { int bsize = sflags & SHF_UNBUF ? (sflags & SHF_RD ? 1 : 0) : SHF_BSIZE; @@ -124,10 +117,7 @@ shf_fdopen(fd, sflags, shf) /* Set up an existing shf (and buffer) to use the given fd */ struct shf * -shf_reopen(fd, sflags, shf) - int fd; - int sflags; - struct shf *shf; +shf_reopen(int fd, int sflags, struct shf *shf) { int bsize = sflags & SHF_UNBUF ? (sflags & SHF_RD ? 1 : 0) : SHF_BSIZE; @@ -174,11 +164,7 @@ shf_reopen(fd, sflags, shf) * When writing, a byte is reserved for a trailing null - see shf_sclose(). */ struct shf * -shf_sopen(buf, bsize, sflags, shf) - char *buf; - int bsize; - int sflags; - struct shf *shf; +shf_sopen(char *buf, int bsize, int sflags, struct shf *shf) { /* can't have a read+write string */ if (!(sflags & (SHF_RD | SHF_WR)) @@ -211,8 +197,7 @@ shf_sopen(buf, bsize, sflags, shf) /* Flush and close file descriptor, free the shf structure */ int -shf_close(shf) - struct shf *shf; +shf_close(struct shf *shf) { int ret = 0; @@ -231,8 +216,7 @@ shf_close(shf) /* Flush and close file descriptor, don't free file structure */ int -shf_fdclose(shf) - struct shf *shf; +shf_fdclose(struct shf *shf) { int ret = 0; @@ -254,8 +238,7 @@ shf_fdclose(shf) * (does not free string if it was allocated). */ char * -shf_sclose(shf) - struct shf *shf; +shf_sclose(struct shf *shf) { unsigned char *s = shf->buf; @@ -271,8 +254,7 @@ shf_sclose(shf) /* Flush and free file structure, don't close file descriptor */ int -shf_finish(shf) - struct shf *shf; +shf_finish(struct shf *shf) { int ret = 0; @@ -290,8 +272,7 @@ shf_finish(shf) * buffered. Returns 0 for success, EOF for (write) error. */ int -shf_flush(shf) - struct shf *shf; +shf_flush(struct shf *shf) { if (shf->flags & SHF_STRING) return (shf->flags & SHF_WR) ? EOF : 0; @@ -322,9 +303,7 @@ shf_flush(shf) * buffer. Returns 0 for success, EOF for (write) error. */ static int -shf_emptybuf(shf, flags) - struct shf *shf; - int flags; +shf_emptybuf(struct shf *shf, int flags) { int ret = 0; @@ -404,8 +383,7 @@ shf_emptybuf(shf, flags) /* Fill up a read buffer. Returns EOF for a read error, 0 otherwise. */ static int -shf_fillbuf(shf) - struct shf *shf; +shf_fillbuf(struct shf *shf) { if (shf->flags & SHF_STRING) return 0; @@ -451,10 +429,7 @@ shf_fillbuf(shf) * buffer. Returns 0 for success, EOF otherwise. */ int -shf_seek(shf, where, from) - struct shf *shf; - off_t where; - int from; +shf_seek(struct shf *shf, off_t where, int from) { if (shf->fd < 0) { errno = EINVAL; @@ -499,10 +474,7 @@ shf_seek(shf, where, from) * a read error occurred. */ int -shf_read(buf, bsize, shf) - char *buf; - int bsize; - struct shf *shf; +shf_read(char *buf, int bsize, struct shf *shf) { int orig_bsize = bsize; int ncopy; @@ -536,10 +508,7 @@ shf_read(buf, bsize, shf) * end of file, returns a pointer to the null byte in buf otherwise. */ char * -shf_getse(buf, bsize, shf) - char *buf; - int bsize; - struct shf *shf; +shf_getse(char *buf, int bsize, struct shf *shf) { unsigned char *end; int ncopy; @@ -578,8 +547,7 @@ shf_getse(buf, bsize, shf) /* Returns the char read. Returns EOF for error and end of file. */ int -shf_getchar(shf) - struct shf *shf; +shf_getchar(struct shf *shf) { if (!(shf->flags & SHF_RD)) internal_errorf(1, "shf_getchar: flags %x", shf->flags); @@ -594,9 +562,7 @@ shf_getchar(shf) * successful, EOF if there is no room. */ int -shf_ungetc(c, shf) - int c; - struct shf *shf; +shf_ungetc(int c, struct shf *shf) { if (!(shf->flags & SHF_RD)) internal_errorf(1, "shf_ungetc: flags %x", shf->flags); @@ -631,9 +597,7 @@ shf_ungetc(c, shf) * the char could not be written. */ int -shf_putchar(c, shf) - int c; - struct shf *shf; +shf_putchar(int c, struct shf *shf) { if (!(shf->flags & SHF_WR)) internal_errorf(1, "shf_putchar: flags %x", shf->flags); @@ -675,9 +639,7 @@ shf_putchar(c, shf) * the string could not be written. */ int -shf_puts(s, shf) - const char *s; - struct shf *shf; +shf_puts(const char *s, struct shf *shf) { if (!s) return EOF; @@ -687,10 +649,7 @@ shf_puts(s, shf) /* Write a buffer. Returns nbytes if successful, EOF if there is an error. */ int -shf_write(buf, nbytes, shf) - const char *buf; - int nbytes; - struct shf *shf; +shf_write(const char *buf, int nbytes, struct shf *shf) { int orig_nbytes = nbytes; int n; @@ -843,8 +802,7 @@ shf_smprintf(const char *fmt, ...) #include <math.h> static double -my_ceil(d) - double d; +my_ceil(double d) { double i; @@ -853,10 +811,7 @@ my_ceil(d) #endif /* FP */ int -shf_vfprintf(shf, fmt, args) - struct shf *shf; - const char *fmt; - va_list args; +shf_vfprintf(struct shf *shf, const char *fmt, va_list args) { char c, *s; int tmp = 0; |