diff options
Diffstat (limited to 'src/util/shared.c')
-rw-r--r-- | src/util/shared.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/util/shared.c b/src/util/shared.c index 3e6fca3..600a967 100644 --- a/src/util/shared.c +++ b/src/util/shared.c @@ -1,6 +1,7 @@ #include "shared.h" #include <errno.h> +#include <limits.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> @@ -232,3 +233,25 @@ FILE* get_tty_stream(char* type) { return file; } +static char path_buffer[PATH_MAX + 1]; +static int path_buffer_index = 0; + +char* get_path_buffer() { + return path_buffer; +} + +int push_path_buffer(const char* string) { + int save = path_buffer_index; + if (path_buffer_index > 1 || (path_buffer_index == 1 && path_buffer[0] != '/')) { + path_buffer[path_buffer_index++] = '/'; + } + int string_len = strlen(string); + memcpy(path_buffer + path_buffer_index, string, string_len + 1); + path_buffer_index += string_len; + return save; +} + +void pop_path_buffer(int i) { + path_buffer_index = i; + path_buffer[path_buffer_index] = '\0'; +} |