Skip to content

Commit

Permalink
Solaris requires a buffer for realpath
Browse files Browse the repository at this point in the history
  • Loading branch information
k0ekk0ek committed Jul 12, 2024
1 parent dd433e0 commit e517fcc
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/zone.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,14 @@ nonnull_all
static int32_t resolve_path(
const char *includer, const char *include, char **path)
{
char *resolved;
char buffer[PATH_MAX + 1];

if (*includer && *include != '/') {
assert(*includer == '/');
const char *separator = strrchr(includer, '/');
if (separator - include > INT_MAX)
return ZONE_OUT_OF_MEMORY;
char buffer[16];
int offset = (int)(separator - includer);
int length = snprintf(
buffer, sizeof(buffer), "%.*s/%s", offset, includer, include);
Expand All @@ -190,15 +192,21 @@ static int32_t resolve_path(
return ZONE_OUT_OF_MEMORY;
(void)snprintf(
absolute, (size_t)length + 1, "%.*s/%s", offset, includer, include);
*path = realpath(absolute, NULL);
resolved = realpath(absolute, buffer);
free(absolute);
} else {
*path = realpath(include, NULL);
resolved = realpath(include, buffer);
}

if (*path)
return 0;
return (errno == ENOMEM) ? ZONE_OUT_OF_MEMORY : ZONE_NOT_A_FILE;
if (!resolved)
return (errno == ENOMEM) ? ZONE_OUT_OF_MEMORY : ZONE_NOT_A_FILE;
assert(resolved == buffer);
size_t length = strlen(buffer);
if (!(resolved = malloc(length + 1)))
return ZONE_OUT_OF_MEMORY;
memcpy(resolved, buffer, length + 1);
*path = resolved;
return 0;
}
#endif

Expand Down Expand Up @@ -276,6 +284,7 @@ static int32_t open_file(

initialize_file(parser, file);

file->path = NULL;
if (!(file->name = malloc(length + 1)))
return ZONE_OUT_OF_MEMORY;
memcpy(file->name, include, length);
Expand Down

0 comments on commit e517fcc

Please sign in to comment.