summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Cedilnik <andy.cedilnik@kitware.com>2005-12-30 15:35:23 (GMT)
committerAndy Cedilnik <andy.cedilnik@kitware.com>2005-12-30 15:35:23 (GMT)
commit9e0633c91090e3254056b33bf8bd1ec4533982a6 (patch)
treef680ede529eb7bb1c7739884038499e4b6229356
parentbc447c7f92730303c16d34cbe3747854b4c776c3 (diff)
downloadCMake-9e0633c91090e3254056b33bf8bd1ec4533982a6.zip
CMake-9e0633c91090e3254056b33bf8bd1ec4533982a6.tar.gz
CMake-9e0633c91090e3254056b33bf8bd1ec4533982a6.tar.bz2
BUG: Several Borland fixes
-rw-r--r--Utilities/cmtar/CMakeLists.txt6
-rw-r--r--Utilities/cmtar/append.c15
-rw-r--r--Utilities/cmtar/config.h.in6
-rw-r--r--Utilities/cmtar/encode.c9
-rw-r--r--Utilities/cmtar/internal.h7
-rw-r--r--Utilities/cmtar/output.c2
-rw-r--r--Utilities/cmtar/util.c16
-rw-r--r--Utilities/cmtar/wrapper.c45
8 files changed, 81 insertions, 25 deletions
diff --git a/Utilities/cmtar/CMakeLists.txt b/Utilities/cmtar/CMakeLists.txt
index fc3a887..ee9d681 100644
--- a/Utilities/cmtar/CMakeLists.txt
+++ b/Utilities/cmtar/CMakeLists.txt
@@ -75,10 +75,12 @@ FOREACH(file
"stdio.h"
"string.h"
"strings.h"
+ "sys/param.h"
"sys/types.h"
"sys/stat.h"
"unistd.h"
"glob.h"
+ "dirent.h"
)
CHECK_INCLUDE_FILE_CONCAT("${file}")
ENDFOREACH(file)
@@ -293,11 +295,11 @@ SET(libtar_SRC
# compat/strmode.c
# compat/strsep.c
)
-IF(NOT UNIX)
+IF(NOT HAVE_DIRENT_H)
SET(libtar_SRC
${libtar_SRC}
filesystem.c filesystem.h)
-ENDIF(NOT UNIX)
+ENDIF(NOT HAVE_DIRENT_H)
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 6dbf1dd..6bcef98 100644
--- a/Utilities/cmtar/append.c
+++ b/Utilities/cmtar/append.c
@@ -69,8 +69,10 @@ tar_append_file(TAR *t, char *realname, char *savename)
tar_ino_t *ti = NULL;
#if !defined(_WIN32) || defined(__CYGWIN__)
int i;
- char path[TAR_MAXPATHLEN];
+#else
+ size_t plen;
#endif
+ char path[TAR_MAXPATHLEN];
#ifdef DEBUG
printf("==> tar_append_file(TAR=0x%lx (\"%s\"), realname=\"%s\", "
@@ -79,7 +81,14 @@ tar_append_file(TAR *t, char *realname, char *savename)
#endif
#if defined(_WIN32) && !defined(__CYGWIN__)
- if (stat(realname, &s) != 0)
+ strncpy(path, realname, sizeof(path)-1);
+ path[sizeof(path)-1] = 0;
+ plen = strlen(path);
+ if (path[plen-1] == '/' )
+ {
+ path[plen-1] = 0;
+ }
+ if (stat(path, &s) != 0)
#else
if (lstat(realname, &s) != 0)
#endif
@@ -126,6 +135,7 @@ tar_append_file(TAR *t, char *realname, char *savename)
return -1;
}
libtar_hashptr_reset(&hp);
+#if !defined(_WIN32) || defined(__CYGWIN__)
if (libtar_hash_getkey(td->td_h, &hp, &(s.st_ino),
(libtar_matchfunc_t)ino_match) != 0)
{
@@ -138,6 +148,7 @@ tar_append_file(TAR *t, char *realname, char *savename)
th_set_link(t, ti->ti_name);
}
else
+#endif
{
#ifdef DEBUG
printf("+++ adding entry: device (0x%lx,0x%lx), inode %ld "
diff --git a/Utilities/cmtar/config.h.in b/Utilities/cmtar/config.h.in
index 6702238..acbbead 100644
--- a/Utilities/cmtar/config.h.in
+++ b/Utilities/cmtar/config.h.in
@@ -36,6 +36,12 @@
/* Define to 1 if you have the <memory.h> header file. */
#cmakedefine HAVE_MEMORY_H @HAVE_MEMORY_H@
+/* Define to 1 if you have the <dirent.h> header file. */
+#cmakedefine HAVE_DIRENT_H @HAVE_DIRENT_H@
+
+/* Define to 1 if you have the <sys/param.h> header file. */
+#cmakedefine HAVE_SYS_PARAM_H @HAVE_SYS_PARAM_H@
+
/* Define to 1 if the system has the type `minor_t'. */
#cmakedefine HAVE_MINOR_T @HAVE_MINOR_T@
diff --git a/Utilities/cmtar/encode.c b/Utilities/cmtar/encode.c
index cadac67..3c8cb6a 100644
--- a/Utilities/cmtar/encode.c
+++ b/Utilities/cmtar/encode.c
@@ -157,12 +157,6 @@ th_set_device(TAR *t, dev_t device)
printf("th_set_device(): major = %d, minor = %d\n",
major(device), minor(device));
#endif
-#ifndef major
-# define major(dev) ((int)(((dev) >> 8) & 0xff))
-#endif
-#ifndef minor
-# define minor(dev) ((int)((dev) & 0xff))
-#endif
int_to_oct(major(device), t->th_buf.devmajor, 8);
int_to_oct(minor(device), t->th_buf.devminor, 8);
}
@@ -209,7 +203,8 @@ th_set_mode(TAR *t, mode_t fmode)
fmode |= S_IFIFO;
}
#endif
- int_to_oct(fmode, (t)->th_buf.mode, 8);
+ /* Looks like on windows the st_mode is longer than 8 characters. */
+ int_to_oct(fmode & 07777777, (t)->th_buf.mode, 8);
}
diff --git a/Utilities/cmtar/internal.h b/Utilities/cmtar/internal.h
index cc2cbd3..60be2af 100644
--- a/Utilities/cmtar/internal.h
+++ b/Utilities/cmtar/internal.h
@@ -14,3 +14,10 @@
#include <libtar/compat.h>
#include <libtar/libtar.h>
+
+#ifndef major
+# define major(dev) ((int)(((dev) >> 8) & 0xff))
+#endif
+#ifndef minor
+# define minor(dev) ((int)((dev) & 0xff))
+#endif
diff --git a/Utilities/cmtar/output.c b/Utilities/cmtar/output.c
index 14757f4..38cf157 100644
--- a/Utilities/cmtar/output.c
+++ b/Utilities/cmtar/output.c
@@ -110,8 +110,8 @@ th_print_long_ls(TAR *t)
if (TH_ISCHR(t) || TH_ISBLK(t))
printf(" %3d, %3d ", th_get_devmajor(t), th_get_devminor(t));
else
- printf("%9ld ", (long)th_get_size(t));
#endif
+ printf("%9ld ", (long)th_get_size(t));
mtime = th_get_mtime(t);
mtm = localtime(&mtime);
diff --git a/Utilities/cmtar/util.c b/Utilities/cmtar/util.c
index 1959e0a..494847b 100644
--- a/Utilities/cmtar/util.c
+++ b/Utilities/cmtar/util.c
@@ -103,12 +103,24 @@ mkdirhier(char *path)
if (dst[0] != '\0')
strcat(dst, "/");
strcat(dst, dirp);
+ if (
#if defined(_WIN32) && !defined(__CYGWIN__)
- if (mkdir(dst) == -1)
+ mkdir(dst) == -1
#else
- if (mkdir(dst, 0777) == -1)
+ mkdir(dst, 0777) == -1
#endif
+ )
{
+#ifdef __BORLANDC__
+ /* There is a bug in the Borland Run time library which makes MKDIR
+ return EACCES when it should return EEXIST
+ if it is some other error besides directory exists
+ then return false */
+ if ( errno == EACCES)
+ {
+ errno = EEXIST;
+ }
+#endif
if (errno != EEXIST)
return -1;
}
diff --git a/Utilities/cmtar/wrapper.c b/Utilities/cmtar/wrapper.c
index be090ee..8f682c2 100644
--- a/Utilities/cmtar/wrapper.c
+++ b/Utilities/cmtar/wrapper.c
@@ -14,11 +14,13 @@
#include <stdio.h>
#include <libtar/compat.h>
-#if defined(_WIN32) && !defined(__CYGWIN__)
-#include <libtarint/filesystem.h>
-#else
+#if defined(HAVE_SYS_PARAM_H)
#include <sys/param.h>
+#endif
+#if defined(HAVE_DIRENT_H)
#include <dirent.h>
+#else
+#include <libtarint/filesystem.h>
#endif
#include <errno.h>
@@ -102,7 +104,8 @@ tar_append_tree(TAR *t, char *realdir, char *savedir)
{
char realpath[TAR_MAXPATHLEN];
char savepath[TAR_MAXPATHLEN];
-#if !defined(_WIN32) || defined(__CYGWIN__)
+ size_t plen;
+#if defined(HAVE_DIRENT_H)
struct dirent *dent;
DIR *dp;
#else
@@ -110,6 +113,14 @@ tar_append_tree(TAR *t, char *realdir, char *savedir)
kwDirectory *dp;
#endif
struct stat s;
+ strncpy(realpath, realdir, sizeof(realpath));
+ realpath[sizeof(realpath)-1] = 0;
+ plen = strlen(realpath);
+ if ( realpath[plen-1] == '/' )
+ {
+ realpath[plen-1] = 0;
+ }
+
#ifdef DEBUG
printf("==> tar_append_tree(0x%lx, \"%s\", \"%s\")\n",
@@ -123,10 +134,22 @@ tar_append_tree(TAR *t, char *realdir, char *savedir)
puts(" tar_append_tree(): done with tar_append_file()...");
#endif
+ if ( stat(realpath, &s) != 0 )
+ {
+ return -1;
+ }
+ if (
#if defined(_WIN32) && !defined(__CYGWIN__)
- dp = kwOpenDir(realdir);
+ (s.st_mode & _S_IFDIR) == 0
#else
+ !S_ISDIR(s.st_mode)
+#endif
+ )
+ return 0;
+#if defined(HAVE_DIRENT_H)
dp = opendir(realdir);
+#else
+ dp = kwOpenDir(realdir);
#endif
if (dp == NULL)
@@ -135,10 +158,10 @@ tar_append_tree(TAR *t, char *realdir, char *savedir)
return 0;
return -1;
}
-#if defined(_WIN32) && !defined(__CYGWIN__)
- while ((dent = kwReadDir(dp)) != NULL)
-#else
+#if defined(HAVE_DIRENT_H)
while ((dent = readdir(dp)) != NULL)
+#else
+ while ((dent = kwReadDir(dp)) != NULL)
#endif
{
if (strcmp(dent->d_name, ".") == 0 ||
@@ -171,10 +194,10 @@ tar_append_tree(TAR *t, char *realdir, char *savedir)
return -1;
}
-#if defined(_WIN32) && !defined(__CYGWIN__)
- kwCloseDir(dp);
-#else
+#if defined(HAVE_DIRENT_H)
closedir(dp);
+#else
+ kwCloseDir(dp);
#endif
return 0;