diff options
| author | Albert Cervin <albert@acervin.com> | 2023-05-11 22:09:49 +0200 |
|---|---|---|
| committer | Albert Cervin <albert@acervin.com> | 2023-05-11 22:09:49 +0200 |
| commit | ea849862a85e1751206c20254e9126cf3e8096b5 (patch) | |
| tree | 249bbd4630a156983ea77bc4d43c186e03f6ed0e /src/dged/path.h | |
| parent | 67276833f9ede96dbc549c508f182c913240ac2c (diff) | |
| download | dged-ea849862a85e1751206c20254e9126cf3e8096b5.tar.gz dged-ea849862a85e1751206c20254e9126cf3e8096b5.tar.xz dged-ea849862a85e1751206c20254e9126cf3e8096b5.zip | |
Fix languages
- Enumerate windows on screen.
- Build with optimizations.
Diffstat (limited to 'src/dged/path.h')
| -rw-r--r-- | src/dged/path.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/dged/path.h b/src/dged/path.h new file mode 100644 index 0000000..d74f723 --- /dev/null +++ b/src/dged/path.h @@ -0,0 +1,38 @@ +#include <limits.h> +#include <stdlib.h> +#include <string.h> + +static char *expanduser(const char *path) { + // replace tilde + char *res = NULL; + char *tilde_pos = strchr(path, '~'); + if (tilde_pos != NULL) { + char *home = getenv("HOME"); + if (home != NULL) { + // allocate a new string based with the new len + size_t home_len = strlen(home); + size_t path_len = strlen(path); + size_t total_len = path_len + home_len; + res = malloc(total_len); + size_t initial_len = tilde_pos - path; + strncpy(res, path, initial_len); + + strncpy(res + initial_len, home, home_len); + + size_t rest_len = path_len - initial_len - 1; + strncpy(res + initial_len + home_len, path + initial_len + 1, rest_len); + res[total_len-1] = '\0'; + } + } + + return res != NULL ? res : strdup(path); +} + +static char *to_abspath(const char *path) { + char *p = realpath(path, NULL); + if (p != NULL) { + return p; + } else { + return strdup(path); + } +} |
