X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Ffb-file.c;h=915c1b40f78018ff4478eae894af59d487ca9fd7;hb=997624f88f37bec5cb96cf9fc3b3cac05ccc6ed8;hp=c33698e9d0d815738ef39eb0143dde933832549a;hpb=61da975c346c50ccf9bb9cb7271ef538dc15ab32;p=libucw.git diff --git a/lib/fb-file.c b/lib/fb-file.c index c33698e9..915c1b40 100644 --- a/lib/fb-file.c +++ b/lib/fb-file.c @@ -1,8 +1,7 @@ /* * Sherlock Library -- Fast Buffered I/O on Files * - * (c) 1997--2002 Martin Mares - * (c) 2004 Robert Spalek + * (c) 1997--2004 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -21,17 +20,17 @@ struct fb_file { struct fastbuf fb; int fd; /* File descriptor, -1 if not a real file */ int is_temp_file; /* 0=normal file, 1=temporary file, delete on close, -1=shared FD */ - int can_overwrite; }; #define FB_FILE(f) ((struct fb_file *)(f)->is_fastbuf) +#define FB_BUFFER(f) (byte *)(FB_FILE(f) + 1) static int bfd_refill(struct fastbuf *f) { + f->bptr = f->buffer = FB_BUFFER(f); int l = read(FB_FILE(f)->fd, f->buffer, f->bufend-f->buffer); if (l < 0) die("Error reading %s: %m", f->name); - f->bptr = f->buffer; f->bstop = f->buffer + l; f->pos += l; return l; @@ -41,7 +40,7 @@ static void bfd_spout(struct fastbuf *f) { int l = f->bptr - f->buffer; - char *c = f->buffer; + byte *c = f->buffer; f->pos += l; while (l) @@ -52,7 +51,7 @@ bfd_spout(struct fastbuf *f) l -= z; c += z; } - f->bptr = f->buffer; + f->bptr = f->buffer = FB_BUFFER(f); } static void @@ -91,11 +90,6 @@ bfd_config(struct fastbuf *f, uns item, int value) case BCONFIG_IS_TEMP_FILE: FB_FILE(f)->is_temp_file = value; return 0; - case BCONFIG_CAN_OVERWRITE: ; - int old_value = FB_FILE(f)->can_overwrite; - if (value >= 0 && value <= 2) - FB_FILE(f)->can_overwrite = value; - return old_value; default: return -1; } @@ -109,7 +103,7 @@ bfdopen_internal(int fd, uns buflen, byte *name) struct fastbuf *f = &F->fb; bzero(F, sizeof(*F)); - f->buffer = (char *)(F+1); + f->buffer = (byte *)(F+1); f->bptr = f->bstop = f->buffer; f->bufend = f->buffer + buflen; f->name = f->bufend; @@ -120,41 +114,41 @@ bfdopen_internal(int fd, uns buflen, byte *name) f->seek = bfd_seek; f->close = bfd_close; f->config = bfd_config; - F->can_overwrite = 2; + f->can_overwrite_buffer = 2; return f; } struct fastbuf * -bopen(byte *name, uns mode, uns buffer) +bopen(byte *name, uns mode, uns buflen) { struct fastbuf *b; int fd; - if (!buffer) + if (!buflen) return bopen_mm(name, mode); fd = sh_open(name, mode, 0666); if (fd < 0) die("Unable to %s file %s: %m", (mode & O_CREAT) ? "create" : "open", name); - b = bfdopen_internal(fd, buffer, name); + b = bfdopen_internal(fd, buflen, name); if (mode & O_APPEND) bfd_seek(b, 0, SEEK_END); return b; } struct fastbuf * -bfdopen(int fd, uns buffer) +bfdopen(int fd, uns buflen) { byte x[32]; sprintf(x, "fd%d", fd); - return bfdopen_internal(fd, buffer, x); + return bfdopen_internal(fd, buflen, x); } struct fastbuf * -bfdopen_shared(int fd, uns buffer) +bfdopen_shared(int fd, uns buflen) { - struct fastbuf *f = bfdopen(fd, buffer); + struct fastbuf *f = bfdopen(fd, buflen); FB_FILE(f)->is_temp_file = -1; return f; }