Path fixes, etc, to work on MINGW.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@7581 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Adam Fedor 2000-09-22 04:20:52 +00:00
parent 47eb44d12d
commit 4ae2035ea0
19 changed files with 209 additions and 93 deletions

View file

@ -1,3 +1,36 @@
2000-09-21 Adam Fedor <fedor@gnu.org>
* configure.in: Check for rint.
* Source/GSCompatibility.m: Define rint if not available.
* Source/NSData.m (readContentsOfFile): Remove incorrectly used
variable (MINGW).
* Source/NSFileManager.m (-removeFileAtPath:handler:): Use more
direct check if path is a dir.
(directoryContentsAtPath): Likewise.
(isExecutableFileAtPath): On MINGW, Return YES if a directory.
(fileSystemRepresentationWithPath:): On MINGW, fix up paths that might
come from Unix-like shells, like Cygwin bash, so they can be used with
Windows functions.
* Source/NSRunLoop.m (-acceptInputForMode:beforeDate:): On MINGW,
check for errno==0 and continue as if there was no error.
* Source/NSString.m (fileSystemRepresentation): Use NSFileManager's
implementation.
(getFileSystemRepresentation:): Likewise.
(isAbsolutePath): Check fileSystemRepresentation.
* Source/NSTask.m: Use fileSystemRepresentation instead of cString.
* Source/NSUser.m (NSHomeDirectoryForUser): On MINGW, return nil
if no home found.
* Source/NSUser.m (pathForUser): Use GNUSTEP_ROOT if no user home
found.
* Testing/nsconnection_client.m: Use impl of getopt for MINGW.
* Testing/nsconnection_server.m: Likewise.
* Testing/nsscanner.m: Likewise.
* Testing/nstask.m: Launch an appropriate Windows task.
* Testing/nsstring.m: Catch exception during inappropriate
string replacement.
2000-09-21 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/gnustep/base/NSURLHandle.h: tidy up.

View file

@ -93,6 +93,9 @@
/* Define if you have the realpath function. */
#undef HAVE_REALPATH
/* Define if you have the rint function. */
#undef HAVE_RINT
/* Define if you have the setpgid function. */
#undef HAVE_SETPGID

View file

