Skip to content

Commit

Permalink
improve error handling api (#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidaty authored Dec 18, 2024
1 parent d1678e4 commit 9e5d066
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/utils/dirs.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ struct dir_path {
static int rmdir_w_msg(const char *path, int *err) {
#ifdef WIN32
if (!RemoveDirectoryA(path)) {
zsv_win_printLastError();
zsv_perror(path);
// zsv_win_printLastError();
*err = 1;
}
#else
Expand Down
8 changes: 7 additions & 1 deletion app/utils/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <fcntl.h> // open

#include <zsv/utils/dirs.h>
#include <zsv/utils/os.h>
#include <zsv/utils/file.h>

/**
Expand All @@ -29,15 +30,20 @@ char *zsv_get_temp_filename(const char *prefix) {
TCHAR lpTempPathBuffer[MAX_PATH];
DWORD dwRetVal = GetTempPath(MAX_PATH, // length of the buffer
lpTempPathBuffer); // buffer for path
if (dwRetVal > 0 && dwRetVal < MAX_PATH) {
if (!(dwRetVal > 0 && dwRetVal < MAX_PATH))
zsv_perror("GetTempPath");
else {
char szTempFileName[MAX_PATH];
UINT uRetVal = GetTempFileName(lpTempPathBuffer, // directory for tmp files
TEXT(prefix), // temp file name prefix
0, // create unique name
szTempFileName); // buffer for name
if (uRetVal > 0)
return strdup(szTempFileName);
zsv_perror(lpTempPathBuffer);
fprintf(stderr, " prefix: %s\n", prefix);
}

return NULL;
}
#else
Expand Down
2 changes: 1 addition & 1 deletion app/utils/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int zsv_replace_file(const void *src, const void *dest) {
return 1; // fail
}

void zsv_win_printLastError(void) {
static void zsv_win_printLastError(void) {
DWORD dw = GetLastError();
LPVOID lpMsgBuf;
LPVOID lpDisplayBuf;
Expand Down
2 changes: 1 addition & 1 deletion include/zsv/utils/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ int zsv_replace_file(const void *src, const void *dest);

/**
* Windows does not have perror(), so we define our own printLastError()
void zsv_win_printLastError(const char *prefix);
*/
void zsv_win_printLastError();

#endif

Expand Down

0 comments on commit 9e5d066

Please sign in to comment.