diff --git a/CMakeLists.txt b/CMakeLists.txt index 0823646..d7006c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ endif() if(MSVC) include_directories(include/msvc) add_definitions(-D_CRT_SECURE_NO_WARNINGS) + add_compile_options(/wd4996) endif() # add pcap headers for win32. assume os/x, linux, etc, already have them. diff --git a/src/config.c b/src/config.c index c3972b1..669b8e2 100644 --- a/src/config.c +++ b/src/config.c @@ -19,9 +19,12 @@ #endif #if defined _MSC_VER -#include -#define snprintf _snprintf + typedef unsigned int mode_t; + +#define strcasecmp stricmp +#define strncasecmp strnicmp + #endif diff --git a/src/host_common.c b/src/host_common.c index 6cab5ab..6b594e6 100644 --- a/src/host_common.c +++ b/src/host_common.c @@ -1,14 +1,9 @@ #define _BSD_SOURCE -#include -#include -#include #include -#include #include #include #include -#include #include "defc.h" #include "gsos.h" @@ -18,6 +13,12 @@ #include #endif +#ifdef _MSC_VER +#define strcasecmp stricmp +#define strncasecmp strnicmp +#endif + + #include "host_common.h" @@ -149,59 +150,6 @@ void host_text_to_merlin(byte *buffer, size_t size) { } -/* - * error remapping. - * NOTE - GS/OS errors are a superset of P8 errors - */ - -static word32 enoent(const char *path) { - /* - some op on path return ENOENT. check if it's - fileNotFound or pathNotFound - */ - char *p = (char *)path; - for(;;) { - struct stat st; - p = dirname(p); - if (p == NULL) break; - if (p[0] == '.' && p[1] == 0) break; - if (p[0] == '/' && p[1] == 0) break; - if (stat(p, &st) < 0) return pathNotFound; - } - return fileNotFound; -} - -word32 host_map_errno(int xerrno) { - switch(xerrno) { - case 0: return 0; - case EBADF: - return invalidAccess; -#ifdef EDQUOT - case EDQUOT: -#endif - case EFBIG: - return volumeFull; - case ENOENT: - return fileNotFound; - case ENOTDIR: - return pathNotFound; - case ENOMEM: - return outOfMem; - case EEXIST: - return dupPathname; - case ENOTEMPTY: - return invalidAccess; - - default: - return drvrIOError; - } -} - -word32 host_map_errno_path(int xerrno, const char *path) { - if (xerrno == ENOENT) return enoent(path); - return host_map_errno(xerrno); -} - const char *host_error_name(word16 error) { static char *errors[] = { "", diff --git a/src/host_mli.c b/src/host_mli.c index 5356e94..9550e5f 100644 --- a/src/host_mli.c +++ b/src/host_mli.c @@ -26,6 +26,11 @@ #include "host_common.h" +#ifdef _MSC_VER +#define strcasecmp stricmp +#define strncasecmp strnicmp +#endif + #define LEVEL 0xBFD8 // current file level #define DEVNUM 0xBF30 // last slot / drive diff --git a/src/options.c b/src/options.c index 86c03f4..f58d199 100644 --- a/src/options.c +++ b/src/options.c @@ -8,10 +8,15 @@ #include #include #include +#include #include "options.h" #include "glog.h" #include "defc.h" +#ifdef _MSC_VER +#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +#endif + // config is parsed in config.c :: config_parse_config_gsplus_file() // cli is parsed here. would be nice to reuse some code diff --git a/src/unix_host_common.c b/src/unix_host_common.c index 0df5b91..adc5110 100644 --- a/src/unix_host_common.c +++ b/src/unix_host_common.c @@ -7,6 +7,8 @@ #include #include #include +#include +#include #if defined(__APPLE__) #include @@ -510,3 +512,58 @@ unsigned host_storage_type(const char *path, word16 *error) { *error = badStoreType; return 0; } + + +/* + * error remapping. + * NOTE - GS/OS errors are a superset of P8 errors + */ + +static word32 enoent(const char *path) { + /* + some op on path return ENOENT. check if it's + fileNotFound or pathNotFound + */ + char *p = (char *)path; + for(;;) { + struct stat st; + p = dirname(p); + if (p == NULL) break; + if (p[0] == '.' && p[1] == 0) break; + if (p[0] == '/' && p[1] == 0) break; + if (stat(p, &st) < 0) return pathNotFound; + } + return fileNotFound; +} + +word32 host_map_errno(int xerrno) { + switch(xerrno) { + case 0: return 0; + case EBADF: + return invalidAccess; +#ifdef EDQUOT + case EDQUOT: +#endif + case EFBIG: + return volumeFull; + case ENOENT: + return fileNotFound; + case ENOTDIR: + return pathNotFound; + case ENOMEM: + return outOfMem; + case EEXIST: + return dupPathname; + case ENOTEMPTY: + return invalidAccess; + + default: + return drvrIOError; + } +} + +word32 host_map_errno_path(int xerrno, const char *path) { + if (xerrno == ENOENT) return enoent(path); + return host_map_errno(xerrno); +} + diff --git a/src/win32_host_common.c b/src/win32_host_common.c index 1b3e016..7e22cc5 100644 --- a/src/win32_host_common.c +++ b/src/win32_host_common.c @@ -11,6 +11,11 @@ #include "host_common.h" +#ifdef _MSC_VER +#define strcasecmp stricmp +#define strncasecmp strnicmp +#endif + void afp_init(struct AFP_Info *info, word16 file_type, word32 aux_type) { @@ -66,7 +71,7 @@ void afp_synchronize(struct AFP_Info *info, int preference) { -static DWORD root_file_id[3] = {}; +static DWORD root_file_id[3] = { 0 }; unsigned host_startup(void) { @@ -97,10 +102,8 @@ unsigned host_startup(void) { if (!(fbi.FileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { fprintf(stderr, "%s is not a directory\n", host_root); - CloseHandle(h); return invalidFSTop; } - CloseHandle(h); return 0; } @@ -231,8 +234,8 @@ FILETIME host_get_date_time(word32 ptr) { TzSpecificLocalTimeToSystemTime(NULL, &tmLocal, &tmUTC); - if (!SystemTimeToFileTime(&tmUTC, &utc)) utc =(FILETIME){0, 0}; - + if (!SystemTimeToFileTime(&tmUTC, &utc)) memset(&utc, 0, sizeof(utc)); + return utc; } @@ -249,6 +252,7 @@ FILETIME host_get_date_time_rec(word32 ptr) { SYSTEMTIME tmUTC; memset(&tmLocal, 0, sizeof(tmLocal)); memset(&tmUTC, 0, sizeof(tmUTC)); + memset(&utc, 0, sizeof(utc)); tmLocal.wSecond = buffer[0]; tmLocal.wMinute = buffer[1]; @@ -258,7 +262,7 @@ FILETIME host_get_date_time_rec(word32 ptr) { tmLocal.wMonth = buffer[5] + 1; TzSpecificLocalTimeToSystemTime(NULL, &tmLocal, &tmUTC); - if (!SystemTimeToFileTime(&tmUTC, &utc)) utc =(FILETIME){0, 0}; + if (!SystemTimeToFileTime(&tmUTC, &utc)) memset(&utc, 0, sizeof(utc)); return utc; } diff --git a/src/win32_host_fst.c b/src/win32_host_fst.c index 05f3360..824edbc 100644 --- a/src/win32_host_fst.c +++ b/src/win32_host_fst.c @@ -20,6 +20,12 @@ #include "host_common.h" +#ifdef _MSC_VER +#define strcasecmp stricmp +#define strncasecmp strnicmp +#endif + + extern Engine_reg engine; @@ -62,7 +68,7 @@ static struct directory *read_directory(const char *path, word16 *error); #define COOKIE_BASE 0x8000 -static word32 cookies[32] = {}; +static word32 cookies[32] = { 0 }; static int alloc_cookie() { for (int i = 0; i < 32; ++i) { @@ -746,7 +752,7 @@ static struct directory *read_directory(const char *path, word16 *error) { size = sizeof(struct directory) + capacity * sizeof(char *); struct directory * tmp = realloc(dd, size); if (!tmp) { - *error = host_map_errno(errno); + *error = outOfMem; free_directory(dd); FindClose(h); return NULL;