@ -1,47 +0,0 @@
Installing on Windows NT/95
***************************
This file is maintained by Scott Christley <scottc@net-community.com>.
If you have questions about the installation procedure on WIN32,
please contact Scott.
The system requires that you have headers and libraries for the WIN32
API and ANSI-C. If you have a working bash shell then you should run
the normal Unix ./configure shell script; otherwise, you can follow
these instructions and run the configure.bat batch file.
Quick installation instructions:
configure
make
make install
Detailled installation instructions:
1. Install `gcc'. The library requires gcc version
2.7.0 or later.
2. Configure the package for your system. Review the Makefile.sed.nt
files which is used to process Makefile.in to create a working
Makefiles. They exist in the directories: ./ , ./checks , ./src
Of interest are:
'libdir' where to install the library file
'includedir' where to install the headers
'install' make rules to install libobjects
3. Run 'configure.bat' to create the Makefiles, and the header configuration
file 'src/include/config.h'
4. Type `make' to compile the package. If you want, you can override
the `make' variables `CFLAGS' like this:
make CFLAGS=-O2
5. Type `make install' to install the library, data files, header
files, and documentation.
6. You can remove the program binaries and object files from the
source directory by typing `make clean'. To also remove the
Makefile(s), and `config.status' (all the files that `configure'
created), type `make distclean'.

View file

@ -24,6 +24,14 @@
#include <config.h>
#include <Foundation/Foundation.h>
#ifndef HAVE_RINT
#include <math.h>
static double rint(double a)
{
return (floor(a+0.5));
}
#endif
/*
* Runtime MacOS-X compatibility flags.
*/

View file

@ -124,7 +124,6 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len, NSZone* zone)
#if defined(__MINGW__)
HANDLE fh;
DWORD fileLength;
DWORD fileSize;
DWORD high;
DWORD got;
#else
@ -173,7 +172,7 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len, NSZone* zone)
thePath, fileLength, strerror(errno));
return NO;
}
if (!ReadFile(fh, tmp, fileSize, &got, 0))
if (!ReadFile(fh, tmp, fileLength, &got, 0))
{
if (tmp != 0)
{
@ -183,7 +182,7 @@ readContentsOfFile(NSString* path, void** buf, unsigned* len, NSZone* zone)
return NO;
}
}
if (got != fileSize)
if (got != fileLength)
{
NSZoneFree(zone, tmp);
CloseHandle(fh);
@ -617,6 +616,7 @@ failure:
{
char thePath[BUFSIZ*2+8];
char theRealPath[BUFSIZ*2];
NSString *tmppath;
FILE *theFile;
int c;
#if defined(__MINGW__)
@ -635,9 +635,9 @@ failure:
#if defined(__MINGW__)
if (useAuxiliaryFile)
{
path = [path stringByAppendingPathExtension: @"tmp"];
tmppath = [path stringByAppendingPathExtension: @"tmp"];
}
if ([path getFileSystemRepresentation: thePath
if ([tmppath getFileSystemRepresentation: thePath
maxLength: sizeof(thePath)-1] == NO)
{
NSDebugLog(@"Open (%s) attempt failed - bad path", thePath);
@ -750,6 +750,7 @@ failure:
att = [[mgr fileAttributesAtPath: path
traverseLink: YES] mutableCopy];
IF_NO_GC(TEST_AUTORELEASE(att));
[mgr removeFileAtPath: path handler: nil];
}
c = rename(thePath, theRealPath);

View file

@ -33,6 +33,7 @@
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSLock.h>
#include <Foundation/NSDebug.h>
#include <Foundation/NSProcessInfo.h>
#include <stdio.h>
@ -536,13 +537,16 @@ static NSFileManager* defaultManager = nil;
- (BOOL) removeFileAtPath: (NSString*)path
handler: handler
{
NSArray *contents;
BOOL exists, is_dir;
if (handler != nil)
[handler fileManager: self willProcessPath: path];
contents = [self directoryContentsAtPath: path];
if (contents == nil)
exists = [self fileExistsAtPath: path isDirectory: &is_dir];
if (!exists)
return NO;
if (!is_dir)
{
const char *cpath = [path fileSystemRepresentation];
@ -575,6 +579,7 @@ static NSFileManager* defaultManager = nil;
}
else
{
NSArray *contents = [self directoryContentsAtPath: path];
unsigned count = [contents count];
unsigned i;
@ -872,6 +877,10 @@ static NSFileManager* defaultManager = nil;
return NO;
if (len > 4 && strcmp(&cpath[len-4], ".exe") == 0)
return YES;
/* FIXME: On unix, directory accessable == executable, so we simulate that
here for Windows. Is there a better check for directory access? */
if (res & FILE_ATTRIBUTE_DIRECTORY)
return YES;
return NO;
#else
return (access(cpath, X_OK) == 0);
@ -1121,14 +1130,12 @@ static NSFileManager* defaultManager = nil;
IMP nxtImp;
IMP addImp;
NSDictionary *attr;
NSString *type;
BOOL is_dir;
/*
* See if this is a directory (don't follow links).
*/
attr = [self fileAttributesAtPath: path traverseLink: NO];
type = [attr objectForKey: NSFileType];
if ([type isEqualToString: NSFileTypeDirectory] == NO)
if ([self fileExistsAtPath: path isDirectory: &is_dir] == NO || is_dir == NO)
return nil;
direnum = [[NSDirectoryEnumerator alloc] initWithDirectoryPath: path
@ -1221,32 +1228,38 @@ static NSFileManager* defaultManager = nil;
- (const char*) fileSystemRepresentationWithPath: (NSString*)path
{
#if 0 && defined(__MINGW__)
unsigned len = [path length];
NSMutableData *d = [NSMutableData dataWithLength: len + 5];
char *fspath = (char*)[d mutableBytes];
[path getCString: &fspath[4]];
fspath[len+4] = '\0';
// Check if path specifies drive number or is current drive
if (fspath[4] && (fspath[5] == ': '))
#ifdef __MINGW__
/* If path is in Unix format, transmorgrify it so Windows functions
can handle it */
NSString *newpath = path;
const char *c_path = [path cString];
if (c_path[0] == '/' && c_path[1] == '/' && isalpha(c_path[2]))
{
fspath[0] = fspath[4];
fspath[1] = fspath[5];
fspath[2] = '\\';
fspath[3] = '\0';
/* Cygwin "//c/" type absolute path */
newpath = [NSString stringWithFormat: @"%c:%s", c_path[2], &c_path[3]];
newpath = [newpath stringByReplacingString: @"/" withString: @"\\"];
}
else
else if (isalpha(c_path[0]) && c_path[1] == ':')
{
fspath = &fspath[2];
fspath[0] = '\\';
fspath[1] = '\0';
/* Unix absolute path */
newpath = [newpath stringByReplacingString: @"/" withString: @"\\"];
}
return fspath;
#else
return [path cString];
else if (c_path[0] == '/')
{
NSDictionary *env;
env = [[NSProcessInfo processInfo] environment];
if ([env objectForKey: @"CYGWIN"])
{
/* FIXME: Find cygwin drive? */
newpath = @"c:/cygwin";
newpath = [newpath stringByAppendingPathComponent: path];
newpath = [newpath stringByReplacingString: @"/" withString: @"\\"];
}
}
/* FIXME: Should we translate relative paths? */
return [newpath cString];
#endif
return [path cString];
}
- (NSString*) stringWithFileSystemRepresentation: (const char*)string

View file

@ -1204,12 +1204,20 @@ const NSMapTableValueCallBacks ArrayMapValueCallBacks =
GSCheckTasks();
select_return = 0;
}
#ifdef __MINGW__
else if (errno == 0)
{
/* MinGW often returns an errno == 0. Not sure why */
select_return = 0;
}
#endif
else
{
/* Some exceptional condition happened. */
/* xxx We can do something with exception_fds, instead of
aborting here. */
perror ("[NSRunLoop acceptInputForMode: beforeDate: ] select()");
NSLog (@"select() error in -acceptInputForMode:beforeDate: '%s'",
strerror(errno));
abort ();
}
}

View file

@ -1971,12 +1971,12 @@ handle_printf_atsign (FILE *stream,
/* Return a string for passing to OS calls to handle file system objects. */
- (const char*) fileSystemRepresentation
{
return [self cString];
return [[NSFileManager defaultManager] fileSystemRepresentationWithPath: self];
}
- (BOOL) getFileSystemRepresentation: (char*)buffer maxLength: (unsigned)size
{
const char* ptr = [self cString];
const char* ptr = [self fileSystemRepresentation];
if (strlen(ptr) > size)
return NO;
strcpy(buffer, ptr);
@ -2471,7 +2471,15 @@ handle_printf_atsign (FILE *stream,
return NO;
#if defined(__MINGW__)
if ([self indexOfString: @":"] != NSNotFound)
if ([self indexOfString: @":"] == NSNotFound)
{
const char *cpath = [self fileSystemRepresentation];
if (isalpha(cpath[0]) && cpath[1] == ':')
return YES;
else
return NO;
}
else
return YES;
#else
{

View file

@ -592,14 +592,14 @@ GSCheckTasks()
start_info.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
start_info.hStdError = GetStdHandle(STD_ERROR_HANDLE);
result = CreateProcess([lpath cString],
result = CreateProcess([lpath fileSystemRepresentation],
c_args,
NULL, /* proc attrs */
NULL, /* thread attrs */
1, /* inherit handles */
0, /* creation flags */
NULL, /* env block */
[[self currentDirectoryPath] cString],
[[self currentDirectoryPath] fileSystemRepresentation],
&start_info,
&proc_info);
objc_free(c_args);
@ -717,7 +717,7 @@ GSCheckTasks()
}
lpath = [self _fullLaunchPath];
executable = [lpath cString];
executable = [lpath fileSystemRepresentation];
args[0] = executable;
for (i = 0; i < ac; i++)
@ -744,7 +744,7 @@ GSCheckTasks()
}
envl[ec] = 0;
path = [[self currentDirectoryPath] cString];
path = [[self currentDirectoryPath] fileSystemRepresentation];
toClose = [NSMutableArray arrayWithCapacity: 3];
hdl = [self standardInput];

View file

@ -147,7 +147,7 @@ NSHomeDirectoryForUser(NSString *login_name)
s = [NSString stringWithCString: buf];
}
else
s = NSOpenStepRootDirectory();
s = nil;
[gnustep_global_lock unlock];
return s;
#endif

View file

@ -297,9 +297,13 @@ static NSString *pathForUser(NSString *user)
home = NSHomeDirectoryForUser(user);
if (home == nil)
{
return nil;
/* Probably on MINGW. Where to put it? */
NSLog(@"Could not get home dir. Using GNUSTEP_ROOT");
home = NSOpenStepRootDirectory();
path = home;
}
path = [home stringByAppendingPathComponent: GNU_UserDefaultsPrefix];
else
path = [home stringByAppendingPathComponent: GNU_UserDefaultsPrefix];
if ([mgr fileExistsAtPath: path isDirectory: &isDir] == NO)
{
NSLog(@"Directory '%@' does not exist - creating it", path);

View file

@ -13,6 +13,8 @@
#include <assert.h>
#include "server.h"
#include "wgetopt.h"
@interface Auth : NSObject
@end
@ -340,8 +342,10 @@ int main (int argc, char *argv[], char **env)
id cobj, prx;
NSAutoreleasePool *arp;
Auth *auth;
#ifndef __MINGW__
extern int optind;
extern char *optarg;
#endif
[NSProcessInfo initializeWithArguments: argv count: argc environment: env];
arp = [NSAutoreleasePool new];

View file

@ -9,6 +9,8 @@
#include <Foundation/NSAutoreleasePool.h>
#include "server.h"
#include "wgetopt.h"
@implementation Server
- (NSData*) authenticationDataForComponents: (NSMutableArray*)components
@ -402,8 +404,10 @@ int main(int argc, char *argv[], char **env)
id o = [[NSObject alloc] init];
NSConnection *c;
NSAutoreleasePool *arp = [NSAutoreleasePool new];
#ifndef __MINGW__
extern int optind;
extern char *optarg;
#endif
[NSProcessInfo initializeWithArguments: argv count: argc environment: env];
debug = 0;

View file

@ -19,6 +19,8 @@
#include <math.h>
#include <stdio.h>
#include "wgetopt.h"
/*
* Doubles differing by this many least-significant-bits
* or less are assumed to be `equal'.

