1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-04-21 03:12:48 +02:00

(dir_name): Assert that there are no trailing slashes.

This commit is contained in:
Jim Meyering
2000-07-29 08:10:46 +00:00
parent ba8620bf01
commit 3819c2d7cb

View File

@@ -32,6 +32,7 @@ char *malloc ();
# define strrchr rindex
# endif
#endif
#include <assert.h>
#ifndef ISSLASH
# define ISSLASH(C) ((C) == '/')
@@ -52,6 +53,13 @@ dir_name (const char *path)
int length; /* Length of result, not including NUL. */
slash = strrchr (path, '/');
/* Make sure there are no trailing slashes. */
assert (slash == NULL /* There are no slashes in PATH. */
|| slash[1] != 0 /* There is a non-NUL byte after the last slash. */
|| path == slash /* PATH is just `/'. */
);
if (slash == 0)
{
/* File is in the current directory. */