BUG: Several Borland fixes

This commit is contained in:
Andy Cedilnik 2005-12-30 10:35:23 -05:00
parent bc447c7f92
commit 9e0633c910
8 changed files with 81 additions and 25 deletions

View File

@ -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)

View File

@ -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 "

View File

@ -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@

View File

@ -156,12 +156,6 @@ th_set_device(TAR *t, dev_t device)
#ifdef DEBUG
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);
}

View File

@ -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

View File

@ -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);

View File

@ -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;
}

View File

@ -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;