concat_path_file.c 606 B

123456789101112131415161718192021222324252627
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Utility routines.
  4. *
  5. * Copyright (C) many different people.
  6. * If you wrote this, please acknowledge your work.
  7. *
  8. * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  9. */
  10. /* concatenate path and file name to new allocation buffer,
  11. * not adding '/' if path name already has '/'
  12. */
  13. #include "libbb.h"
  14. char *concat_path_file(const char *path, const char *filename)
  15. {
  16. char *lc;
  17. if (!path)
  18. path = "";
  19. lc = last_char_is(path, '/');
  20. while (*filename == '/')
  21. filename++;
  22. return xasprintf("%s%s%s", path, (lc==NULL ? "/" : ""), filename);
  23. }