From 9522d81cd7ff4b3a8fdabe85eed7a1d23b341f07 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 11 Dec 2009 07:42:06 +0000 Subject: [PATCH] - Added Blzut's zipdir compatibility patch for Solaris. SVN r2020 (trunk) --- tools/zipdir/zipdir.c | 100 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 2 deletions(-) diff --git a/tools/zipdir/zipdir.c b/tools/zipdir/zipdir.c index 584cf98aee..0daf927f99 100644 --- a/tools/zipdir/zipdir.c +++ b/tools/zipdir/zipdir.c @@ -36,8 +36,10 @@ #define stat _stat #else #include +#if !defined(__sun) #include #endif +#endif #include #include #include @@ -131,7 +133,10 @@ typedef unsigned int DWORD; typedef unsigned short WORD; typedef unsigned char BYTE; -#pragma pack(push,1) +// [BL] Solaris (well GCC on Solaris) doesn't seem to support pack(push/pop, 1) so we'll need to use use it +// on the whole file. +#pragma pack(1) +//#pragma pack(push,1) typedef struct { DWORD Magic; // 0 @@ -179,7 +184,7 @@ typedef struct DWORD DirectoryOffset; WORD ZipCommentLength; } EndOfCentralDirectory; -#pragma pack(pop) +//#pragma pack(pop) // EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- @@ -484,6 +489,97 @@ dir_tree_t *add_dirs(char **argv) return trees; } +#elif defined(__sun) + +//========================================================================== +// +// add_dirs +// Solaris version +// +// Given NULL-terminated array of directory paths, create trees for them. +// +//========================================================================== + +void add_dir(dir_tree_t *tree, char* dirpath) +{ + DIR *directory = opendir(dirpath); + if(directory == NULL) + return; + + struct dirent *file; + while((file = readdir(directory)) != NULL) + { + if(file->d_name[0] == '.') //File is hidden or ./.. directory so ignore it. + continue; + + int isDirectory = 0; + int time = 0; + + char* fullFileName = malloc(strlen(dirpath) + strlen(file->d_name) + 1); + strcpy(fullFileName, dirpath); + strcat(fullFileName, file->d_name); + + struct stat *fileStat; + fileStat = malloc(sizeof(struct stat)); + stat(fullFileName, fileStat); + isDirectory = S_ISDIR(fileStat->st_mode); + time = fileStat->st_mtime; + free(stat); + + free(fullFileName); + + if(isDirectory) + { + char* newdir; + newdir = malloc(strlen(dirpath) + strlen(file->d_name) + 2); + strcpy(newdir, dirpath); + strcat(newdir, file->d_name); + strcat(newdir, "/"); + add_dir(tree, newdir); + free(newdir); + continue; + } + + file_entry_t *entry; + entry = alloc_file_entry(dirpath, file->d_name, time); + if (entry == NULL) + { + //no_mem = 1; + break; + } + entry->next = tree->files; + tree->files = entry; + } + + closedir(directory); +} + +dir_tree_t *add_dirs(char **argv) +{ + dir_tree_t *tree, *trees = NULL; + + int i = 0; + while(argv[i] != NULL) + { + tree = alloc_dir_tree(argv[i]); + tree->next = trees; + trees = tree; + + if(tree != NULL) + { + char* dirpath = malloc(sizeof(argv[i]) + 2); + strcpy(dirpath, argv[i]); + if(dirpath[strlen(dirpath)] != '/') + strcat(dirpath, "/"); + add_dir(tree, dirpath); + free(dirpath); + } + + i++; + } + return trees; +} + #else //==========================================================================