View file

@ -11,8 +11,13 @@ main()
pool = [[NSAutoreleasePool alloc] init];
#ifdef __MINGW__
task = [NSTask launchedTaskWithLaunchPath: @"C:\\WINDOWS\\COMMAND\\MEM.EXE"
arguments: nil];
#else
task = [NSTask launchedTaskWithLaunchPath: @"/bin/ls"
arguments: nil];
#endif
[task waitUntilExit];
printf("Exit status - %d\n", [task terminationStatus]);

View file

@ -1,4 +1,5 @@
#include <Foundation/NSString.h>
#include <Foundation/NSException.h>
// Fri Oct 23 02:58:47 MET DST 1998 dave@turbocat.de
// cStringNoCopy -> cString
@ -25,7 +26,11 @@ int main()
int a;
NSMutableString *fo = [NSMutableString stringWithString: @"abcdefg"];
NS_DURING
[fo replaceCharactersInRange: [fo rangeOfString: @"xx"] withString: @"aa"];
NS_HANDLER
printf("Caught exception during string replacement (expected)\n");
NS_ENDHANDLER
print_string(s);

65
Testing/wgetopt.h Normal file
View file

@ -0,0 +1,65 @@
#if (defined __MINGW__)
/* A simple implementation of getopt() */
static int
indexof(char c, char *string)
{
int i;
for (i = 0; i < strlen(string); i++)
{
if (string[i] == c)
{
return i;
}
}
return -1;
}
static char *optarg;
static int optind;
static char
getopt(int argc, char **argv, char *options)
{
static char *arg;
int index;
char retval = '\0';
optarg = NULL;
if (optind == 0)
{
optind = 1;
}
while (optind < argc)
{
arg = argv[optind];
if (strlen(arg) == 2)
{
if (arg[0] == '-')
{
if ((index = indexof(arg[1], options)) != -1)
{
retval = arg[1];
if (index < strlen(options))
{
if (options[index+1] == ':')
{
if (optind < argc-1)
{
optind++;
optarg = argv[optind];
}
else
{
return -1; /* ':' given, but argv exhausted */
}
}
}
}
}
}
optind++;
return retval;
}
return -1;
}
#endif

2
configure vendored
View file

@ -2831,7 +2831,7 @@ else
fi
done
for ac_func in statvfs symlink readlink geteuid
for ac_func in statvfs symlink readlink geteuid rint
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
echo "configure:2838: checking for $ac_func" >&5

View file

@ -541,7 +541,7 @@ AC_CHECK_HEADERS(values.h)
#--------------------------------------------------------------------
AC_CHECK_HEADERS(sys/stat.h sys/vfs.h sys/statfs.h sys/statvfs.h pwd.h grp.h)
AC_CHECK_HEADERS(sys/mount.h sys/types.h windows.h)
AC_CHECK_FUNCS(statvfs symlink readlink geteuid)
AC_CHECK_FUNCS(statvfs symlink readlink geteuid rint)
#--------------------------------------------------------------------
# These two headers (functions) needed by Time.m