path.c (705B)
- // utils-std: Collection of commonly available Unix tools
- // SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- // SPDX-License-Identifier: MPL-2.0
- #include "./path.h"
- #include <string.h> // strrchr
- char *
- static_basename(char *path)
- {
- char *sep = strrchr(path, '/');
- return (sep == NULL) ? path : sep + 1;
- }
- char *
- path_split_static(char *path, bool trim)
- {
- char *child = NULL;
- size_t path_len = strlen(path);
- // delete trailing slashes
- if(trim)
- for(int i = path_len - 1; i > 0 && path[i] == '/'; i--)
- path[i] = 0;
- for(int i = path_len - 1; i > 0; i--)
- if(path[i] == '/')
- {
- path[i] = 0;
- child = &path[i + 1];
- break;
- }
- return child;
- }