system_file.c 578 B

1234567891011121314151617181920212223242526272829
  1. /*
  2. * system_file.c
  3. */
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include "private.h"
  7. #include "lub/string.h"
  8. /*-------------------------------------------------------- */
  9. /* perform a simple tilde substitution for the home directory
  10. * defined in HOME
  11. */
  12. char *lub_system_tilde_expand(const char *path)
  13. {
  14. char *home_dir = getenv("HOME");
  15. char *result = NULL;
  16. char *tilde;
  17. while ((tilde = strchr(path, '~'))) {
  18. lub_string_catn(&result, path, tilde - path);
  19. lub_string_cat(&result, home_dir);
  20. path = tilde + 1;
  21. }
  22. lub_string_cat(&result, path);
  23. return result;
  24. }