Add ft_basename
Closed this issue · 0 comments
rask24 commented
Requirements
- The function prototype should be
char *ft_basename(char *path);
. - If path is "/path/to/file.ext", it should return "file.ext".
- If path is "/", it should return "/".
- If path is "///" or any sequence of repeated slashes, it should return "/".
- If path is an empty string, it should return ".".
- If path ends with a slash, the trailing slash should be ignored.
- The function should directly modify the path argument.
- Thorough testing should be performed, including edge cases.
POSIX vs. GNU Implementations
There are two main versions of basename: POSIX and GNU. The key differences are:
POSIX version:
Directly modifies the path argument.
Returns a pointer to the modified path.
GNU version:
Does not modify the path argument.
Returns a pointer to a static buffer containing the result.
The path argument is declared as const char *.
For this implementation, we will follow the POSIX standard.