diff options
author | Andy Cedilnik <andy.cedilnik@kitware.com> | 2005-12-30 19:51:15 (GMT) |
---|---|---|
committer | Andy Cedilnik <andy.cedilnik@kitware.com> | 2005-12-30 19:51:15 (GMT) |
commit | bb618a7db5fb9df2770c29bc9d86e1c198325504 (patch) | |
tree | e610bdabe3f6ef5c228ca81fe31b949eb81805c8 /Utilities/cmtar | |
parent | 8b9512559dab2ed2a9bca1052b74c899d8983b49 (diff) | |
download | CMake-bb618a7db5fb9df2770c29bc9d86e1c198325504.zip CMake-bb618a7db5fb9df2770c29bc9d86e1c198325504.tar.gz CMake-bb618a7db5fb9df2770c29bc9d86e1c198325504.tar.bz2 |
ENH: Cleanup the file handler stuf so that now any file descriptor type can be used
Diffstat (limited to 'Utilities/cmtar')
-rw-r--r-- | Utilities/cmtar/handle.c | 53 | ||||
-rw-r--r-- | Utilities/cmtar/libtar.c | 9 | ||||
-rw-r--r-- | Utilities/cmtar/libtar.h | 24 |
3 files changed, 38 insertions, 48 deletions
diff --git a/Utilities/cmtar/handle.c b/Utilities/cmtar/handle.c index 6770b2b..4b9a169 100644 --- a/Utilities/cmtar/handle.c +++ b/Utilities/cmtar/handle.c @@ -34,29 +34,37 @@ const char libtar_version[] = PACKAGE_VERSION; +struct libtar_fd_file +{ + int fd; +}; + +static struct libtar_fd_file libtar_fd_file_pointer; + static int libtar_open(void* call_data, const char* pathname, int flags, mode_t mode) { - (void)call_data; - return open(pathname, flags, mode); + struct libtar_fd_file* lf = (struct libtar_fd_file*)call_data; + lf->fd = open(pathname, flags, mode); + return lf->fd; } -static int libtar_close(void* call_data, int fd) +static int libtar_close(void* call_data) { - (void)call_data; - return close(fd); + struct libtar_fd_file* lf = (struct libtar_fd_file*)call_data; + return close(lf->fd); } -static ssize_t libtar_read(void* call_data, int fd, void* buf, size_t count) +static ssize_t libtar_read(void* call_data, void* buf, size_t count) { - (void)call_data; - return read(fd, buf, count); + struct libtar_fd_file* lf = (struct libtar_fd_file*)call_data; + return read(lf->fd, buf, count); } -static ssize_t libtar_write(void* call_data, int fd, const void* buf, size_t count) +static ssize_t libtar_write(void* call_data, const void* buf, size_t count) { - (void)call_data; - return write(fd, buf, count); + struct libtar_fd_file* lf = (struct libtar_fd_file*)call_data; + return write(lf->fd, buf, count); } -static tartype_t default_type = { libtar_open, libtar_close, libtar_read, libtar_write, 0 }; +static tartype_t default_type = { libtar_open, libtar_close, libtar_read, libtar_write, &libtar_fd_file_pointer }; static int tar_init(TAR **t, char *pathname, tartype_t *type, @@ -98,6 +106,7 @@ int tar_open(TAR **t, char *pathname, tartype_t *type, int oflags, int mode, int options) { + int res; if (tar_init(t, pathname, type, oflags, mode, options) == -1) return -1; @@ -108,8 +117,8 @@ tar_open(TAR **t, char *pathname, tartype_t *type, oflags |= O_BINARY; #endif - (*t)->fd = (*((*t)->type->openfunc))((*t)->type->call_data, pathname, oflags, mode); - if ((*t)->fd == -1) + res = (*((*t)->type->openfunc))((*t)->type->call_data, pathname, oflags, mode); + if (res == -1) { free(*t); return -1; @@ -126,25 +135,21 @@ tar_fdopen(TAR **t, int fd, char *pathname, tartype_t *type, if (tar_init(t, pathname, type, oflags, mode, options) == -1) return -1; - (*t)->fd = fd; + if ( !type ) + { + struct libtar_fd_file* lf = (struct libtar_fd_file*)((*t)->type->call_data); + lf->fd = fd; + } return 0; } - -int -tar_fd(TAR *t) -{ - return t->fd; -} - - /* close tarfile handle */ int tar_close(TAR *t) { int i; - i = (*(t->type->closefunc))(t->type->call_data, t->fd); + i = (*(t->type->closefunc))(t->type->call_data); if (t->h != NULL) libtar_hash_free(t->h, ((t->oflags & O_ACCMODE) == O_RDONLY diff --git a/Utilities/cmtar/libtar.c b/Utilities/cmtar/libtar.c index 58326b0..a4c9741 100644 --- a/Utilities/cmtar/libtar.c +++ b/Utilities/cmtar/libtar.c @@ -110,24 +110,21 @@ int libtar_gzopen(void* call_data, const char *pathname, int oflags, mode_t mode return fd; } -int libtar_gzclose(void* call_data, int fd) +int libtar_gzclose(void* call_data) { struct gzStruct* gzf = (struct gzStruct*)call_data; - (void)fd; return cm_zlib_gzclose(gzf->GZFile); } -ssize_t libtar_gzread(void* call_data, int fd, void* buf, size_t count) +ssize_t libtar_gzread(void* call_data, void* buf, size_t count) { struct gzStruct* gzf = (struct gzStruct*)call_data; - (void)fd; return cm_zlib_gzread(gzf->GZFile, buf, count); } -ssize_t libtar_gzwrite(void* call_data, int fd, const void* buf, size_t count) +ssize_t libtar_gzwrite(void* call_data, const void* buf, size_t count) { struct gzStruct* gzf = (struct gzStruct*)call_data; - (void)fd; return cm_zlib_gzwrite(gzf->GZFile, (void*)buf, count); } diff --git a/Utilities/cmtar/libtar.h b/Utilities/cmtar/libtar.h index 9990a97..fb87e5b 100644 --- a/Utilities/cmtar/libtar.h +++ b/Utilities/cmtar/libtar.h @@ -20,8 +20,7 @@ #include <libtar/libtar_listhash.h> #include <libtar/compat.h> #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif @@ -63,9 +62,9 @@ struct tar_header /***** handle.c ************************************************************/ typedef int (*openfunc_t)(void* call_data, const char *, int, mode_t); -typedef int (*closefunc_t)(void* call_data, int); -typedef ssize_t (*readfunc_t)(void* call_data, int, void *, size_t); -typedef ssize_t (*writefunc_t)(void* call_data, int, const void *, size_t); +typedef int (*closefunc_t)(void* call_data); +typedef ssize_t (*readfunc_t)(void* call_data, void *, size_t); +typedef ssize_t (*writefunc_t)(void* call_data, const void *, size_t); typedef struct { @@ -81,7 +80,6 @@ typedef struct { tartype_t *type; char *pathname; - long fd; int oflags; int options; struct tar_header th_buf; @@ -103,7 +101,6 @@ TAR; extern const char libtar_version[]; - /* open a new tarfile handle */ int tar_open(TAR **t, char *pathname, tartype_t *type, int oflags, int mode, int options); @@ -112,15 +109,6 @@ int tar_open(TAR **t, char *pathname, tartype_t *type, int tar_fdopen(TAR **t, int fd, char *pathname, tartype_t *type, int oflags, int mode, int options); -/* returns the descriptor associated with t */ -int tar_fd(TAR *t); - -/* returns the descriptor associated with t */ -void* tar_call_data(TAR *t); - -/* returns the descriptor associated with t */ -void tar_set_call_data(TAR *t, void* cd); - /* close tarfile handle */ int tar_close(TAR *t); @@ -152,9 +140,9 @@ int tar_append_regfile(TAR *t, char *realname); /* macros for reading/writing tarchive blocks */ #define tar_block_read(t, buf) \ - (*((t)->type->readfunc))((t)->type->call_data, (t)->fd, (char *)(buf), T_BLOCKSIZE) + (*((t)->type->readfunc))((t)->type->call_data, (char *)(buf), T_BLOCKSIZE) #define tar_block_write(t, buf) \ - (*((t)->type->writefunc))((t)->type->call_data, (t)->fd, (char *)(buf), T_BLOCKSIZE) + (*((t)->type->writefunc))((t)->type->call_data, (char *)(buf), T_BLOCKSIZE) /* read/write a header block */ int th_read(TAR *t); |