Skip to content

Commit

Permalink
Fix working_dir containing back-slashes and ending slash on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
thevindu-w committed Dec 15, 2024
1 parent 3d5c4ce commit eeae920
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
10 changes: 10 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ static inline void _set_error_log_file(const char *path) {
* Change working directory to the directory specified in the configuration
*/
static inline void _change_working_dir(void) {
if (!configuration.working_dir) error_exit("Invalid working directory");
char *ptr;
for (ptr = configuration.working_dir; *ptr; ptr++) {
if (*ptr == PATH_SEP) *ptr = '/';
}
ptr--;
while (*ptr == '/' && ptr > configuration.working_dir) { // do not remove / from root
*ptr = 0;
ptr--;
}
if (!is_directory(configuration.working_dir, 1)) {
char err[3072];
snprintf_check(err, 3072, "Error: Not existing working directory \'%s\'", configuration.working_dir);
Expand Down
11 changes: 2 additions & 9 deletions utils/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,11 @@ int is_directory(const char *path, int follow_symlinks) {
#elif defined(_WIN32)
(void)follow_symlinks;
wchar_t *wpath;
if (utf8_to_wchar_str(path, &wpath, NULL) != EXIT_SUCCESS) return -1;
if (utf8_to_wchar_str(path, &wpath, NULL) != EXIT_SUCCESS) return 0;
stat_result = _wstat64(wpath, &sb);
free(wpath);
#endif
if (stat_result == 0) {
if (S_ISDIR(sb.st_mode)) {
return 1;
} else {
return 0;
}
}
return 0;
return (stat_result == 0) && S_ISDIR(sb.st_mode);
}

void png_mem_write_data(png_structp png_ptr, png_bytep data, png_size_t length) {
Expand Down

0 comments on commit eeae920

Please sign in to comment.