From 93f1bc859ac97c1a3eb1b4099148bfa3fc322279 Mon Sep 17 00:00:00 2001 From: fedor Date: Mon, 12 Jun 2000 05:17:41 +0000 Subject: [PATCH] Mingw update git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@6666 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 20 +++ Headers/gnustep/base/NSBundle.h | 1 + Headers/gnustep/base/TcpPort.h | 6 +- Headers/gnustep/base/UdpPort.h | 4 +- Headers/gnustep/base/preface.h.in | 6 + Source/GNUmakefile | 1 - Source/GSTcpPort.m | 8 +- Source/Makefile.postamble | 3 + Source/NSBundle.m | 58 ++++++- Source/NSData.m | 20 +-- Source/NSDate.m | 4 +- Source/NSFileManager.m | 38 ++--- Source/NSHost.m | 6 +- Source/NSLog.m | 2 +- Source/NSPage.m | 4 +- Source/NSProcessInfo.m | 8 +- Source/NSString.m | 14 +- Source/NSTask.m | 21 +-- Source/NSThread.m | 4 +- Source/NSUser.m | 8 +- Source/UdpPort.m | 8 +- Source/UnixFileHandle.m | 6 +- Source/find_exec.c | 241 ------------------------------ Source/find_exec.m | 241 ------------------------------ 24 files changed, 155 insertions(+), 577 deletions(-) delete mode 100644 Source/find_exec.c delete mode 100644 Source/find_exec.m diff --git a/ChangeLog b/ChangeLog index 345a2f380..cfe203eaa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2000-06-11 Adam Fedor + + * Headers/gnustep/base/preface.h.in: Define MINGW if MINW32. + * Headers/gnustep/base/TcpPort.h: Change WIN32 to MINGW since + CYGWIN has unix-like services. + * Headers/gnustep/base/UdpPort.h: Likewise. + * Source/GSTcpPort.m, Source/NSData.m, Source/NSDate.m, + Source/NSFileManager.m, Source/NSHost.m, Source/NSLog.m, + Source/NSPage.m, Source/NSProcessInfo.m, Source/NSString.m, + Source/NSThread.m, Source/NSUser.m, Source/UdpPort.m, + Source/UnixFileHandle.m, : Likewise. + + * Source/Makefile.postamble: touch generated h files so they aren'y + re-copied every compile. + + * Source/NSBundle.m (_absolutePathOfExecutable:): New method. + (mainBundle): Use it. + * Source/NSTask.m (launch): Likewise. + * Source/find_exec.m: Removed. + 2000-06-09 Richard Frith-Macdonald * Source/GSeq.h: Reverted bogus change. diff --git a/Headers/gnustep/base/NSBundle.h b/Headers/gnustep/base/NSBundle.h index 7d3d55ac7..650b98fa9 100644 --- a/Headers/gnustep/base/NSBundle.h +++ b/Headers/gnustep/base/NSBundle.h @@ -89,6 +89,7 @@ extern NSString* NSLoadedClasses; #ifndef NO_GNUSTEP @interface NSBundle (GNUstep) ++ (NSString *) _absolutePathOfExecutable: (NSString *)path; + (NSString*) _gnustep_target_cpu; + (NSString*) _gnustep_target_dir; + (NSString*) _gnustep_target_os; diff --git a/Headers/gnustep/base/TcpPort.h b/Headers/gnustep/base/TcpPort.h index 4f000fcd4..b3fdf8381 100644 --- a/Headers/gnustep/base/TcpPort.h +++ b/Headers/gnustep/base/TcpPort.h @@ -27,11 +27,13 @@ #include #include #include -#if !defined(__WIN32__) || defined(__CYGWIN__) +#ifdef __MINGW__ +# include +#else #include #include #include -#endif /* !__WIN32__ */ +#endif #include /* A concrete implementation of a Port object implemented on top of diff --git a/Headers/gnustep/base/UdpPort.h b/Headers/gnustep/base/UdpPort.h index 430068ff4..62b392596 100644 --- a/Headers/gnustep/base/UdpPort.h +++ b/Headers/gnustep/base/UdpPort.h @@ -27,12 +27,12 @@ #include #include #include -#ifdef __WIN32__ +#ifdef __MINGW__ # include #else # include # include -#endif /* !WIN32 */ +#endif @interface UdpInPort : InPort { diff --git a/Headers/gnustep/base/preface.h.in b/Headers/gnustep/base/preface.h.in index e2b4af8a6..c48ae0af5 100644 --- a/Headers/gnustep/base/preface.h.in +++ b/Headers/gnustep/base/preface.h.in @@ -35,6 +35,12 @@ #endif #endif +#ifdef __MINGW32__ +#ifndef __MINGW__ +#define __MINGW__ +#endif +#endif + #if defined(__WIN32__) #include #define GNUSTEP_BASE_SOCKET_MESSAGE (WM_USER + 1) diff --git a/Source/GNUmakefile b/Source/GNUmakefile index b477c46b7..186240473 100644 --- a/Source/GNUmakefile +++ b/Source/GNUmakefile @@ -335,7 +335,6 @@ NSValue.m \ NSZone.m \ externs.m \ objc-load.m \ -find_exec.m \ NSURL.m \ NSURLHandle.m diff --git a/Source/GSTcpPort.m b/Source/GSTcpPort.m index c699ba30e..eb6f8e5f5 100644 --- a/Source/GSTcpPort.m +++ b/Source/GSTcpPort.m @@ -41,7 +41,7 @@ #include #include #include -#if !defined(__WIN32__) || defined(__CYGWIN__) +#ifndef __MINGW__ #include /* for gethostname() */ #include /* for inet_ntoa() */ #include @@ -63,14 +63,14 @@ extern int errno; #define NBLK_OPT FNDELAY #endif -#endif /* !__WIN32__ */ +#endif /* !__MINGW__ */ #include /* for memset() and strchr() */ -#if !defined(__WIN32__) || defined(__CYGWIN__) +#ifndef __MINGW__ #include #include #include #include -#endif /* !__WIN32__ */ +#endif /* !__MINGW__ */ #ifndef INADDR_NONE #define INADDR_NONE -1 diff --git a/Source/Makefile.postamble b/Source/Makefile.postamble index 9b537fa4b..8b0dcf9b6 100644 --- a/Source/Makefile.postamble +++ b/Source/Makefile.postamble @@ -153,14 +153,17 @@ $(GNUSTEP_OBJ_DIR)/preface${OEXT}: Foundation/preface.h $(GNUSTEP_TARGET_CPU)/$(GNUSTEP_TARGET_OS)/config.h: ../config.status $(MKDIRS) $(GNUSTEP_TARGET_CPU)/$(GNUSTEP_TARGET_OS) -mv Foundation/config.h $(GNUSTEP_TARGET_CPU)/$(GNUSTEP_TARGET_OS) + -touch $(GNUSTEP_TARGET_CPU)/$(GNUSTEP_TARGET_OS)/config.h $(GNUSTEP_TARGET_CPU)/$(GNUSTEP_TARGET_OS)/GSConfig.h: ../config.status $(MKDIRS) $(GNUSTEP_TARGET_CPU)/$(GNUSTEP_TARGET_OS) -mv Foundation/GSConfig.h $(GNUSTEP_TARGET_CPU)/$(GNUSTEP_TARGET_OS) + -touch $(GNUSTEP_TARGET_CPU)/$(GNUSTEP_TARGET_OS)/GSConfig.h $(GNUSTEP_TARGET_CPU)/$(GNUSTEP_TARGET_OS)/mframe.h: mframe/config.status $(MKDIRS) $(GNUSTEP_TARGET_CPU)/$(GNUSTEP_TARGET_OS) -mv mframe/mframe.h $(GNUSTEP_TARGET_CPU)/$(GNUSTEP_TARGET_OS) + -touch $(GNUSTEP_TARGET_CPU)/$(GNUSTEP_TARGET_OS)/mframe.h Foundation/o_%_bas.h: Foundation/o_x_bas.h.in sed -e "s/@XX@/$*/g" $< > $@ diff --git a/Source/NSBundle.m b/Source/NSBundle.m index 8b5fd7c8f..467bd3b20 100644 --- a/Source/NSBundle.m +++ b/Source/NSBundle.m @@ -96,9 +96,6 @@ static NSString* library_combo = nil; #endif -/* Declaration from find_exec.c */ -extern char *objc_find_executable(const char *name); - /* This function is provided for objc-load.c, although I'm not sure it really needs it (So far only needed if using GNU dld library) */ const char * @@ -237,7 +234,6 @@ _bundle_load_callback(Class theClass, Category *theCategory) { NSMutableString *system; NSString *str; - char *output; if ((str = [env objectForKey: @"GNUSTEP_TARGET_DIR"]) != nil) gnustep_target_dir = RETAIN(str); @@ -270,10 +266,9 @@ _bundle_load_callback(Class theClass, Category *theCategory) { _executable_path = [[[NSProcessInfo processInfo] arguments] objectAtIndex: 0]; - output = objc_find_executable([_executable_path cString]); - NSAssert(output, NSInternalInconsistencyException); - _executable_path = [NSString stringWithCString: output]; - OBJC_FREE(output); + _executable_path = + [NSBundle _absolutePathOfExecutable: _executable_path]; + NSAssert(_executable_path, NSInternalInconsistencyException); } RETAIN(_executable_path); @@ -308,6 +303,53 @@ _bundle_load_callback(Class theClass, Category *theCategory) return [self notImplemented: _cmd]; } ++ (NSString *) _absolutePathOfExecutable: (NSString *)path +{ + NSFileManager *mgr; + NSDictionary *env; + NSString *pathlist, *prefix; + id patharr; + + path = [path stringByStandardizingPath]; + if ([path isAbsolutePath]) + return path; + + mgr = [NSFileManager defaultManager]; + env = [[NSProcessInfo processInfo] environment]; + pathlist = [env objectForKey:@"PATH"]; +#if defined(__MINGW__) + patharr = [pathlist componentsSeparatedByString:@";"]; +#else + patharr = [pathlist componentsSeparatedByString:@":"]; +#endif + patharr = [patharr objectEnumerator]; + while ((prefix = [patharr nextObject])) + { + if ([prefix isEqual:@"."]) + prefix = [mgr currentDirectoryPath]; + prefix = [prefix stringByAppendingPathComponent: path]; + if ([mgr isExecutableFileAtPath: prefix]) + return [prefix stringByStandardizingPath]; +#if defined(__WIN32__) + /* Also add common executable extensions on windows */ + if ([path pathExtension] == nil) + { + NSString *wpath; + wpath = [prefix stringByAppendingPathExtension: @"exe"]; + if ([mgr isExecutableFileAtPath: wpath]) + return [wpath stringByStandardizingPath]; + wpath = [prefix stringByAppendingPathExtension: @"com"]; + if ([mgr isExecutableFileAtPath: wpath]) + return [wpath stringByStandardizingPath]; + wpath = [prefix stringByAppendingPathExtension: @"cmd"]; + if ([mgr isExecutableFileAtPath: wpath]) + return [wpath stringByStandardizingPath]; + } +#endif + } + return nil; +} + + (NSBundle *)mainBundle { [load_lock lock]; diff --git a/Source/NSData.m b/Source/NSData.m index b002a9da7..116aeea1f 100644 --- a/Source/NSData.m +++ b/Source/NSData.m @@ -120,17 +120,17 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len, NSZone* zone) void *tmp = 0; int c; +#if defined(__MINGW__) + return NO; +#endif + if ([path getFileSystemRepresentation: thePath maxLength: sizeof(thePath)-1] == NO) { NSDebugLog(@"Open (%s) attempt failed - bad path", thePath); return NO; } -#if defined(__WIN32__) theFile = fopen(thePath, "rb"); -#else - theFile = fopen(thePath, "r"); -#endif if (theFile == NULL) /* We failed to open the file. */ { @@ -541,6 +541,10 @@ failure: FILE *theFile; int c; +#if defined(__MINGW__) + return NO; +#endif + if ([path getFileSystemRepresentation: theRealPath maxLength: sizeof(theRealPath)-1] == NO) { @@ -568,11 +572,7 @@ failure: else { strcpy(thePath, theRealPath); -#if defined(__WIN32__) theFile = fopen(thePath, "wb"); -#else - theFile = fopen(thePath, "w"); -#endif } #else if (useAuxiliaryFile) @@ -594,11 +594,7 @@ failure: } /* Open the file (whether temp or real) for writing. */ -#if defined(__WIN32__) theFile = fopen(thePath, "wb"); -#else - theFile = fopen(thePath, "w"); -#endif #endif if (theFile == NULL) /* Something went wrong; we weren't diff --git a/Source/NSDate.m b/Source/NSDate.m index 6d5c26603..87de29b02 100644 --- a/Source/NSDate.m +++ b/Source/NSDate.m @@ -108,7 +108,7 @@ otherTime(NSDate* other) NSTimeInterval GSTimeNow() { -#if !defined(__WIN32__) +#if !defined(__MINGW__) volatile NSTimeInterval interval; struct timeval tp; @@ -137,7 +137,7 @@ GSTimeNow() t = otherTime(d); RELEASE(d); return t + sys_time.wMilliseconds / 1000.0; -#endif /* __WIN32__ */ +#endif /* __MINGW__ */ } /* The implementation of NSDate. */ diff --git a/Source/NSFileManager.m b/Source/NSFileManager.m index 720c58199..987741f2b 100644 --- a/Source/NSFileManager.m +++ b/Source/NSFileManager.m @@ -61,7 +61,7 @@ #define DIR_enum_state DIR -#if defined(__WIN32__) +#if defined(__MINGW__) #define WIN32ERR ((DWORD)0xFFFFFFFF) #endif @@ -71,7 +71,7 @@ # include /* for PATH_MAX */ # include #else -#ifdef __WIN32__ +#ifdef __MINGW__ # include # include #else @@ -206,8 +206,8 @@ static NSFileManager* defaultManager = nil; { const char* cpath = [self fileSystemRepresentationWithPath: path]; -#if defined(__WIN32__) - return SetCurrentDirectory(cpath); +#if defined(__MINGW__) + return SetCurrentDirectory(cpath) == TRUE ? YES : NO; #else return (chdir(cpath) == 0); #endif @@ -216,7 +216,7 @@ static NSFileManager* defaultManager = nil; - (BOOL) createDirectoryAtPath: (NSString*)path attributes: (NSDictionary*)attributes { -#if defined(__WIN32__) +#if defined(__MINGW__) BOOL ok; ok = CreateDirectory([self fileSystemRepresentationWithPath: path], NULL); @@ -321,14 +321,14 @@ static NSFileManager* defaultManager = nil; while (cur < len); return YES; -#endif /* WIN32 */ +#endif /* !MINGW */ } - (NSString*) currentDirectoryPath { char path[PATH_MAX]; -#if defined(__WIN32__) +#if defined(__MINGW__) if (GetCurrentDirectory(PATH_MAX, path) > PATH_MAX) return nil; #else @@ -339,7 +339,7 @@ static NSFileManager* defaultManager = nil; if (getwd(path) == NULL) return nil; #endif /* HAVE_GETCWD */ -#endif /* WIN32 */ +#endif /* !MINGW */ return [self stringWithFileSystemRepresentation: path length: strlen(path)]; } @@ -716,7 +716,7 @@ static NSFileManager* defaultManager = nil; } else { -#if defined(__WIN32__) +#if defined(__MINGW__) DWORD res; res = GetFileAttributes(cpath); @@ -743,7 +743,7 @@ static NSFileManager* defaultManager = nil; } return YES; -#endif /* WIN32 */ +#endif /* MINGW */ } } @@ -755,7 +755,7 @@ static NSFileManager* defaultManager = nil; return NO; else { -#if defined(__WIN32__) +#if defined(__MINGW__) DWORD res= GetFileAttributes(cpath); if (res == WIN32ERR) @@ -775,7 +775,7 @@ static NSFileManager* defaultManager = nil; return NO; else { -#if defined(__WIN32__) +#if defined(__MINGW__) DWORD res= GetFileAttributes(cpath); if (res == WIN32ERR) @@ -795,7 +795,7 @@ static NSFileManager* defaultManager = nil; return NO; else { -#if defined(__WIN32__) +#if defined(__MINGW__) DWORD res= GetFileAttributes(cpath); int len = strlen(cpath); @@ -839,7 +839,7 @@ static NSFileManager* defaultManager = nil; - (NSDictionary*) fileSystemAttributesAtPath: (NSString*)path { -#if defined(__WIN32__) +#if defined(__MINGW__) long long totalsize, freesize; id values[5]; id keys[5] = { @@ -912,7 +912,7 @@ static NSFileManager* defaultManager = nil; #else return nil; #endif -#endif /* WIN32 */ +#endif /* MINGW */ } - (BOOL) changeFileAttributes: (NSDictionary*)attributes atPath: (NSString*)path @@ -923,7 +923,7 @@ static NSFileManager* defaultManager = nil; NSDate *date; BOOL allOk = YES; -#ifndef __WIN32__ +#ifndef __MINGW__ num = [attributes objectForKey: NSFileOwnerAccountNumber]; if (num) { @@ -990,7 +990,7 @@ static NSFileManager* defaultManager = nil; ASSIGN(_lastError, str); } } -#endif /* __WIN32__ */ +#endif /* __MINGW__ */ num = [attributes objectForKey: NSFilePosixPermissions]; if (num) @@ -1123,7 +1123,7 @@ static NSFileManager* defaultManager = nil; const char* lpath = [self fileSystemRepresentationWithPath: path]; const char* npath = [self fileSystemRepresentationWithPath: otherPath]; -#ifdef __WIN32__ +#ifdef __MINGW__ return NO; #else return (symlink(lpath, npath) == 0); @@ -1146,7 +1146,7 @@ static NSFileManager* defaultManager = nil; - (const char*) fileSystemRepresentationWithPath: (NSString*)path { -#if 0 && defined(__WIN32__) +#if 0 && defined(__MINGW__) unsigned len = [path length]; NSMutableData *d = [NSMutableData dataWithLength: len + 5]; char *fspath = (char*)[d mutableBytes]; diff --git a/Source/NSHost.m b/Source/NSHost.m index 998c3ee5f..9672228fb 100644 --- a/Source/NSHost.m +++ b/Source/NSHost.m @@ -34,15 +34,15 @@ #include /* #include */ -#if defined(__WIN32__) && !defined(__CYGWIN__) -#include +#if defined(__MINGW__) +#include #else #include #include #include #include #include -#endif /* __WIN32__*/ +#endif /* !__MINGW__*/ #ifndef INADDR_NONE #define INADDR_NONE -1 diff --git a/Source/NSLog.m b/Source/NSLog.m index c28ec95cc..7cf18ec23 100644 --- a/Source/NSLog.m +++ b/Source/NSLog.m @@ -97,7 +97,7 @@ NSLogv (NSString* format, va_list args) if (_NSLog_printf_handler == NULL) _NSLog_printf_handler = *_NSLog_standard_printf_handler; -#if defined(__WIN32__) +#if defined(__MINGW__) pid = (int)GetCurrentProcessId(), #else pid = (int)getpid(); diff --git a/Source/NSPage.m b/Source/NSPage.m index 2202b9023..34b271a5a 100644 --- a/Source/NSPage.m +++ b/Source/NSPage.m @@ -25,7 +25,7 @@ #include #include #include -#ifndef __WIN32__ +#ifndef __MINGW__ #include #endif #include @@ -38,7 +38,7 @@ #include #endif -#ifdef __WIN32__ +#ifdef __MINGW__ #include static size_t getpagesize(void) diff --git a/Source/NSProcessInfo.m b/Source/NSProcessInfo.m index 3f98be61d..27f9f4e71 100644 --- a/Source/NSProcessInfo.m +++ b/Source/NSProcessInfo.m @@ -184,7 +184,7 @@ _gnu_process_args(int argc, char *argv[], char *env[]) i = 0; while (env[i]) { -#if defined(__WIN32__) +#if defined(__MINGW__) char buf[1024]; char *cp; DWORD len; @@ -486,7 +486,7 @@ extern char** _environ; #undef main int main(int argc, char *argv[], char *env[]) { -#if defined(__WIN32__) && !defined(__CYGWIN__) +#if defined(__MINGW__) WSADATA lpWSAData; // Initialize Windows Sockets @@ -495,7 +495,7 @@ int main(int argc, char *argv[], char *env[]) printf("Could not startup Windows Sockets\n"); exit(1); } -#endif /* __WIN32__ */ +#endif /* __MINGW__ */ #ifdef __MS_WIN32__ _MB_init_runtime(); @@ -566,7 +566,7 @@ int main(int argc, char *argv[], char *env[]) { int pid; -#if defined(__WIN32__) +#if defined(__MINGW__) pid = (int)GetCurrentProcessId(); #else pid = (int)getpid(); diff --git a/Source/NSString.m b/Source/NSString.m index cf2ea814c..483d641dd 100644 --- a/Source/NSString.m +++ b/Source/NSString.m @@ -117,7 +117,7 @@ static Class NSString_class; /* For speed */ #define GSPLUNI 1 #include "propList.h" -#if defined(__WIN32__) +#if defined(__MINGW__) static unichar pathSepChar = (unichar)'\\'; static NSString *pathSepString = @"\\"; static NSString *rootPath = @"C:\\"; @@ -138,7 +138,7 @@ pathSeps() { if (myPathSeps == nil) { -#if defined(__WIN32__) +#if defined(__MINGW__) myPathSeps = [NSCharacterSet characterSetWithCharactersInString: @"/\\"]; #else myPathSeps = [NSCharacterSet characterSetWithCharactersInString: @"/"]; @@ -2121,7 +2121,7 @@ handle_printf_atsign (FILE *stream, - (NSString*) stringByResolvingSymlinksInPath { -#if defined(__WIN32__) +#if defined(__MINGW__) return self; #else const int MAX_PATH = 1024; @@ -2268,7 +2268,7 @@ handle_printf_atsign (FILE *stream, strcpy(new_buf, &new_buf[8]); } return [NSString stringWithCString: new_buf]; -#endif /* (__WIN32__) */ +#endif /* (__MINGW__) */ } - (NSString*) stringByStandardizingPath @@ -2317,10 +2317,10 @@ handle_printf_atsign (FILE *stream, return s; /* - * For absolute paths, we must resolve symbolic links or (on win32) + * For absolute paths, we must resolve symbolic links or (on MINGW) * remove '/../' sequences and their matching parent directories. */ -#if defined(__WIN32__) +#if defined(__MINGW__) /* Condense `/../' */ r = NSMakeRange(0, [s length]); while ((r = [s rangeOfCharacterFromSet: pathSeps() @@ -2400,7 +2400,7 @@ handle_printf_atsign (FILE *stream, if ([self length] == 0) return NO; -#if defined(__WIN32__) +#if defined(__MINGW__) if ([self indexOfString: @":"] != NSNotFound) return YES; #else diff --git a/Source/NSTask.m b/Source/NSTask.m index 1e41117e7..d08b5a3e4 100644 --- a/Source/NSTask.m +++ b/Source/NSTask.m @@ -361,9 +361,6 @@ GSCheckTasks() #endif } -/* Declaration from find_exec.c */ -extern char *objc_find_executable(const char *name); - - (void) launch { NSMutableArray *toClose; @@ -427,29 +424,21 @@ extern char *objc_find_executable(const char *name); lpath = [base_path stringByAppendingPathComponent: prog]; if ([mgr isExecutableFileAtPath: lpath] == NO) { - const char *cpath = 0; - /* * Last resort - if the launch path was simply a program name - * get objc_find_executable() to try using the PATH environment + * get NSBundle to try using the PATH environment * variable to find the executable. */ if ([base_path isEqualToString: @""] == YES) { - - cpath = objc_find_executable([prog cString]); + lpath = [NSBundle _absolutePathOfExecutable: prog]; } - if (cpath == 0) + if (lpath == nil) { [NSException raise: NSInvalidArgumentException - format: @"NSTask - launch path (%@) is not valid", + format: @"NSTask - launch path (%@) not valid", _launchPath]; } - else - { - lpath = [NSString stringWithCString: cpath]; - OBJC_FREE((void*)cpath); - } } } } @@ -552,7 +541,7 @@ extern char *objc_find_executable(const char *name); setpgrp(getpid(), getpid()); #endif #else -#if defined(__WIN32__) +#if defined(__MINGW__) pid = (int)GetCurrentProcessId(), #else pid = (int)getpid(); diff --git a/Source/NSThread.m b/Source/NSThread.m index c93eb776c..f89e7acdf 100644 --- a/Source/NSThread.m +++ b/Source/NSThread.m @@ -254,7 +254,7 @@ gnustep_base_thread_callback() #ifdef HAVE_USLEEP usleep (30*60*1000000); #else -#if defined(__WIN32__) +#if defined(__MINGW__) Sleep (30*60*1000); #else sleep (30*60); @@ -269,7 +269,7 @@ gnustep_base_thread_callback() #ifdef HAVE_USLEEP usleep ((int)(delay*1000000)); #else -#if defined(__WIN32__) +#if defined(__MINGW__) Sleep (delay*1000); #else sleep ((int)delay); diff --git a/Source/NSUser.m b/Source/NSUser.m index dc496a989..701c67431 100644 --- a/Source/NSUser.m +++ b/Source/NSUser.m @@ -115,7 +115,7 @@ NSHomeDirectory(void) NSString * NSHomeDirectoryForUser(NSString *login_name) { -#if !defined(__WIN32__) +#if !defined(__MINGW__) struct passwd *pw; [gnustep_global_lock lock]; @@ -140,12 +140,14 @@ NSHomeDirectoryForUser(NSString *login_name) s = [NSString stringWithCString: nb]; NSZoneFree(NSDefaultMallocZone(), nb); } - else + else if (n > 0) { /* null terminate it and return the string */ buf[n] = '\0'; s = [NSString stringWithCString: buf]; } + else + s = NSOpenStepRootDirectory(); [gnustep_global_lock unlock]; return s; #endif @@ -289,7 +291,7 @@ NSOpenStepRootDirectory(void) objectForKey: @"GNUSTEP_ROOT"]; if (root == nil) -#if defined(__WIN32__) +#if defined(__MINGW__) root = @"C:\\"; #else root = @"/"; diff --git a/Source/UdpPort.m b/Source/UdpPort.m index 4c76548d7..33c693adc 100644 --- a/Source/UdpPort.m +++ b/Source/UdpPort.m @@ -37,14 +37,14 @@ #include #endif /* _AIX */ -#ifdef __WIN32__ +#ifdef __MINGW__ #include #else #include #include #include #include -#endif /* !__WIN32__ */ +#endif /* !__MINGW__ */ /* For IRIX machines, which don't define this */ #ifndef IPPORT_USERRESERVED @@ -262,11 +262,11 @@ static NSMapTable *port_number_2_in_port = NULL; { if (_is_valid) { -#if defined(__WIN32__) +#if defined(__MINGW__) closesocket (_port_socket); #else close (_port_socket); -#endif /* __WIN32__ */ +#endif /* __MINGW__ */ [super invalidate]; } } diff --git a/Source/UnixFileHandle.m b/Source/UnixFileHandle.m index 2f5d9ddc0..527511dec 100644 --- a/Source/UnixFileHandle.m +++ b/Source/UnixFileHandle.m @@ -36,8 +36,8 @@ #include #include -#if defined(__WIN32__) && !defined(__CYGWIN__) -#include +#if defined(__MINGW__) +#include #else #include #include @@ -46,7 +46,7 @@ #include #include #include -#endif /* __WIN32__ */ +#endif /* __MINGW__ */ #include #include diff --git a/Source/find_exec.c b/Source/find_exec.c deleted file mode 100644 index 386f0f1eb..000000000 --- a/Source/find_exec.c +++ /dev/null @@ -1,241 +0,0 @@ -/* - find_exec.c - routine to find the executable path - - From the dld distribution -- copyrighted below. - Modified by Adam Fedor - traverse links - - Given a filename, objc_find_executable searches the directories listed in - environment variable PATH for a file with that filename. - A new copy of the complete path name of that file is returned. This new - string may be disposed by free() later on. -*/ - -/* This file is part of DLD, a dynamic link/unlink editor for C. - - Copyright (C) 1990 by W. Wilson Ho. - - The author can be reached electronically by how@cs.ucdavis.edu or - through physical mail at: - - W. Wilson Ho - Division of Computer Science - University of California at Davis - Davis, CA 95616 -*/ - -/* This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 1, or (at your option) any - later version. -*/ - -#include -#include - -#include - -#ifdef __WIN32__ -#include -#define S_IFLNK 0120000 -int readlink(char *path, char *buf, int bufsiz) { return (-1); } -int lstat(char *path, struct stat *buf) { return (-1); } -#define MAXPATHLEN 255 -#else -#include -#include -#include -#endif /* __WIN32__ */ - -#include -#include - -#define DEFAULT_PATH ".:~/bin::/usr/local/bin:/usr/new:/usr/ucb:/usr/bin:/bin:/usr/hosts" - -#if defined(__WIN32__) || defined(_WIN32) -#define PATH_SEPARATOR ';' -#define PATH_COMPONENT "\\" -#else -#define PATH_SEPARATOR ':' -#define PATH_COMPONENT "/" -#endif - -/* ABSOLUTE_FILENAME_P (fname): True if fname is an absolute filename */ -#if defined(atarist) || defined(__WIN32__) || defined(_WIN32) -#define ABSOLUTE_FILENAME_P(fname) ((fname[0] == '/') || \ - (fname[0] && (fname[1] == ':'))) -#else -#define ABSOLUTE_FILENAME_P(fname) (fname[0] == '/') -#endif /* atarist */ - -static char * -copy_of (s) -register char *s; -{ - register char *p = (char *) malloc (strlen(s)+1); - - if (!p) return 0; - - *p = 0; - strcpy (p, s); - return p; -} - -static int -find_full_path(char *path) -{ - struct stat statbuf; - - if ( stat(path, &statbuf) != 0) - return -1; - - if ( (lstat(path, &statbuf) == 0) - && (statbuf.st_mode & S_IFLNK) == S_IFLNK) { - char link[MAXPATHLEN+1]; - int cc; - cc = readlink(path, link, MAXPATHLEN); - if (cc == -1) - return -1; - link[cc] = '\0'; - if (ABSOLUTE_FILENAME_P(link)) { - strcpy(path, link); - } else if (strlen(path)+strlen(link) < MAXPATHLEN) { - char *p; - p = strrchr(path, '/'); - if (p) - *(p+1) = '\0'; - strcat(path, link); - } else - return -1; - } - - return 0; -} - -char * -objc_find_executable (const char *file) -{ - char *search; - register char *p; - int cwd_in_path = 0; - - if (ABSOLUTE_FILENAME_P(file)) { - search = copy_of(file); - find_full_path(search); - return search; -/* - return copy_of (file); -*/ - } - - if ((search = (char *) getenv("PATH")) == 0) - search = DEFAULT_PATH; - - p = search; - - while (*p) { - char name[MAXPATHLEN]; - register char *next; - - next = name; - - /* copy directory name into [name] */ - while (*p && *p != PATH_SEPARATOR) *next++ = *p++; - *next = 0; - if (*p) p++; - - if (name[0] == '.' && name[1] == 0) { -#ifdef HAVE_GETCWD - getcwd (name, MAXPATHLEN); -#else - getwd (name); -#endif - cwd_in_path = 1; - } - - strcat (name, PATH_COMPONENT); - strcat (name, file); - -/* - if (access (name, X_OK) == 0) -*/ - if (find_full_path (name) == 0) - return copy_of (name); - - /* Also add common executable extensions on windows */ -#if defined(__WIN32__) || defined(_WIN32) - { - int fl = strlen(name); - - strcat (name, ".com"); - if (find_full_path (name) == 0) - return copy_of (name); - name[fl] = '\0'; - - strcat (name, ".exe"); - if (find_full_path (name) == 0) - return copy_of (name); - name[fl] = '\0'; - - strcat (name, ".bat"); - if (find_full_path (name) == 0) - return copy_of (name); - name[fl] = '\0'; - - strcat (name, ".cmd"); - if (find_full_path (name) == 0) - return copy_of (name); - name[fl] = '\0'; - } -#endif - } - - /* - If '.' not in PATH, check this too - */ - if (!cwd_in_path) { - char name[MAXPATHLEN]; - -#ifdef HAVE_GETCWD - getcwd (name, MAXPATHLEN); -#else - getwd (name); -#endif - strcat (name, PATH_COMPONENT); - strcat (name, file); - -/* - if (access (name, X_OK) == 0) -*/ - if (find_full_path (name) == 0) - return copy_of (name); - - /* Also add common executable extensions on windows */ -#if defined(__WIN32__) || defined(_WIN32) - { - int fl = strlen(name); - - strcat (name, ".com"); - if (find_full_path (name) == 0) - return copy_of (name); - name[fl] = '\0'; - - strcat (name, ".exe"); - if (find_full_path (name) == 0) - return copy_of (name); - name[fl] = '\0'; - - strcat (name, ".bat"); - if (find_full_path (name) == 0) - return copy_of (name); - name[fl] = '\0'; - - strcat (name, ".cmd"); - if (find_full_path (name) == 0) - return copy_of (name); - name[fl] = '\0'; - } -#endif - } - - return 0; -} diff --git a/Source/find_exec.m b/Source/find_exec.m deleted file mode 100644 index 386f0f1eb..000000000 --- a/Source/find_exec.m +++ /dev/null @@ -1,241 +0,0 @@ -/* - find_exec.c - routine to find the executable path - - From the dld distribution -- copyrighted below. - Modified by Adam Fedor - traverse links - - Given a filename, objc_find_executable searches the directories listed in - environment variable PATH for a file with that filename. - A new copy of the complete path name of that file is returned. This new - string may be disposed by free() later on. -*/ - -/* This file is part of DLD, a dynamic link/unlink editor for C. - - Copyright (C) 1990 by W. Wilson Ho. - - The author can be reached electronically by how@cs.ucdavis.edu or - through physical mail at: - - W. Wilson Ho - Division of Computer Science - University of California at Davis - Davis, CA 95616 -*/ - -/* This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 1, or (at your option) any - later version. -*/ - -#include -#include - -#include - -#ifdef __WIN32__ -#include -#define S_IFLNK 0120000 -int readlink(char *path, char *buf, int bufsiz) { return (-1); } -int lstat(char *path, struct stat *buf) { return (-1); } -#define MAXPATHLEN 255 -#else -#include -#include -#include -#endif /* __WIN32__ */ - -#include -#include - -#define DEFAULT_PATH ".:~/bin::/usr/local/bin:/usr/new:/usr/ucb:/usr/bin:/bin:/usr/hosts" - -#if defined(__WIN32__) || defined(_WIN32) -#define PATH_SEPARATOR ';' -#define PATH_COMPONENT "\\" -#else -#define PATH_SEPARATOR ':' -#define PATH_COMPONENT "/" -#endif - -/* ABSOLUTE_FILENAME_P (fname): True if fname is an absolute filename */ -#if defined(atarist) || defined(__WIN32__) || defined(_WIN32) -#define ABSOLUTE_FILENAME_P(fname) ((fname[0] == '/') || \ - (fname[0] && (fname[1] == ':'))) -#else -#define ABSOLUTE_FILENAME_P(fname) (fname[0] == '/') -#endif /* atarist */ - -static char * -copy_of (s) -register char *s; -{ - register char *p = (char *) malloc (strlen(s)+1); - - if (!p) return 0; - - *p = 0; - strcpy (p, s); - return p; -} - -static int -find_full_path(char *path) -{ - struct stat statbuf; - - if ( stat(path, &statbuf) != 0) - return -1; - - if ( (lstat(path, &statbuf) == 0) - && (statbuf.st_mode & S_IFLNK) == S_IFLNK) { - char link[MAXPATHLEN+1]; - int cc; - cc = readlink(path, link, MAXPATHLEN); - if (cc == -1) - return -1; - link[cc] = '\0'; - if (ABSOLUTE_FILENAME_P(link)) { - strcpy(path, link); - } else if (strlen(path)+strlen(link) < MAXPATHLEN) { - char *p; - p = strrchr(path, '/'); - if (p) - *(p+1) = '\0'; - strcat(path, link); - } else - return -1; - } - - return 0; -} - -char * -objc_find_executable (const char *file) -{ - char *search; - register char *p; - int cwd_in_path = 0; - - if (ABSOLUTE_FILENAME_P(file)) { - search = copy_of(file); - find_full_path(search); - return search; -/* - return copy_of (file); -*/ - } - - if ((search = (char *) getenv("PATH")) == 0) - search = DEFAULT_PATH; - - p = search; - - while (*p) { - char name[MAXPATHLEN]; - register char *next; - - next = name; - - /* copy directory name into [name] */ - while (*p && *p != PATH_SEPARATOR) *next++ = *p++; - *next = 0; - if (*p) p++; - - if (name[0] == '.' && name[1] == 0) { -#ifdef HAVE_GETCWD - getcwd (name, MAXPATHLEN); -#else - getwd (name); -#endif - cwd_in_path = 1; - } - - strcat (name, PATH_COMPONENT); - strcat (name, file); - -/* - if (access (name, X_OK) == 0) -*/ - if (find_full_path (name) == 0) - return copy_of (name); - - /* Also add common executable extensions on windows */ -#if defined(__WIN32__) || defined(_WIN32) - { - int fl = strlen(name); - - strcat (name, ".com"); - if (find_full_path (name) == 0) - return copy_of (name); - name[fl] = '\0'; - - strcat (name, ".exe"); - if (find_full_path (name) == 0) - return copy_of (name); - name[fl] = '\0'; - - strcat (name, ".bat"); - if (find_full_path (name) == 0) - return copy_of (name); - name[fl] = '\0'; - - strcat (name, ".cmd"); - if (find_full_path (name) == 0) - return copy_of (name); - name[fl] = '\0'; - } -#endif - } - - /* - If '.' not in PATH, check this too - */ - if (!cwd_in_path) { - char name[MAXPATHLEN]; - -#ifdef HAVE_GETCWD - getcwd (name, MAXPATHLEN); -#else - getwd (name); -#endif - strcat (name, PATH_COMPONENT); - strcat (name, file); - -/* - if (access (name, X_OK) == 0) -*/ - if (find_full_path (name) == 0) - return copy_of (name); - - /* Also add common executable extensions on windows */ -#if defined(__WIN32__) || defined(_WIN32) - { - int fl = strlen(name); - - strcat (name, ".com"); - if (find_full_path (name) == 0) - return copy_of (name); - name[fl] = '\0'; - - strcat (name, ".exe"); - if (find_full_path (name) == 0) - return copy_of (name); - name[fl] = '\0'; - - strcat (name, ".bat"); - if (find_full_path (name) == 0) - return copy_of (name); - name[fl] = '\0'; - - strcat (name, ".cmd"); - if (find_full_path (name) == 0) - return copy_of (name); - name[fl] = '\0'; - } -#endif - } - - return 0; -}