Skip to content

Commit 54158da

Browse files
resolve issues with sanity kit
1 parent 3fbd0eb commit 54158da

File tree

1 file changed

+22
-27
lines changed

1 file changed

+22
-27
lines changed

code/logic/sanity.c

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,52 +15,47 @@
1515
#include "fossil/pizza/sanity.h"
1616
#ifdef _WIN32
1717
#include <windows.h>
18-
#include <process.h>
19-
#include <io.h>
20-
#define access _access
21-
#define F_OK 0
2218
#else
2319
#include <unistd.h>
2420
#include <sys/types.h>
2521
#include <sys/stat.h>
22+
#include <fcntl.h>
2623
#endif
2724

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) {
3126
#ifdef _WIN32
32-
return status;
27+
return system(command); // On Windows, use the system function to execute the command.
3328
#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.
3630
#endif
3731
}
3832

39-
int fossil_sanity_sys_getpid(void) {
33+
int fossil_sys_call_getpid(void) {
4034
#ifdef _WIN32
41-
return _getpid();
35+
return GetCurrentProcessId(); // On Windows, use the GetCurrentProcessId function to get the process ID.
4236
#else
43-
return getpid();
37+
return getpid(); // On Unix-like systems, use the getpid function to get the process ID.
4438
#endif
4539
}
4640

47-
void fossil_sanity_sys_sleep(int milliseconds) {
41+
void fossil_sys_call_sleep(int milliseconds) {
4842
#ifdef _WIN32
49-
Sleep((DWORD)milliseconds);
43+
Sleep(milliseconds); // On Windows, use the Sleep function to sleep for the specified number of milliseconds.
5044
#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.
5246
#endif
5347
}
5448

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
6661
}

0 commit comments

Comments
 (0)