From bd19ee1a689b5a5dc358fc3e02cc4837413d7485 Mon Sep 17 00:00:00 2001 From: fedor Date: Fri, 19 Mar 2004 18:34:46 +0000 Subject: [PATCH] Fix nil path handling git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@18858 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 9 +++++++++ Source/NSFileManager.m | 33 +++++++++++++++++++++++---------- Source/NSUser.m | 4 +++- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index ae1fedfbf..2d876c957 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2004-03-19 Adam Fedor + + * Source/NSFileManager.m (-createDirectoryAtPath:attributes:): + Return NO if path is nil. + (-createFileAtPath:contents:attributes:): Idem. + + * Source/NSUser.m (NSUserName): Set initial olduid to an invalid + uid. + 2004-03-16 Richard Frith-Macdonald * Source/NSDictionary.m: Don't use stack as temporary storage for diff --git a/Source/NSFileManager.m b/Source/NSFileManager.m index 2e795a48d..92aab5787 100644 --- a/Source/NSFileManager.m +++ b/Source/NSFileManager.m @@ -555,7 +555,19 @@ static NSFileManager* defaultManager = nil; NSEnumerator *paths = [[path pathComponents] objectEnumerator]; NSString *subPath; NSString *completePath = nil; +#else + const char *cpath; + char dirpath[PATH_MAX+1]; + struct stat statbuf; + int len, cur; + NSDictionary *needChown = nil; +#endif + /* This is consitent with MacOSX - just return NO for an invalid path. */ + if (path == nil) + return NO; + +#if defined(__MINGW__) while ((subPath = [paths nextObject])) { BOOL isDir = NO; @@ -583,12 +595,7 @@ static NSFileManager* defaultManager = nil; } #else - const char *cpath; - char dirpath[PATH_MAX+1]; - struct stat statbuf; - int len, cur; - NSDictionary *needChown = nil; - + /* * If there is no file owner specified, and we are running setuid to * root, then we assume we need to change ownership to correct user. @@ -701,12 +708,21 @@ static NSFileManager* defaultManager = nil; attributes: (NSDictionary*)attributes { const char *cpath = [self fileSystemRepresentationWithPath: path]; - #if defined(__MINGW__) HANDLE fh; DWORD written = 0; DWORD len = [contents length]; +#else + int fd; + int len; + int written; +#endif + /* This is consitent with MacOSX - just return NO for an invalid path. */ + if (path == nil) + return NO; + +#if defined(__MINGW__) fh = CreateFile(cpath, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (fh == INVALID_HANDLE_VALUE) @@ -728,9 +744,6 @@ static NSFileManager* defaultManager = nil; return YES; } #else - int fd; - int len; - int written; fd = open(cpath, GSBINIO|O_WRONLY|O_TRUNC|O_CREAT, 0644); if (fd < 0) diff --git a/Source/NSUser.m b/Source/NSUser.m index d846456be..2ebf8d15d 100644 --- a/Source/NSUser.m +++ b/Source/NSUser.m @@ -151,7 +151,9 @@ NSUserName(void) format: @"Unable to determine current user name"]; } #else - static int olduid = 0; + /* Set olduid to some invalid uid that we could never start off running + as. */ + static int olduid = -1; #ifdef HAVE_GETEUID int uid = geteuid(); #else