diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-07-26 13:30:24 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-07-26 13:30:24 -0400 |
| commit | b2e752ee3257e967fa4796b39054a7f32629291d (patch) | |
| tree | e87ef2581de45301571b0c9d79bad78aaa4677ae /builtins | |
| parent | cfe46ee393aa3c9a2344a916bccfc4a69d4b8b77 (diff) | |
Replace heap_str with GC_strdup
Diffstat (limited to 'builtins')
| -rw-r--r-- | builtins/files.c | 22 | ||||
| -rw-r--r-- | builtins/util.c | 6 | ||||
| -rw-r--r-- | builtins/util.h | 1 |
3 files changed, 11 insertions, 18 deletions
diff --git a/builtins/files.c b/builtins/files.c index 6c833469..70c76484 100644 --- a/builtins/files.c +++ b/builtins/files.c @@ -28,36 +28,36 @@ public char *resolve_path(const char *path, const char *relative_to, const char char buf[PATH_MAX] = {0}; if (streq(path, "~") || strncmp(path, "~/", 2) == 0) { char *resolved = realpath(heap_strf("%s%s", getenv("HOME"), path+1), buf); - if (resolved) return heap_str(resolved); + if (resolved) return GC_strdup(resolved); } else if (streq(path, ".") || strncmp(path, "./", 2) == 0) { - char *relative_dir = dirname(heap_str(relative_to)); + char *relative_dir = dirname(GC_strdup(relative_to)); char *resolved = realpath(heap_strf("%s/%s", relative_dir, path), buf); - if (resolved) return heap_str(resolved); + if (resolved) return GC_strdup(resolved); } else if (path[0] == '/') { // Absolute path: char *resolved = realpath(path, buf); - if (resolved) return heap_str(resolved); + if (resolved) return GC_strdup(resolved); } else { // Relative path: - char *relative_dir = dirname(heap_str(relative_to)); + char *relative_dir = dirname(GC_strdup(relative_to)); if (!system_path) system_path = "."; - char *copy = heap_str(system_path); + char *copy = GC_strdup(system_path); for (char *dir, *pos = copy; (dir = strsep(&pos, ":")); ) { if (dir[0] == '/') { char *resolved = realpath(heap_strf("%s/%s", dir, path), buf); - if (resolved) return heap_str(resolved); + if (resolved) return GC_strdup(resolved); } else if (dir[0] == '~' && (dir[1] == '\0' || dir[1] == '/')) { char *resolved = realpath(heap_strf("%s%s/%s", getenv("HOME"), dir+1, path), buf); - if (resolved) return heap_str(resolved); + if (resolved) return GC_strdup(resolved); } else if (streq(dir, ".") || strncmp(dir, "./", 2) == 0) { char *resolved = realpath(heap_strf("%s/%s", relative_dir, path), buf); - if (resolved) return heap_str(resolved); + if (resolved) return GC_strdup(resolved); } else if (streq(dir, ".") || streq(dir, "..") || strncmp(dir, "./", 2) == 0 || strncmp(dir, "../", 3) == 0) { char *resolved = realpath(heap_strf("%s/%s/%s", relative_dir, dir, path), buf); - if (resolved) return heap_str(resolved); + if (resolved) return GC_strdup(resolved); } else { char *resolved = realpath(heap_strf("%s/%s", dir, path), buf); - if (resolved) return heap_str(resolved); + if (resolved) return GC_strdup(resolved); } } } diff --git a/builtins/util.c b/builtins/util.c index 598ab259..d4f3cd31 100644 --- a/builtins/util.c +++ b/builtins/util.c @@ -11,12 +11,6 @@ public bool USE_COLOR; -public char *heap_str(const char *str) -{ - if (!str) return NULL; - return GC_strndup(str, strlen(str)); -} - public char *heap_strf(const char *fmt, ...) { va_list args; diff --git a/builtins/util.h b/builtins/util.h index 08de9779..bc0a5828 100644 --- a/builtins/util.h +++ b/builtins/util.h @@ -25,7 +25,6 @@ extern bool USE_COLOR; -char *heap_str(const char *str); char *heap_strf(const char *fmt, ...); CORD CORD_asprintf(CORD fmt, ...); #define CORD_appendf(cord, fmt, ...) CORD_sprintf(cord, "%r" fmt, *(cord) __VA_OPT__(,) __VA_ARGS__) |
