|
15 | 15 | #include "fossil/pizza/sanity.h" |
16 | 16 | #ifdef _WIN32 |
17 | 17 | #include <windows.h> |
18 | | -#include <process.h> |
19 | | -#include <io.h> |
20 | | -#define access _access |
21 | | -#define F_OK 0 |
22 | 18 | #else |
23 | 19 | #include <unistd.h> |
24 | 20 | #include <sys/types.h> |
25 | 21 | #include <sys/stat.h> |
| 22 | +#include <fcntl.h> |
26 | 23 | #endif |
27 | 24 |
|
28 | | -int fossil_sanity_sys_execute(const char* command) { |
29 | | - if (!command) return -1; |
30 | | - int status = system(command); |
| 25 | +int fossil_sys_call_execute(const char *command) { |
31 | 26 | #ifdef _WIN32 |
32 | | - return status; |
| 27 | + return system(command); // On Windows, use the system function to execute the command. |
33 | 28 | #else |
34 | | - if (WIFEXITED(status)) return WEXITSTATUS(status); |
35 | | - return -1; |
| 29 | + return system(command); // On Unix-like systems, use the system function to execute the command. |
36 | 30 | #endif |
37 | 31 | } |
38 | 32 |
|
39 | | -int fossil_sanity_sys_getpid(void) { |
| 33 | +int fossil_sys_call_getpid(void) { |
40 | 34 | #ifdef _WIN32 |
41 | | - return _getpid(); |
| 35 | + return GetCurrentProcessId(); // On Windows, use the GetCurrentProcessId function to get the process ID. |
42 | 36 | #else |
43 | | - return getpid(); |
| 37 | + return getpid(); // On Unix-like systems, use the getpid function to get the process ID. |
44 | 38 | #endif |
45 | 39 | } |
46 | 40 |
|
47 | | -void fossil_sanity_sys_sleep(int milliseconds) { |
| 41 | +void fossil_sys_call_sleep(int milliseconds) { |
48 | 42 | #ifdef _WIN32 |
49 | | - Sleep((DWORD)milliseconds); |
| 43 | + Sleep(milliseconds); // On Windows, use the Sleep function to sleep for the specified number of milliseconds. |
50 | 44 | #else |
51 | | - usleep(milliseconds * 1000); |
| 45 | + usleep(milliseconds * 1000); // On Unix-like systems, use the usleep function to sleep for the specified number of microseconds. |
52 | 46 | #endif |
53 | 47 | } |
54 | 48 |
|
55 | | -int fossil_sanity_sys_create_file(const char* filename) { |
56 | | - if (!filename) return -1; |
57 | | - FILE* fp = fopen(filename, "w"); |
58 | | - if (!fp) return -2; |
59 | | - fclose(fp); |
60 | | - return 0; |
61 | | -} |
62 | | - |
63 | | -int fossil_sanity_sys_file_exists(const char* filename) { |
64 | | - if (!filename) return 0; |
65 | | - return access(filename, F_OK) == 0 ? 1 : 0; |
| 49 | +int fossil_sys_call_create_file(const char *filename) { |
| 50 | +#ifdef _WIN32 |
| 51 | + HANDLE hFile = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); |
| 52 | + if (hFile == INVALID_HANDLE_VALUE) return -1; // If the file handle is invalid, return an error code. |
| 53 | + CloseHandle(hFile); // Close the file handle. |
| 54 | + return 0; // Return success. |
| 55 | +#else |
| 56 | + int fd = open(filename, O_CREAT | O_WRONLY, 0644); // On Unix-like systems, use the open function to create the file. |
| 57 | + if (fd == -1) return -1; // If the file descriptor is invalid, return an error code. |
| 58 | + close(fd); // Close the file descriptor. |
| 59 | + return 0; // Return success. |
| 60 | +#endif |
66 | 61 | } |
0 commit comments