X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Ffb-mmap.c;h=a57d1034c32b04cfdaa4aec66912a633d7b4ee5d;hb=aafbea40b7613274180c8bab60012a0322f8d7dd;hp=15c542a07082bbc0f1a0f4d23d9d334596b9d461;hpb=87b27e3e532a51e97407cd6f54533138d78ebd01;p=libucw.git diff --git a/lib/fb-mmap.c b/lib/fb-mmap.c index 15c542a0..a57d1034 100644 --- a/lib/fb-mmap.c +++ b/lib/fb-mmap.c @@ -7,6 +7,8 @@ * of the GNU Lesser General Public License. */ +#undef LOCAL_DEBUG + #include "lib/lib.h" #include "lib/fastbuf.h" #include "lib/lfs.h" @@ -142,33 +144,28 @@ bfmm_close(struct fastbuf *f) if (F->file_extend > F->file_size && sh_ftruncate(F->fd, F->file_size)) die("ftruncate(%s): %m", f->name); - switch (F->is_temp_file) - { - case 1: - if (unlink(f->name) < 0) - log(L_ERROR, "unlink(%s): %m", f->name); - case 0: - if (close(F->fd)) - die("close(%s): %m", f->name); - } + bclose_file_helper(f, F->fd, F->is_temp_file); xfree(f); } static int bfmm_config(struct fastbuf *f, uns item, int value) { + int orig; + switch (item) { case BCONFIG_IS_TEMP_FILE: + orig = FB_MMAP(f)->is_temp_file; FB_MMAP(f)->is_temp_file = value; - return 0; + return orig; default: return -1; } } struct fastbuf * -bfmmopen_internal(int fd, byte *name, uns mode) +bfmmopen_internal(int fd, const char *name, uns mode) { int namelen = strlen(name) + 1; struct fb_mmap *F = xmalloc(sizeof(struct fb_mmap) + namelen); @@ -197,8 +194,9 @@ bfmmopen_internal(int fd, byte *name, uns mode) int main(int argc, char **argv) { - struct fastbuf *f = bopen_mm(argv[1], O_RDONLY); - struct fastbuf *g = bopen_mm(argv[2], O_RDWR | O_CREAT | O_TRUNC); + struct fb_params par = { .type = FB_MMAP }; + struct fastbuf *f = bopen_file(argv[1], O_RDONLY, &par); + struct fastbuf *g = bopen_file(argv[2], O_RDWR | O_CREAT | O_TRUNC, &par); int c; DBG("Copying");