diff options
Diffstat (limited to 'lib/buffer.c')
-rw-r--r-- | lib/buffer.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/lib/buffer.c b/lib/buffer.c new file mode 100644 index 0000000..2bee94b --- /dev/null +++ b/lib/buffer.c @@ -0,0 +1,60 @@ +#include "buffer.h" +#include "convert.h" + +#include <limits.h> +#include <string.h> + +static int push_path_buffer_b(char* buf, int* index, const char* string) { + int save, string_len; + + save = *index; + if (*index > 1 || (*index == 1 && buf[0] != '/')) { + buf[(*index)++] = '/'; + } + + string_len = strlen(string); + memcpy(buf + *index, string, string_len + 1); + + *index += string_len; + + return save; +} + +static void pop_path_buffer_b(char* buf, int* index, int i) { + *index = i; + buf[*index] = '\0'; +} + +static char path_buffer[PATH_MAX + 1]; +static int path_buffer_index = 0; + +char* get_path_buffer(void) { + return path_buffer; +} + +int push_path_buffer(const char* string) { + return push_path_buffer_b(path_buffer, &path_buffer_index, string); +} + +void pop_path_buffer(int i) { + pop_path_buffer_b(path_buffer, &path_buffer_index, i); +} + +static char path_buffer_2[PATH_MAX + 1]; +static int path_buffer_index_2 = 0; + +char* get_path_buffer_2(void) { + return path_buffer_2; +} + +int push_path_buffer_2(const char* string) { + return push_path_buffer_b(path_buffer_2, &path_buffer_index_2, string); +} + +void pop_path_buffer_2(int i) { + pop_path_buffer_b(path_buffer_2, &path_buffer_index_2, i); +} + +bool is_dot_dir(const char* path) { + return streql(path, ".") || streql(path, ".."); +} |