Works properly even if there are trailing slashes
(by effectively ignoring them). */
size_t
-dir_name_r (const char *path, const char **result)
+dir_name_r (char const *path, char const **result)
{
- char *slash;
+ char const *slash;
size_t length; /* Length of result, not including NUL. */
slash = strrchr (path, '/');
if (BACKSLASH_IS_PATH_SEPARATOR)
{
- char *b = strrchr (path, '\\');
+ char const *b = strrchr (path, '\\');
if (b && slash < b)
slash = b;
}
slash = memrchr (path, '/', slash - path);
if (BACKSLASH_IS_PATH_SEPARATOR)
{
- char *b = memrchr (path, '\\', slash - path);
+ char const *b = memrchr (path, '\\', slash - path);
if (b && slash < b)
slash = b;
}
/* Remove any trailing slashes from the result. */
if (BACKSLASH_IS_PATH_SEPARATOR)
{
- const char *lim = ((path[0] >= 'A' && path[0] <= 'z'
+ char const *lim = ((path[0] >= 'A' && path[0] <= 'z'
&& path[1] == ':')
? path + 2 : path);
(by effectively ignoring them). */
char *
-dir_name (const char *path)
+dir_name (char const *path)
{
- const char *result;
+ char const *result;
size_t length = dir_name_r (path, &result);
char *newpath = (char *) malloc (length + 1);
if (newpath == 0)
{
char path[MAX_BUFF_LEN];
char expected_result[MAX_BUFF_LEN];
- char *result;
+ char const *result;
sscanf (buff, "%s %s", path, expected_result);
result = dir_name (path);
if (strcmp (result, expected_result))