Skip to content

Commit

Permalink
fix: support for relative file paths in windows
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Nov 29, 2022
1 parent fe09683 commit 67cf2ac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

*
* Support for relative file paths in Windows

## [0.4.6] - 2022-11-29

Expand Down
16 changes: 14 additions & 2 deletions src/pconvert/pconvert.c
Expand Up @@ -84,8 +84,14 @@ ERROR_T read_png(char *file_name, char demultiply, struct pcv_image *image) {
/* opens the file and tests for proper opening, this is required
to avoid possible problems while handling improper file reading */
#ifdef _MSC_VER
char is_absolute = strncmp(file_name, "./", 2) != 0 &&\
strstr(file_name, ":\\");
wchar_t file_name_w[1024];
swprintf(file_name_w, 1024, L"\\\\?\\%hs", file_name);
if(is_absolute) {
swprintf(file_name_w, 1024, L"\\\\?\\%hs", file_name);
} else {
swprintf(file_name_w, 1024, L"%hs", file_name);
}
fp = _wfopen(file_name_w, L"rb");
#else
fp = fopen(file_name, "rb");
Expand Down Expand Up @@ -182,8 +188,14 @@ ERROR_T write_png_extra(
writting of the final file and the verifies it the open operation
has been completed with the proper success */
#ifdef _MSC_VER
char is_absolute = strncmp(file_name, "./", 2) != 0 &&\
strstr(file_name, ":\\");
wchar_t file_name_w[1024];
swprintf(file_name_w, 1024, L"\\\\?\\%hs", file_name);
if(is_absolute) {
swprintf(file_name_w, 1024, L"\\\\?\\%hs", file_name);
} else {
swprintf(file_name_w, 1024, L"%hs", file_name);
}
fp = _wfopen(file_name_w, L"wb");
#else
fp = fopen(file_name, "wb");
Expand Down

0 comments on commit 67cf2ac

Please sign in to comment.