Skip to content

Commit

Permalink
Improve the implementation of hs_mkdir() on windows to correctly ha…
Browse files Browse the repository at this point in the history
…ndle UTF-8 paths.
  • Loading branch information
Arignir committed Jul 1, 2024
1 parent edc44f6 commit c7c2b92
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions include/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <shellapi.h>

#define hs_isatty(x) false
#define hs_mkdir(path) CreateDirectoryA((path), NULL)

static inline
wchar_t *
Expand Down Expand Up @@ -76,14 +75,22 @@ hs_fopen(
}

static inline
char const *
hs_basename(
bool
hs_mkdir(
char const *path
) {
char const *base;
wchar_t *wpath;
bool out;

base = strrchr(path, '\\');
return (base ? base + 1 : path);
wpath = hs_convert_to_wchar(path);
if (!wpath) {
return (false);
}

out = CreateDirectoryW(wpath, NULL);

free(wpath);
return out;
}

static inline
Expand All @@ -105,6 +112,17 @@ hs_fexists(
return (out);
}

static inline
char const *
hs_basename(
char const *path
) {
char const *base;

base = strrchr(path, '\\');
return (base ? base + 1 : path);
}

static inline
char *
hs_fmtime(
Expand Down Expand Up @@ -221,7 +239,7 @@ hs_fmtime(
return (NULL);
}

out = malloc(sizeof(char) * 128);
out = (char *)malloc(sizeof(char) * 128);
hs_assert(out);

tm = localtime(&stbuf.st_mtime);
Expand Down

0 comments on commit c7c2b92

Please sign in to comment.