From 728beef702ce0b7d618676ddc944c95ee2a9870b Mon Sep 17 00:00:00 2001 From: Jamey Sharp
Date: Sun, 24 Dec 2006 00:30:18 -0800 Subject: [PATCH] Add support for cross-compiling mtools for Windows using MinGW. Commit by Josh Triplett and Jamey Sharp. --- expand.c | 10 ++++++++-- file.c | 2 +- mainloop.c | 4 +++- mcopy.c | 6 +++++- misc.c | 4 ++++ msdos.h | 2 ++ mtools.h | 2 ++ mzip.c | 4 ++-- plain_io.c | 2 ++ precmd.c | 2 ++ privileges.c | 32 ++++++++++++++++++++++++++++++-- scsi.c | 4 ++-- signal.c | 8 ++++++++ sysincludes.h | 20 ++++++++++++++++++-- 14 files changed, 89 insertions(+), 13 deletions(-) diff --git a/expand.c b/expand.c index a87d14e..7725c99 100644 --- a/expand.c +++ b/expand.c @@ -7,7 +7,7 @@ #include "sysincludes.h" #include "mtools.h" - +#ifndef OS_mingw32msvc int safePopenOut(char **command, char *output, int len) { int pipefd[2]; @@ -42,11 +42,12 @@ int safePopenOut(char **command, char *output, int len) } return last; } - +#endif const char *expand(const char *input, char *ans) { +#ifndef OS_mingw32msvc int last; char buf[256]; char *command[] = { "/bin/sh", "sh", "-c", 0, 0 }; @@ -80,4 +81,9 @@ const char *expand(const char *input, char *ans) else strncpy(ans, input, EXPAND_BUF-1); return ans; +#else + strncpy(ans, input, EXPAND_BUF-1); + ans[EXPAND_BUF-1]='\0'; + return ans; +#endif } diff --git a/file.c b/file.c index 1a0cc99..f46f33e 100644 --- a/file.c +++ b/file.c @@ -408,7 +408,7 @@ static __inline__ time_t conv_stamp(struct directory *dir) tzone = tz.tz_minuteswest * 60L; } #else -#ifdef HAVE_TZSET +#if defined HAVE_TZSET && !defined OS_mingw32msvc { #if !defined OS_ultrix && !defined OS_cygwin /* Ultrix defines this to be a different type */ diff --git a/mainloop.c b/mainloop.c index f64e285..08dc9be 100644 --- a/mainloop.c +++ b/mainloop.c @@ -56,10 +56,12 @@ int unix_loop(Stream_t *Stream, MainParam_t *mp, char *arg, int follow_dir_link) } GET_DATA(mp->File, 0, 0, &isdir, 0); if(isdir) { +#if !defined(__EMX__) && !defined(OS_mingw32msvc) struct MT_STAT buf; +#endif FREE(&mp->File); -#ifndef __EMX__ +#if !defined(__EMX__) && !defined(OS_mingw32msvc) if(!follow_dir_link && MT_LSTAT(arg, &buf) == 0 && S_ISLNK(buf.st_mode)) { diff --git a/mcopy.c b/mcopy.c index af55824..4e16401 100644 --- a/mcopy.c +++ b/mcopy.c @@ -176,7 +176,11 @@ static int unix_write(direntry_t *entry, MainParam_t *mp, int needfilter) static int makeUnixDir(char *filename) { - if(!mkdir(filename, 0777)) + if(!mkdir(filename +#ifndef OS_mingw32msvc + , 0777 +#endif + )) return 0; if(errno == EEXIST) { struct MT_STAT buf; diff --git a/misc.c b/misc.c index 5f6175c..e9ee25d 100644 --- a/misc.c +++ b/misc.c @@ -16,6 +16,7 @@ void printOom(void) char *get_homedir(void) { +#ifndef OS_mingw32msvc struct passwd *pw; uid_t uid; char *homedir; @@ -47,6 +48,9 @@ char *get_homedir(void) if ( pw ) return pw->pw_dir; return 0; +#else + return getenv("HOME"); +#endif } diff --git a/msdos.h b/msdos.h index b261611..22bd36c 100644 --- a/msdos.h +++ b/msdos.h @@ -8,7 +8,9 @@ #define MAX_SECTOR 8192 /* largest sector size */ #define MDIR_SIZE 32 /* MSDOS directory entry size in bytes*/ #define MAX_CLUSTER 8192 /* largest cluster size */ +#ifndef MAX_PATH #define MAX_PATH 128 /* largest MSDOS path length */ +#endif #define MAX_DIR_SECS 64 /* largest directory (in sectors) */ #define MSECTOR_SIZE msector_size diff --git a/mtools.h b/mtools.h index eb195b3..5b9d102 100644 --- a/mtools.h +++ b/mtools.h @@ -228,7 +228,9 @@ const char *fix_mcwd(char *); FILE *open_mcwd(const char *mode); void unlink_mcwd(void); +#ifndef OS_mingw32msvc int safePopenOut(char **command, char *output, int len); +#endif #define ROUND_DOWN(value, grain) ((value) - (value) % (grain)) #define ROUND_UP(value, grain) ROUND_DOWN((value) + (grain)-1, (grain)) diff --git a/mzip.c b/mzip.c index 80876a8..058a26a 100644 --- a/mzip.c +++ b/mzip.c @@ -304,9 +304,9 @@ void mzip(int argc, char **argv, int type) if(IS_PRIVILEGED(dev)) reclaim_privs(); - fd = scsi_open(name, O_RDONLY | + fd = scsi_open(name, O_RDONLY #ifdef O_NDELAY - O_NDELAY + | O_NDELAY #endif , 0644, &extra_data); diff --git a/plain_io.c b/plain_io.c index 3aafb15..1469e47 100644 --- a/plain_io.c +++ b/plain_io.c @@ -593,6 +593,7 @@ APIRET rc; } #ifndef __EMX__ #ifndef __CYGWIN__ +#ifndef OS_mingw32msvc /* lock the device on writes */ if (locked && lock_dev(This->fd, mode == O_RDWR, dev)) { if(errmsg) @@ -613,6 +614,7 @@ APIRET rc; } #endif #endif +#endif /* set default parameters, if needed */ if (dev){ if ((!IS_MFORMAT_ONLY(dev) && dev->tracks) && diff --git a/precmd.c b/precmd.c index 583faed..d025691 100644 --- a/precmd.c +++ b/precmd.c @@ -9,6 +9,7 @@ void precmd(struct device *dev) { +#ifndef OS_mingw32msvc int status; pid_t pid; @@ -27,5 +28,6 @@ void precmd(struct device *dev) wait(&status); break; } +#endif } diff --git a/privileges.c b/privileges.c index 139ec6b..32222ba 100644 --- a/privileges.c +++ b/privileges.c @@ -2,6 +2,35 @@ #include "msdos.h" #include "mtools.h" +int noPrivileges=0; + +#ifdef OS_mingw32msvc +void reclaim_privs(void) +{ +} + +void drop_privs(void) +{ +} + +void destroy_privs(void) +{ +} + +uid_t get_real_uid(void) +{ + return 0; +} + +void init_privs(void) +{ +} + +void closeExec(int fd) +{ +} + +#else /*#define PRIV_DEBUG*/ #if 0 @@ -24,8 +53,6 @@ static __inline__ void print_privs(const char *message) #endif } -int noPrivileges=0; - static gid_t rgid, egid; static uid_t ruid, euid; @@ -164,3 +191,4 @@ void closeExec(int fd) fcntl(fd, F_SETFD, 1); #endif } +#endif diff --git a/scsi.c b/scsi.c index 209d50e..8eb5a61 100644 --- a/scsi.c +++ b/scsi.c @@ -73,9 +73,9 @@ int scsi_open(const char *name, int flag, int mode, void **extra_data) else return -1; #else - return open(name, O_RDONLY | O_LARGEFILE | + return open(name, O_RDONLY | O_LARGEFILE #ifdef O_NDELAY - O_NDELAY + | O_NDELAY #endif /* O_RDONLY | dev->mode*/); #endif diff --git a/signal.c b/signal.c index 130280a..09169a1 100644 --- a/signal.c +++ b/signal.c @@ -28,8 +28,16 @@ int do_gotsignal(char *f, int n) void setup_signal(void) { /* catch signals */ +#ifdef SIGHUP signal(SIGHUP, (SIG_CAST)signal_handler); +#endif +#ifdef SIGINT signal(SIGINT, (SIG_CAST)signal_handler); +#endif +#ifdef SIGTERM signal(SIGTERM, (SIG_CAST)signal_handler); +#endif +#ifdef SIGQUIT signal(SIGQUIT, (SIG_CAST)signal_handler); +#endif } diff --git a/sysincludes.h b/sysincludes.h index bfe971e..d414b5d 100644 --- a/sysincludes.h +++ b/sysincludes.h @@ -58,6 +58,10 @@ # endif #endif +#ifdef OS_mingw32msvc +typedef void *caddr_t; +#endif + /***********************************************************************/ /* */ @@ -223,7 +227,11 @@ extern int ioctl(int fildes, int request, void *arg); #include