From 6e1e67a5221c1c31c8dffe8705e6a450f302ba8b Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Thu, 9 Feb 2012 23:09:46 +0100 Subject: [PATCH] More modules moved to io.h and renamed to io-*.c This includes carefulio, mmap, file_size() and sync. --- ucw/Makefile | 6 +++--- ucw/{carefulio.c => io-careful.c} | 3 ++- ucw/{mmap.c => io-mmap.c} | 3 ++- ucw/io-size.c | 21 +++++++++++++++++++++ ucw/{sync.c => io-sync.c} | 3 ++- ucw/io.h | 27 +++++++++++++++++---------- ucw/lib.h | 14 -------------- 7 files changed, 47 insertions(+), 30 deletions(-) rename ucw/{carefulio.c => io-careful.c} (92%) rename ucw/{mmap.c => io-mmap.c} (93%) create mode 100644 ucw/io-size.c rename ucw/{sync.c => io-sync.c} (85%) diff --git a/ucw/Makefile b/ucw/Makefile index 6c44266b..d33b01fb 100644 --- a/ucw/Makefile +++ b/ucw/Makefile @@ -10,13 +10,13 @@ endif LIBUCW_MODS= \ threads \ alloc alloc_str realloc bigalloc mempool mempool-str mempool-fmt eltpool \ - mmap partmap hashfunc \ + partmap hashfunc \ slists simple-lists bitsig \ log log-stream log-file log-syslog log-conf proctitle tbf \ conf-alloc conf-dump conf-input conf-intr conf-journal conf-parse conf-section \ ipaccess \ fastbuf ff-binary ff-string ff-printf ff-unicode ff-stkstring \ - fb-file carefulio fb-mem fb-temp tempfile fb-mmap fb-limfd fb-buffer fb-grow fb-pool fb-atomic fb-param fb-socket \ + fb-file fb-mem fb-temp tempfile fb-mmap fb-limfd fb-buffer fb-grow fb-pool fb-atomic fb-param fb-socket \ char-cat char-upper char-lower unicode stkstring \ wildmatch regex \ prime primetable random timer \ @@ -27,7 +27,7 @@ LIBUCW_MODS= \ lizard lizard-safe adler32 \ md5 sha1 sha1-hmac \ base64 base224 \ - sync \ + io-careful io-sync io-mmap io-size \ qache \ string str-esc str-split str-match str-imatch str-hex \ bbuf gary \ diff --git a/ucw/carefulio.c b/ucw/io-careful.c similarity index 92% rename from ucw/carefulio.c rename to ucw/io-careful.c index 44e01e14..21b3678e 100644 --- a/ucw/carefulio.c +++ b/ucw/io-careful.c @@ -1,13 +1,14 @@ /* * UCW Library -- Careful Read/Write * - * (c) 2004 Martin Mares + * (c) 2004--2012 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. */ #include "ucw/lib.h" +#include "ucw/io.h" #include diff --git a/ucw/mmap.c b/ucw/io-mmap.c similarity index 93% rename from ucw/mmap.c rename to ucw/io-mmap.c index 6b982369..30000b00 100644 --- a/ucw/mmap.c +++ b/ucw/io-mmap.c @@ -1,13 +1,14 @@ /* * UCW Library -- Mapping of Files * - * (c) 1999--2002 Martin Mares + * (c) 1999--2012 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. */ #include "ucw/lib.h" +#include "ucw/io.h" #include #include diff --git a/ucw/io-size.c b/ucw/io-size.c new file mode 100644 index 00000000..547aee56 --- /dev/null +++ b/ucw/io-size.c @@ -0,0 +1,21 @@ +/* + * UCW Library -- File Sizes + * + * (c) 1999--2012 Martin Mares + * + * This software may be freely distributed and used according to the terms + * of the GNU Lesser General Public License. + */ + +#include "ucw/lib.h" +#include "ucw/io.h" + +ucw_off_t ucw_file_size(const char *name) +{ + int fd = ucw_open(name, O_RDONLY); + if (fd < 0) + die("Cannot open %s: %m", name); + ucw_off_t len = ucw_seek(fd, 0, SEEK_END); + close(fd); + return len; +} diff --git a/ucw/sync.c b/ucw/io-sync.c similarity index 85% rename from ucw/sync.c rename to ucw/io-sync.c index 0f3ef788..08ac93fa 100644 --- a/ucw/sync.c +++ b/ucw/io-sync.c @@ -1,10 +1,11 @@ /* * UCW Library -- Syncing Directories * - * (c) 2004--2005 Martin Mares + * (c) 2004--2012 Martin Mares */ #include "ucw/lib.h" +#include "ucw/io.h" #include #include diff --git a/ucw/io.h b/ucw/io.h index 593dcf7d..aa36f936 100644 --- a/ucw/io.h +++ b/ucw/io.h @@ -49,15 +49,22 @@ typedef struct stat ucw_stat_t; #define HAVE_PREAD -static inline ucw_off_t -ucw_file_size(const char *name) -{ - int fd = ucw_open(name, O_RDONLY); - if (fd < 0) - die("Cannot open %s: %m", name); - ucw_off_t len = ucw_seek(fd, 0, SEEK_END); - close(fd); - return len; -} +/* io-size.c */ + +ucw_off_t ucw_file_size(const char *name); + +/* io-mmap.c */ + +void *mmap_file(const char *name, unsigned *len, int writeable); +void munmap_file(void *start, unsigned len); + +/* io-careful.c */ + +int careful_read(int fd, void *buf, int len); +int careful_write(int fd, const void *buf, int len); + +/* io-sync.c */ + +void sync_dir(const char *name); #endif /* !_UCW_LFS_H */ diff --git a/ucw/lib.h b/ucw/lib.h index ec984888..2b76b7a3 100644 --- a/ucw/lib.h +++ b/ucw/lib.h @@ -181,11 +181,6 @@ uns random_max(uns max); /** Return a pseudorandom 32-bit number in range [0,@ u64 random_u64(void); /** Return a pseudorandom 64-bit number. **/ u64 random_max_u64(u64 max); /** Return a pseudorandom 64-bit number in range [0,@max). **/ -/* mmap.c */ - -void *mmap_file(const char *name, unsigned *len, int writeable); -void munmap_file(void *start, unsigned len); - /* proctitle.c */ void setproctitle_init(int argc, char **argv); @@ -206,15 +201,6 @@ int run_command_v(const char *cmd, va_list args); void NONRET exec_command_v(const char *cmd, va_list args); void echo_command_v(char *buf, int size, const char *cmd, va_list args); -/* carefulio.c */ - -int careful_read(int fd, void *buf, int len); -int careful_write(int fd, const void *buf, int len); - -/* sync.c */ - -void sync_dir(const char *name); - /* sighandler.c */ typedef int (*ucw_sighandler_t)(int); // gets signum, returns nonzero if abort() should be called -- 2.39.2