ENH: Cleanup the file handler stuf so that now any file descriptor type can be used
This commit is contained in:
parent
8b9512559d
commit
bb618a7db5
|
@ -45,6 +45,13 @@
|
|||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||
# include <libtar/libtar.h>
|
||||
# include <memory> // auto_ptr
|
||||
# include <fcntl.h>
|
||||
# include <cmzlib/zlib.h>
|
||||
#endif
|
||||
|
||||
#if defined(__sgi) && !defined(__GNUC__)
|
||||
# pragma set woff 1375 /* base class destructor not virtual */
|
||||
#endif
|
||||
|
@ -1360,18 +1367,13 @@ bool cmSystemTools::IsPathToFramework(const char* path)
|
|||
}
|
||||
|
||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||
# include <libtar/libtar.h>
|
||||
# include <memory> // auto_ptr
|
||||
# include <fcntl.h>
|
||||
# include <cmzlib/zlib.h>
|
||||
|
||||
struct cmSystemToolsGZStruct
|
||||
{
|
||||
gzFile GZFile;
|
||||
static int Open(void* call_data, const char *pathname, int oflags, mode_t mode);
|
||||
static int Close(void* call_data, int fd);
|
||||
static ssize_t Read(void* call_data, int fd, void* buf, size_t count);
|
||||
static ssize_t Write(void* call_data, int fd, const void* buf, size_t count);
|
||||
static int Close(void* call_data);
|
||||
static ssize_t Read(void* call_data, void* buf, size_t count);
|
||||
static ssize_t Write(void* call_data, const void* buf, size_t count);
|
||||
};
|
||||
|
||||
int cmSystemToolsGZStruct::Open(void* call_data, const char *pathname, int oflags, mode_t mode)
|
||||
|
@ -1418,23 +1420,20 @@ int cmSystemToolsGZStruct::Open(void* call_data, const char *pathname, int oflag
|
|||
return fd;
|
||||
}
|
||||
|
||||
int cmSystemToolsGZStruct::Close(void* call_data, int fd)
|
||||
int cmSystemToolsGZStruct::Close(void* call_data)
|
||||
{
|
||||
(void)fd;
|
||||
cmSystemToolsGZStruct* gzf = static_cast<cmSystemToolsGZStruct*>(call_data);
|
||||
return cm_zlib_gzclose(gzf->GZFile);
|
||||
}
|
||||
|
||||
ssize_t cmSystemToolsGZStruct::Read(void* call_data, int fd, void* buf, size_t count)
|
||||
ssize_t cmSystemToolsGZStruct::Read(void* call_data, void* buf, size_t count)
|
||||
{
|
||||
(void)fd;
|
||||
cmSystemToolsGZStruct* gzf = static_cast<cmSystemToolsGZStruct*>(call_data);
|
||||
return cm_zlib_gzread(gzf->GZFile, buf, count);
|
||||
}
|
||||
|
||||
ssize_t cmSystemToolsGZStruct::Write(void* call_data, int fd, const void* buf, size_t count)
|
||||
ssize_t cmSystemToolsGZStruct::Write(void* call_data, const void* buf, size_t count)
|
||||
{
|
||||
(void)fd;
|
||||
cmSystemToolsGZStruct* gzf = static_cast<cmSystemToolsGZStruct*>(call_data);
|
||||
return cm_zlib_gzwrite(gzf->GZFile, (void*)buf, count);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue