From 18d31fd97c3305b54a6d1d56b6ef8600089ef6da Mon Sep 17 00:00:00 2001 From: Andy Cedilnik Date: Wed, 28 Dec 2005 14:58:07 -0500 Subject: [PATCH] COMP: Several borland fixes --- Utilities/cmtar/CMakeLists.txt | 6 +++++- Utilities/cmtar/append.c | 10 +++++----- Utilities/cmtar/compat/basename.c | 4 ++-- Utilities/cmtar/compat/compat.h | 9 +++++++++ Utilities/cmtar/compat/dirname.c | 4 ++-- Utilities/cmtar/decode.c | 8 ++++---- Utilities/cmtar/extract.c | 22 ++++++++++++++-------- Utilities/cmtar/filesystem.c | 4 +--- Utilities/cmtar/filesystem.h | 9 ++------- Utilities/cmtar/handle.c | 15 +++++++++++++++ Utilities/cmtar/internal.h | 1 - Utilities/cmtar/libtar.c | 2 +- Utilities/cmtar/util.c | 12 ++++++------ Utilities/cmtar/wrapper.c | 22 +++++++++++----------- 14 files changed, 77 insertions(+), 51 deletions(-) diff --git a/Utilities/cmtar/CMakeLists.txt b/Utilities/cmtar/CMakeLists.txt index 48a3efa29..7ffe0e184 100644 --- a/Utilities/cmtar/CMakeLists.txt +++ b/Utilities/cmtar/CMakeLists.txt @@ -290,7 +290,6 @@ SET(libtar_SRC output.c util.c wrapper.c - filesystem.c filesystem.h internal.h ${LIBTAR_BINARY_DIR}/libtar/config.h config.h.in @@ -304,6 +303,11 @@ SET(libtar_SRC # compat/strmode.c # compat/strsep.c ) +IF(NOT UNIX) + SET(libtar_SRC + ${libtar_SRC} + filesystem.c filesystem.h) +ENDIF(NOT UNIX) IF(NOT HAVE_STRLCPY) SET(libtar_SRC ${libtar_SRC} compat/strlcpy.c) diff --git a/Utilities/cmtar/append.c b/Utilities/cmtar/append.c index 5007c626f..77bb34fff 100644 --- a/Utilities/cmtar/append.c +++ b/Utilities/cmtar/append.c @@ -15,7 +15,7 @@ #include #include #include -#ifdef _MSC_VER +#if defined(_WIN32) && !defined(__CYGWIN__) # include #else # include @@ -45,7 +45,7 @@ typedef struct tar_dev tar_dev_t; struct tar_ino { ino_t ti_ino; - char ti_name[MAXPATHLEN]; + char ti_name[TAR_MAXPATHLEN]; }; typedef struct tar_ino tar_ino_t; @@ -68,7 +68,7 @@ tar_append_file(TAR *t, char *realname, char *savename) libtar_hashptr_t hp; tar_dev_t *td = NULL; tar_ino_t *ti = NULL; - char path[MAXPATHLEN]; + char path[TAR_MAXPATHLEN]; #ifdef DEBUG printf("==> tar_append_file(TAR=0x%lx (\"%s\"), realname=\"%s\", " @@ -162,8 +162,8 @@ tar_append_file(TAR *t, char *realname, char *savename) #endif if (i == -1) return -1; - if (i >= MAXPATHLEN) - i = MAXPATHLEN - 1; + if (i >= TAR_MAXPATHLEN) + i = TAR_MAXPATHLEN - 1; path[i] = '\0'; #ifdef DEBUG printf(" tar_append_file(): encoding symlink \"%s\" -> " diff --git a/Utilities/cmtar/compat/basename.c b/Utilities/cmtar/compat/basename.c index 3b87b0eb7..ddaf89d32 100644 --- a/Utilities/cmtar/compat/basename.c +++ b/Utilities/cmtar/compat/basename.c @@ -33,14 +33,14 @@ static char rcsid[] = "$OpenBSD: basename.c,v 1.4 1999/05/30 17:10:30 espie Exp #include #include -//#include #include +#include char * openbsd_basename(path) const char *path; { - static char bname[MAXPATHLEN]; + static char bname[TAR_MAXPATHLEN]; register const char *endp, *startp; /* Empty or NULL string gets treated as "." */ diff --git a/Utilities/cmtar/compat/compat.h b/Utilities/cmtar/compat/compat.h index 880f54b1a..f308b9951 100644 --- a/Utilities/cmtar/compat/compat.h +++ b/Utilities/cmtar/compat/compat.h @@ -312,3 +312,12 @@ char *strsep(register char **, register const char *); #endif #define S_ISFIFO(m) (((m)&S_IFFIFO)==S_IFFIFO) #endif + +#if defined(PATH_MAX) +# define TAR_MAXPATHLEN PATH_MAX +#elif defined(MAXPATHLEN) +# define TAR_MAXPATHLEN MAXPATHLEN +#else +# define TAR_MAXPATHLEN 16384 +#endif + diff --git a/Utilities/cmtar/compat/dirname.c b/Utilities/cmtar/compat/dirname.c index f322bbd7d..f05a3819d 100644 --- a/Utilities/cmtar/compat/dirname.c +++ b/Utilities/cmtar/compat/dirname.c @@ -33,14 +33,14 @@ static char rcsid[] = "$OpenBSD: dirname.c,v 1.4 1999/05/30 17:10:30 espie Exp $ #include #include -//#include #include +#include char * openbsd_dirname(path) const char *path; { - static char bname[MAXPATHLEN]; + static char bname[TAR_MAXPATHLEN]; register const char *endp; /* Empty or NULL string gets treated as "." */ diff --git a/Utilities/cmtar/decode.c b/Utilities/cmtar/decode.c index 178ffc0f6..788fb3fde 100644 --- a/Utilities/cmtar/decode.c +++ b/Utilities/cmtar/decode.c @@ -14,10 +14,10 @@ #include -#ifndef _MSC_VER -#include +#if defined(_WIN32) && !defined(__CYGWIN__) +# include #else -#include +# include #endif #ifndef WIN32 @@ -34,7 +34,7 @@ char * th_get_pathname(TAR *t) { - char filename[MAXPATHLEN]; + char filename[TAR_MAXPATHLEN]; if (t->th_buf.gnu_longname) return t->th_buf.gnu_longname; diff --git a/Utilities/cmtar/extract.c b/Utilities/cmtar/extract.c index 506dff164..7ceece194 100644 --- a/Utilities/cmtar/extract.c +++ b/Utilities/cmtar/extract.c @@ -17,14 +17,20 @@ #include #include #include -#ifdef _MSC_VER -#include -#include -#include + +#if defined(_WIN32) && !defined(__CYGWIN__) +# ifdef _MSC_VER +# include +# else +# include +# endif +# include +# include #else -#include -#include +# include +# include #endif + #ifdef STDC_HEADERS # include # include @@ -41,8 +47,8 @@ struct linkname { - char ln_save[MAXPATHLEN]; - char ln_real[MAXPATHLEN]; + char ln_save[TAR_MAXPATHLEN]; + char ln_real[TAR_MAXPATHLEN]; }; typedef struct linkname linkname_t; diff --git a/Utilities/cmtar/filesystem.c b/Utilities/cmtar/filesystem.c index 3418d1edc..1ddd5a528 100644 --- a/Utilities/cmtar/filesystem.c +++ b/Utilities/cmtar/filesystem.c @@ -3,7 +3,6 @@ // First microsoft compilers -#ifdef _MSC_VER #include #include #include @@ -61,7 +60,7 @@ kwDirEntry * kwReadDir(kwDirectory * dir) return NULL; } entry = (kwDirEntry*)malloc(sizeof(kwDirEntry)); - strncpy(entry->d_name,dir->Entry.name,MAXPATHLEN-1); + strncpy(entry->d_name,dir->Entry.name,TAR_MAXPATHLEN-1); if(_findnext(dir->SrchHandle, &dir->Entry) == -1) { dir->EOD=1; @@ -79,4 +78,3 @@ int kwCloseDir(kwDirectory * dir) if(r==-1) return 0; return 1; } -#endif diff --git a/Utilities/cmtar/filesystem.h b/Utilities/cmtar/filesystem.h index f2ee20294..cd61ed226 100644 --- a/Utilities/cmtar/filesystem.h +++ b/Utilities/cmtar/filesystem.h @@ -1,8 +1,8 @@ #ifndef _FILESYSTEM_H_ #define _FILESYSTEM_H_ -#ifdef _MSC_VER #include +#include struct _KWDIR { @@ -15,12 +15,9 @@ struct _KWDIR int EOD; //end of directory }; -#ifndef MAXPATHLEN -#define MAXPATHLEN _MAX_PATH -#endif typedef struct _KWDIRENTRY { - char d_name[MAXPATHLEN]; + char d_name[TAR_MAXPATHLEN]; }kwDirEntry; typedef struct _KWDIR kwDirectory; @@ -31,5 +28,3 @@ int kwCloseDir(kwDirectory * dir); #endif //MSC - -#endif diff --git a/Utilities/cmtar/handle.c b/Utilities/cmtar/handle.c index 1fe053eba..5238e0367 100644 --- a/Utilities/cmtar/handle.c +++ b/Utilities/cmtar/handle.c @@ -34,7 +34,22 @@ const char libtar_version[] = PACKAGE_VERSION; +#define libtar_symbol(name, ret, args, callargs) \ + static ret libtar_##name args \ + { \ + return name callargs; \ + } + +#if defined(__BORLANDC__) +libtar_symbol(open, int, (const char* pathname, int flags, mode_t mode), (pathname, flags, mode)); +libtar_symbol(close, int, (int fd), (fd)); +libtar_symbol(read, ssize_t, (int fd, void* buf, size_t count), (fd, buf, count)); +libtar_symbol(write, ssize_t, (int fd, void* buf, size_t count), (fd, buf, count)); + +static tartype_t default_type = { libtar_open, libtar_close, libtar_read, libtar_write }; +#else static tartype_t default_type = { open, close, read, write }; +#endif static int diff --git a/Utilities/cmtar/internal.h b/Utilities/cmtar/internal.h index 434fbb0ad..cc2cbd35d 100644 --- a/Utilities/cmtar/internal.h +++ b/Utilities/cmtar/internal.h @@ -14,4 +14,3 @@ #include #include - diff --git a/Utilities/cmtar/libtar.c b/Utilities/cmtar/libtar.c index cdbe7a136..ee0107502 100644 --- a/Utilities/cmtar/libtar.c +++ b/Utilities/cmtar/libtar.c @@ -113,7 +113,7 @@ create(char *tarfile, char *rootdir, libtar_list_t *l) { TAR *t; char *pathname; - char buf[MAXPATHLEN]; + char buf[TAR_MAXPATHLEN]; libtar_listptr_t lp; if (tar_open(&t, tarfile, diff --git a/Utilities/cmtar/util.c b/Utilities/cmtar/util.c index 007ed9301..1959e0a5d 100644 --- a/Utilities/cmtar/util.c +++ b/Utilities/cmtar/util.c @@ -20,7 +20,7 @@ # include #endif -#ifdef _MSC_VER +#if defined(_WIN32) && !defined(__CYGWIN__) #include #else #include @@ -30,7 +30,7 @@ int path_hashfunc(char *key, int numbuckets) { - char buf[MAXPATHLEN]; + char buf[TAR_MAXPATHLEN]; char *p; strcpy(buf, key); @@ -82,7 +82,7 @@ ino_hash(ino_t *inode) int mkdirhier(char *path) { - char src[MAXPATHLEN], dst[MAXPATHLEN] = ""; + char src[TAR_MAXPATHLEN], dst[TAR_MAXPATHLEN] = ""; char *dirp, *nextp = src; int retval = 1; @@ -103,10 +103,10 @@ mkdirhier(char *path) if (dst[0] != '\0') strcat(dst, "/"); strcat(dst, dirp); -#ifndef _MSC_VER - if (mkdir(dst, 0777) == -1) -#else +#if defined(_WIN32) && !defined(__CYGWIN__) if (mkdir(dst) == -1) +#else + if (mkdir(dst, 0777) == -1) #endif { if (errno != EEXIST) diff --git a/Utilities/cmtar/wrapper.c b/Utilities/cmtar/wrapper.c index a54586244..be090ee64 100644 --- a/Utilities/cmtar/wrapper.c +++ b/Utilities/cmtar/wrapper.c @@ -14,7 +14,7 @@ #include #include -#ifdef _MSC_VER +#if defined(_WIN32) && !defined(__CYGWIN__) #include #else #include @@ -35,7 +35,7 @@ int tar_extract_glob(TAR *t, char *globname, char *prefix) { char *filename; - char buf[MAXPATHLEN]; + char buf[TAR_MAXPATHLEN]; int i; while ((i = th_read(t)) == 0) @@ -65,7 +65,7 @@ int tar_extract_all(TAR *t, char *prefix) { char *filename; - char buf[MAXPATHLEN]; + char buf[TAR_MAXPATHLEN]; int i; #ifdef DEBUG @@ -100,9 +100,9 @@ tar_extract_all(TAR *t, char *prefix) int tar_append_tree(TAR *t, char *realdir, char *savedir) { - char realpath[MAXPATHLEN]; - char savepath[MAXPATHLEN]; -#ifndef _MSC_VER + char realpath[TAR_MAXPATHLEN]; + char savepath[TAR_MAXPATHLEN]; +#if !defined(_WIN32) || defined(__CYGWIN__) struct dirent *dent; DIR *dp; #else @@ -123,7 +123,7 @@ tar_append_tree(TAR *t, char *realdir, char *savedir) puts(" tar_append_tree(): done with tar_append_file()..."); #endif -#ifdef _MSC_VER +#if defined(_WIN32) && !defined(__CYGWIN__) dp = kwOpenDir(realdir); #else dp = opendir(realdir); @@ -135,7 +135,7 @@ tar_append_tree(TAR *t, char *realdir, char *savedir) return 0; return -1; } -#ifdef _MSC_VER +#if defined(_WIN32) && !defined(__CYGWIN__) while ((dent = kwReadDir(dp)) != NULL) #else while ((dent = readdir(dp)) != NULL) @@ -145,10 +145,10 @@ tar_append_tree(TAR *t, char *realdir, char *savedir) strcmp(dent->d_name, "..") == 0) continue; - snprintf(realpath, MAXPATHLEN, "%s/%s", realdir, + snprintf(realpath, TAR_MAXPATHLEN, "%s/%s", realdir, dent->d_name); if (savedir) - snprintf(savepath, MAXPATHLEN, "%s/%s", savedir, + snprintf(savepath, TAR_MAXPATHLEN, "%s/%s", savedir, dent->d_name); #ifndef WIN32 @@ -171,7 +171,7 @@ tar_append_tree(TAR *t, char *realdir, char *savedir) return -1; } -#ifdef _MSC_VER +#if defined(_WIN32) && !defined(__CYGWIN__) kwCloseDir(dp); #else closedir(dp);