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>
|
#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__)
|
#if defined(__sgi) && !defined(__GNUC__)
|
||||||
# pragma set woff 1375 /* base class destructor not virtual */
|
# pragma set woff 1375 /* base class destructor not virtual */
|
||||||
#endif
|
#endif
|
||||||
@ -1360,18 +1367,13 @@ bool cmSystemTools::IsPathToFramework(const char* path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||||
# include <libtar/libtar.h>
|
|
||||||
# include <memory> // auto_ptr
|
|
||||||
# include <fcntl.h>
|
|
||||||
# include <cmzlib/zlib.h>
|
|
||||||
|
|
||||||
struct cmSystemToolsGZStruct
|
struct cmSystemToolsGZStruct
|
||||||
{
|
{
|
||||||
gzFile GZFile;
|
gzFile GZFile;
|
||||||
static int Open(void* call_data, const char *pathname, int oflags, mode_t mode);
|
static int Open(void* call_data, const char *pathname, int oflags, mode_t mode);
|
||||||
static int Close(void* call_data, int fd);
|
static int Close(void* call_data);
|
||||||
static ssize_t Read(void* call_data, int fd, void* buf, size_t count);
|
static ssize_t Read(void* call_data, void* buf, size_t count);
|
||||||
static ssize_t Write(void* call_data, int fd, const 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)
|
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;
|
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);
|
cmSystemToolsGZStruct* gzf = static_cast<cmSystemToolsGZStruct*>(call_data);
|
||||||
return cm_zlib_gzclose(gzf->GZFile);
|
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);
|
cmSystemToolsGZStruct* gzf = static_cast<cmSystemToolsGZStruct*>(call_data);
|
||||||
return cm_zlib_gzread(gzf->GZFile, buf, count);
|
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);
|
cmSystemToolsGZStruct* gzf = static_cast<cmSystemToolsGZStruct*>(call_data);
|
||||||
return cm_zlib_gzwrite(gzf->GZFile, (void*)buf, count);
|
return cm_zlib_gzwrite(gzf->GZFile, (void*)buf, count);
|
||||||
}
|
}
|
||||||
|
@ -34,29 +34,37 @@
|
|||||||
|
|
||||||
const char libtar_version[] = PACKAGE_VERSION;
|
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)
|
static int libtar_open(void* call_data, const char* pathname, int flags, mode_t mode)
|
||||||
{
|
{
|
||||||
(void)call_data;
|
struct libtar_fd_file* lf = (struct libtar_fd_file*)call_data;
|
||||||
return open(pathname, flags, mode);
|
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;
|
struct libtar_fd_file* lf = (struct libtar_fd_file*)call_data;
|
||||||
return close(fd);
|
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;
|
struct libtar_fd_file* lf = (struct libtar_fd_file*)call_data;
|
||||||
return read(fd, buf, count);
|
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;
|
struct libtar_fd_file* lf = (struct libtar_fd_file*)call_data;
|
||||||
return write(fd, buf, count);
|
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
|
static int
|
||||||
tar_init(TAR **t, char *pathname, tartype_t *type,
|
tar_init(TAR **t, char *pathname, tartype_t *type,
|
||||||
@ -98,6 +106,7 @@ int
|
|||||||
tar_open(TAR **t, char *pathname, tartype_t *type,
|
tar_open(TAR **t, char *pathname, tartype_t *type,
|
||||||
int oflags, int mode, int options)
|
int oflags, int mode, int options)
|
||||||
{
|
{
|
||||||
|
int res;
|
||||||
if (tar_init(t, pathname, type, oflags, mode, options) == -1)
|
if (tar_init(t, pathname, type, oflags, mode, options) == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -108,8 +117,8 @@ tar_open(TAR **t, char *pathname, tartype_t *type,
|
|||||||
oflags |= O_BINARY;
|
oflags |= O_BINARY;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
(*t)->fd = (*((*t)->type->openfunc))((*t)->type->call_data, pathname, oflags, mode);
|
res = (*((*t)->type->openfunc))((*t)->type->call_data, pathname, oflags, mode);
|
||||||
if ((*t)->fd == -1)
|
if (res == -1)
|
||||||
{
|
{
|
||||||
free(*t);
|
free(*t);
|
||||||
return -1;
|
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)
|
if (tar_init(t, pathname, type, oflags, mode, options) == -1)
|
||||||
return -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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
tar_fd(TAR *t)
|
|
||||||
{
|
|
||||||
return t->fd;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* close tarfile handle */
|
/* close tarfile handle */
|
||||||
int
|
int
|
||||||
tar_close(TAR *t)
|
tar_close(TAR *t)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = (*(t->type->closefunc))(t->type->call_data, t->fd);
|
i = (*(t->type->closefunc))(t->type->call_data);
|
||||||
|
|
||||||
if (t->h != NULL)
|
if (t->h != NULL)
|
||||||
libtar_hash_free(t->h, ((t->oflags & O_ACCMODE) == O_RDONLY
|
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;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
int libtar_gzclose(void* call_data, int fd)
|
int libtar_gzclose(void* call_data)
|
||||||
{
|
{
|
||||||
struct gzStruct* gzf = (struct gzStruct*)call_data;
|
struct gzStruct* gzf = (struct gzStruct*)call_data;
|
||||||
(void)fd;
|
|
||||||
return cm_zlib_gzclose(gzf->GZFile);
|
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;
|
struct gzStruct* gzf = (struct gzStruct*)call_data;
|
||||||
(void)fd;
|
|
||||||
return cm_zlib_gzread(gzf->GZFile, buf, count);
|
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;
|
struct gzStruct* gzf = (struct gzStruct*)call_data;
|
||||||
(void)fd;
|
|
||||||
return cm_zlib_gzwrite(gzf->GZFile, (void*)buf, count);
|
return cm_zlib_gzwrite(gzf->GZFile, (void*)buf, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,8 +20,7 @@
|
|||||||
#include <libtar/libtar_listhash.h>
|
#include <libtar/libtar_listhash.h>
|
||||||
#include <libtar/compat.h>
|
#include <libtar/compat.h>
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C" {
|
||||||
{
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -63,9 +62,9 @@ struct tar_header
|
|||||||
/***** handle.c ************************************************************/
|
/***** handle.c ************************************************************/
|
||||||
|
|
||||||
typedef int (*openfunc_t)(void* call_data, const char *, int, mode_t);
|
typedef int (*openfunc_t)(void* call_data, const char *, int, mode_t);
|
||||||
typedef int (*closefunc_t)(void* call_data, int);
|
typedef int (*closefunc_t)(void* call_data);
|
||||||
typedef ssize_t (*readfunc_t)(void* call_data, int, void *, size_t);
|
typedef ssize_t (*readfunc_t)(void* call_data, void *, size_t);
|
||||||
typedef ssize_t (*writefunc_t)(void* call_data, int, const void *, size_t);
|
typedef ssize_t (*writefunc_t)(void* call_data, const void *, size_t);
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@ -81,7 +80,6 @@ typedef struct
|
|||||||
{
|
{
|
||||||
tartype_t *type;
|
tartype_t *type;
|
||||||
char *pathname;
|
char *pathname;
|
||||||
long fd;
|
|
||||||
int oflags;
|
int oflags;
|
||||||
int options;
|
int options;
|
||||||
struct tar_header th_buf;
|
struct tar_header th_buf;
|
||||||
@ -103,7 +101,6 @@ TAR;
|
|||||||
|
|
||||||
extern const char libtar_version[];
|
extern const char libtar_version[];
|
||||||
|
|
||||||
|
|
||||||
/* open a new tarfile handle */
|
/* open a new tarfile handle */
|
||||||
int tar_open(TAR **t, char *pathname, tartype_t *type,
|
int tar_open(TAR **t, char *pathname, tartype_t *type,
|
||||||
int oflags, int mode, int options);
|
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 tar_fdopen(TAR **t, int fd, char *pathname, tartype_t *type,
|
||||||
int oflags, int mode, int options);
|
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 */
|
/* close tarfile handle */
|
||||||
int tar_close(TAR *t);
|
int tar_close(TAR *t);
|
||||||
|
|
||||||
@ -152,9 +140,9 @@ int tar_append_regfile(TAR *t, char *realname);
|
|||||||
|
|
||||||
/* macros for reading/writing tarchive blocks */
|
/* macros for reading/writing tarchive blocks */
|
||||||
#define tar_block_read(t, buf) \
|
#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) \
|
#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 */
|
/* read/write a header block */
|
||||||
int th_read(TAR *t);
|
int th_read(TAR *t);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user