-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
winapi: Implement all
direct.h
functions apart from path manipulation
`fnmerge` and `fnsplit` haven't been implemented since I noticed inconsistencies in the documentation relating to them, for now I simply have empty function definitions in the form described by https://www.digitalmars.com/rtl/direct.html (ie no `_` prefix) The status of other functions is as follows: `_chdir`, `_chdrive`: impossible to implement, succeeds without an error code, or change of state in the Xbox `_getcwd`, `_getwd`: impossible to implement, return NULL pointers and sets `errno` to `-EINVAL` `_getdrive`: as before, impossible to implement - returns `0` and sets `errno` to `-EINVAL` (this is the error state described by a combo of MS public documentation and digital mars docs) `_searchpath`: impossible to implement since there is no PATH variable on the Xbox `_mkdir`, `_rmdir`: implemented, testing required, however
- Loading branch information
skye
committed
Jun 10, 2023
1 parent
500354e
commit 680b892
Showing
2 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
// SPDX-FileCopyrightText: 2023 ExoSkye | ||
|
||
// Part of Microsoft CRT | ||
|
||
#include <errno.h> | ||
#include <string.h> | ||
#include <stdbool.h> | ||
#include <windows.h> | ||
|
||
// Made referencing https://www.digitalmars.com/rtl/direct.html, retrieved 2023-06-10, copyrighted 1999-2018 by Digital Mars | ||
|
||
#define MAXPATH 80 | ||
#define MAXDRIVE 3 | ||
#define MAXDIR 66 | ||
#define MAXFILE 9 | ||
#define MAXEXT 5 | ||
|
||
/* | ||
* These silently succeed, since they wouldn't have any effect on the program at all | ||
*/ | ||
|
||
int _chdir(char* path) { | ||
return 0; | ||
} | ||
|
||
int _chdrive(int drive) { | ||
return 0; | ||
} | ||
|
||
/* | ||
* The Xbox has no concept of current working directory, so these can't work | ||
*/ | ||
|
||
char* _getcwd(char* buffer, size_t length) { | ||
errno = -EINVAL; | ||
return NULL; | ||
} | ||
|
||
char* _getwd(char* path_name) { | ||
errno = -EINVAL; | ||
return NULL; | ||
} | ||
|
||
int _getdrive(void) { | ||
errno = -EINVAL; | ||
return 0; | ||
} | ||
|
||
/* | ||
* There's no path variable on the Xbox, so this can't work | ||
*/ | ||
|
||
char* _searchpath(const char* file) { | ||
errno = -EINVAL; | ||
return NULL; | ||
} | ||
|
||
/* | ||
* Below are the only things that can work | ||
*/ | ||
|
||
int _mkdir(const char* pathname) { | ||
BOOL result = CreateDirectoryA( | ||
pathname, | ||
NULL | ||
); | ||
|
||
if (result == true) { | ||
return 0; | ||
} else { | ||
DWORD err = GetLastError(); | ||
|
||
if (err == ERROR_ALREADY_EXISTS) { | ||
errno = EACCES; | ||
} else if (err == ERROR_PATH_NOT_FOUND) { | ||
errno = ENOENT; | ||
} | ||
|
||
return -1; | ||
} | ||
} | ||
|
||
int _rmdir(const char* pathname) { | ||
BOOL result = RemoveDirectoryA( | ||
pathname | ||
); | ||
|
||
if (result == true) { | ||
return 0; | ||
} else { | ||
DWORD err = GetLastError(); | ||
|
||
if (err == ERROR_ALREADY_EXISTS) { | ||
errno = EACCES; | ||
} else if (err == ERROR_PATH_NOT_FOUND) { | ||
errno = ENOENT; | ||
} | ||
|
||
return -1; | ||
} | ||
} | ||
|
||
void fnmerge(char* path, const char* drive, const char* dir, const char* name, const char* ext) { | ||
|
||
} | ||
|
||
void fnsplit(const char* path, char* drive, char* dir, char* name, char* ext) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters