mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 00:30:53 +00:00
Win MSVC: add NSFileManager support
Also unifies _CHAR in NSFileManager with GSNativeChar, as they are internally required to be the same.
This commit is contained in:
parent
54ae296b69
commit
5fb5fb46c4
5 changed files with 1056 additions and 49 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
||||||
|
2021-03-12 Frederik Seiffert <frederik@algoriddim.com>
|
||||||
|
|
||||||
|
* Source/NSFileManager.m:
|
||||||
|
* Source/NSProcessInfo.m:
|
||||||
|
* Source/win32/dirent.h:
|
||||||
|
Add NSFileManager support on Windows MSVC using dirent.h from:
|
||||||
|
https://github.com/tronkko/dirent/blob/master/include/dirent.h
|
||||||
|
Also unifies _CHAR in NSFileManager with GSNativeChar, as they are
|
||||||
|
internally required to be the same.
|
||||||
|
|
||||||
2021-03-09 Frederik Seiffert <frederik@algoriddim.com>
|
2021-03-09 Frederik Seiffert <frederik@algoriddim.com>
|
||||||
|
|
||||||
* Source/NSRunLoop.m:
|
* Source/NSRunLoop.m:
|
||||||
|
|
|
@ -240,7 +240,7 @@ typedef gsuaddr gsaddr;
|
||||||
* Native character type for use in systemcalls etc.
|
* Native character type for use in systemcalls etc.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(__MINGW__)
|
#if defined(_WIN32)
|
||||||
# define GSNativeChar uint16_t
|
# define GSNativeChar uint16_t
|
||||||
#else
|
#else
|
||||||
# define GSNativeChar char
|
# define GSNativeChar char
|
||||||
|
|
|
@ -75,6 +75,9 @@
|
||||||
# include <sys/ndir.h>
|
# include <sys/ndir.h>
|
||||||
#elif defined(HAVE_NDIR_H)
|
#elif defined(HAVE_NDIR_H)
|
||||||
# include <ndir.h>
|
# include <ndir.h>
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
// we provide our own version of dirent.h on Windows MSVC
|
||||||
|
# include <win32/dirent.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_WINDOWS_H
|
#ifdef HAVE_WINDOWS_H
|
||||||
|
@ -196,28 +199,7 @@
|
||||||
* Macros to handle unichar filesystem support.
|
* Macros to handle unichar filesystem support.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_WIN32)
|
||||||
|
|
||||||
#warning NSFileManager is currently unsupported on Windows MSVC
|
|
||||||
|
|
||||||
#define _CHMOD(A,B) 0
|
|
||||||
#define _CLOSEDIR(A)
|
|
||||||
#define _OPENDIR(A) NULL
|
|
||||||
#define _READDIR(A) NULL
|
|
||||||
#define _RENAME(A,B) -1
|
|
||||||
#define _RMDIR(A) -1
|
|
||||||
#define _STAT(A,B) -1
|
|
||||||
#define _UTIME(A,B) -1
|
|
||||||
|
|
||||||
#define _CHAR unichar
|
|
||||||
#define _DIR void
|
|
||||||
#define _DIRENT {const char *d_name;}
|
|
||||||
#define _STATB {int st_ctime; int st_gid; int st_atime; int st_mtime; int st_mode; int st_uid; int st_size; int st_ino; int st_dev; int st_nlink;}
|
|
||||||
#define _UTIMB {int actime; int modtime;}
|
|
||||||
|
|
||||||
#define _NUL L'\0'
|
|
||||||
|
|
||||||
#elif defined(_WIN32)
|
|
||||||
|
|
||||||
#define _CHMOD(A,B) _wchmod(A,B)
|
#define _CHMOD(A,B) _wchmod(A,B)
|
||||||
#define _CLOSEDIR(A) _wclosedir(A)
|
#define _CLOSEDIR(A) _wclosedir(A)
|
||||||
|
@ -228,7 +210,6 @@
|
||||||
#define _STAT(A,B) _wstat(A,B)
|
#define _STAT(A,B) _wstat(A,B)
|
||||||
#define _UTIME(A,B) _wutime(A,B)
|
#define _UTIME(A,B) _wutime(A,B)
|
||||||
|
|
||||||
#define _CHAR unichar
|
|
||||||
#define _DIR _WDIR
|
#define _DIR _WDIR
|
||||||
#define _DIRENT _wdirent
|
#define _DIRENT _wdirent
|
||||||
#define _STATB _stat
|
#define _STATB _stat
|
||||||
|
@ -247,7 +228,6 @@
|
||||||
#define _STAT(A,B) stat(A,B)
|
#define _STAT(A,B) stat(A,B)
|
||||||
#define _UTIME(A,B) utime(A,B)
|
#define _UTIME(A,B) utime(A,B)
|
||||||
|
|
||||||
#define _CHAR char
|
|
||||||
#define _DIR DIR
|
#define _DIR DIR
|
||||||
#define _DIRENT dirent
|
#define _DIRENT dirent
|
||||||
#define _STATB stat
|
#define _STATB stat
|
||||||
|
@ -257,6 +237,7 @@
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define _CHAR GSNativeChar
|
||||||
#define _CCP const _CHAR*
|
#define _CCP const _CHAR*
|
||||||
|
|
||||||
|
|
||||||
|
@ -590,11 +571,7 @@ static NSStringEncoding defaultEncoding;
|
||||||
{
|
{
|
||||||
BOOL ok = NO;
|
BOOL ok = NO;
|
||||||
struct _STATB sb;
|
struct _STATB sb;
|
||||||
#if defined(_WIN32)
|
|
||||||
const _CHAR *lpath;
|
const _CHAR *lpath;
|
||||||
#else
|
|
||||||
const char *lpath;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
lpath = [self fileSystemRepresentationWithPath: path];
|
lpath = [self fileSystemRepresentationWithPath: path];
|
||||||
if (_STAT(lpath, &sb) != 0)
|
if (_STAT(lpath, &sb) != 0)
|
||||||
|
@ -1083,15 +1060,11 @@ static NSStringEncoding defaultEncoding;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
|
||||||
const _CHAR *lpath;
|
const _CHAR *lpath;
|
||||||
|
|
||||||
lpath = [self fileSystemRepresentationWithPath: path];
|
lpath = [self fileSystemRepresentationWithPath: path];
|
||||||
|
#if defined(_WIN32)
|
||||||
isDir = (CreateDirectoryW(lpath, 0) != FALSE) ? YES : NO;
|
isDir = (CreateDirectoryW(lpath, 0) != FALSE) ? YES : NO;
|
||||||
#else
|
#else
|
||||||
const char *lpath;
|
|
||||||
|
|
||||||
lpath = [self fileSystemRepresentationWithPath: path];
|
|
||||||
isDir = (mkdir(lpath, 0777) == 0) ? YES : NO;
|
isDir = (mkdir(lpath, 0777) == 0) ? YES : NO;
|
||||||
if (YES == isDir)
|
if (YES == isDir)
|
||||||
{
|
{
|
||||||
|
@ -1145,12 +1118,12 @@ static NSStringEncoding defaultEncoding;
|
||||||
attributes: (NSDictionary*)attributes
|
attributes: (NSDictionary*)attributes
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
const _CHAR *lpath = [self fileSystemRepresentationWithPath: path];
|
const _CHAR *lpath = [self fileSystemRepresentationWithPath: path];
|
||||||
HANDLE fh;
|
HANDLE fh;
|
||||||
DWORD written = 0;
|
DWORD written = 0;
|
||||||
DWORD len = [contents length];
|
DWORD len = [contents length];
|
||||||
#else
|
#else
|
||||||
const char *lpath;
|
const _CHAR *lpath;
|
||||||
int fd;
|
int fd;
|
||||||
int len;
|
int len;
|
||||||
int written;
|
int written;
|
||||||
|
@ -1262,7 +1235,7 @@ static NSStringEncoding defaultEncoding;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
char path[PATH_MAX];
|
_CHAR path[PATH_MAX];
|
||||||
#ifdef HAVE_GETCWD
|
#ifdef HAVE_GETCWD
|
||||||
if (getcwd(path, PATH_MAX-1) == 0)
|
if (getcwd(path, PATH_MAX-1) == 0)
|
||||||
return nil;
|
return nil;
|
||||||
|
@ -2309,7 +2282,7 @@ static NSStringEncoding defaultEncoding;
|
||||||
#endif
|
#endif
|
||||||
unsigned long long totalsize, freesize;
|
unsigned long long totalsize, freesize;
|
||||||
unsigned long blocksize;
|
unsigned long blocksize;
|
||||||
const char* lpath = [self fileSystemRepresentationWithPath: path];
|
const _CHAR* lpath = [self fileSystemRepresentationWithPath: path];
|
||||||
|
|
||||||
id values[5];
|
id values[5];
|
||||||
id keys[5] = {
|
id keys[5] = {
|
||||||
|
@ -2516,8 +2489,8 @@ static NSStringEncoding defaultEncoding;
|
||||||
pathContent: (NSString*)otherPath
|
pathContent: (NSString*)otherPath
|
||||||
{
|
{
|
||||||
#ifdef HAVE_SYMLINK
|
#ifdef HAVE_SYMLINK
|
||||||
const char* newpath = [self fileSystemRepresentationWithPath: path];
|
const _CHAR* newpath = [self fileSystemRepresentationWithPath: path];
|
||||||
const char* oldpath = [self fileSystemRepresentationWithPath: otherPath];
|
const _CHAR* oldpath = [self fileSystemRepresentationWithPath: otherPath];
|
||||||
|
|
||||||
return (symlink(oldpath, newpath) == 0);
|
return (symlink(oldpath, newpath) == 0);
|
||||||
#else
|
#else
|
||||||
|
@ -2534,7 +2507,7 @@ static NSStringEncoding defaultEncoding;
|
||||||
{
|
{
|
||||||
#ifdef HAVE_READLINK
|
#ifdef HAVE_READLINK
|
||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
const char* lpath = [self fileSystemRepresentationWithPath: path];
|
const _CHAR* lpath = [self fileSystemRepresentationWithPath: path];
|
||||||
int llen = readlink(lpath, buf, PATH_MAX-1);
|
int llen = readlink(lpath, buf, PATH_MAX-1);
|
||||||
|
|
||||||
if (llen > 0)
|
if (llen > 0)
|
||||||
|
@ -2808,11 +2781,7 @@ static inline void gsedRelease(GSEnumeratedDirectory X)
|
||||||
{
|
{
|
||||||
GSEnumeratedDirectory dir = GSIArrayLastItem(_stack).ext;
|
GSEnumeratedDirectory dir = GSIArrayLastItem(_stack).ext;
|
||||||
struct _STATB statbuf;
|
struct _STATB statbuf;
|
||||||
#if defined(_WIN32)
|
const _CHAR *dirname = NULL;
|
||||||
const wchar_t *dirname = NULL;
|
|
||||||
#else
|
|
||||||
const char *dirname = NULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
if (dir.assetDir)
|
if (dir.assetDir)
|
||||||
|
@ -4071,10 +4040,10 @@ static NSSet *fileKeys = nil;
|
||||||
case S_IFREG: return NSFileTypeRegular;
|
case S_IFREG: return NSFileTypeRegular;
|
||||||
case S_IFDIR: return NSFileTypeDirectory;
|
case S_IFDIR: return NSFileTypeDirectory;
|
||||||
case S_IFCHR: return NSFileTypeCharacterSpecial;
|
case S_IFCHR: return NSFileTypeCharacterSpecial;
|
||||||
#ifdef S_IFBLK
|
#if defined(S_IFBLK) && !defined(_WIN32)
|
||||||
case S_IFBLK: return NSFileTypeBlockSpecial;
|
case S_IFBLK: return NSFileTypeBlockSpecial;
|
||||||
#endif
|
#endif
|
||||||
#ifdef S_IFLNK
|
#if defined(S_IFLNK) && !defined(_WIN32)
|
||||||
case S_IFLNK: return NSFileTypeSymbolicLink;
|
case S_IFLNK: return NSFileTypeSymbolicLink;
|
||||||
#endif
|
#endif
|
||||||
#ifdef S_IFIFO
|
#ifdef S_IFIFO
|
||||||
|
|
|
@ -1194,7 +1194,8 @@ static void determineOperatingSystem()
|
||||||
_operatingSystemName = @"GSGNULinuxOperatingSystem";
|
_operatingSystemName = @"GSGNULinuxOperatingSystem";
|
||||||
_operatingSystem = GSGNULinuxOperatingSystem;
|
_operatingSystem = GSGNULinuxOperatingSystem;
|
||||||
}
|
}
|
||||||
else if ([os hasPrefix: @"mingw"] == YES)
|
else if ([os hasPrefix: @"mingw"] == YES
|
||||||
|
|| [os isEqualToString: @"windows"] == YES)
|
||||||
{
|
{
|
||||||
_operatingSystemName = @"NSWindowsNTOperatingSystem";
|
_operatingSystemName = @"NSWindowsNTOperatingSystem";
|
||||||
_operatingSystem = NSWindowsNTOperatingSystem;
|
_operatingSystem = NSWindowsNTOperatingSystem;
|
||||||
|
|
1027
Source/win32/dirent.h
Normal file
1027
Source/win32/dirent.h
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue