Skip to content

Commit 4b7f717

Browse files
committed
Solaris requires a buffer for realpath
1 parent 0dc4f7d commit 4b7f717

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/zone.c

+15-6
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,11 @@ nonnull_all
176176
static int32_t resolve_path(
177177
const char *includer, const char *include, char **path)
178178
{
179+
char *resolved;
180+
char buffer[PATH_MAX + 1];
181+
179182
if (*includer && *include != '/') {
180183
assert(*includer == '/');
181-
char buffer[16];
182184
int length = snprintf(
183185
buffer, sizeof(buffer), "%s/%s", includer, include);
184186
if (length < 0)
@@ -188,15 +190,21 @@ static int32_t resolve_path(
188190
return ZONE_OUT_OF_MEMORY;
189191
(void)snprintf(
190192
absolute, (size_t)length + 1, "%s/%s", includer, include);
191-
*path = realpath(absolute, NULL);
193+
resolved = realpath(absolute, buffer);
192194
free(absolute);
193195
} else {
194-
*path = realpath(include, NULL);
196+
resolved = realpath(include, buffer);
195197
}
196198

197-
if (*path)
198-
return 0;
199-
return (errno == ENOMEM) ? ZONE_OUT_OF_MEMORY : ZONE_NOT_A_FILE;
199+
if (!resolved)
200+
return (errno == ENOMEM) ? ZONE_OUT_OF_MEMORY : ZONE_NOT_A_FILE;
201+
assert(resolved == buffer);
202+
size_t length = strlen(buffer);
203+
if (!(resolved = malloc(length + 1)))
204+
return ZONE_OUT_OF_MEMORY;
205+
memcpy(resolved, buffer, length + 1);
206+
*path = resolved;
207+
return 0;
200208
}
201209
#endif
202210

@@ -280,6 +288,7 @@ static int32_t open_file(
280288

281289
initialize_file(parser, file);
282290

291+
file->path = NULL;
283292
if (!(file->name = malloc(length + 1)))
284293
return ZONE_OUT_OF_MEMORY;
285294
memcpy(file->name, include, length);

0 commit comments

Comments
 (0)