along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
-#ifdef HAVE_CONFIG_H
+#if HAVE_CONFIG_H
# include <config.h>
#endif
# endif
#endif
-#include <ctype.h>
-
-#if defined STDC_HEADERS || (!defined isascii && !defined HAVE_ISASCII)
-# define IN_CTYPE_DOMAIN(c) 1
-#else
-# define IN_CTYPE_DOMAIN(c) isascii(c)
-#endif
-#define ISALPHA(Ch) (IN_CTYPE_DOMAIN (Ch) && isalpha (Ch))
+#include "dirname.h"
/* Return the leading directories part of PATH,
allocated with malloc. If out of memory, return 0.
removed. */
char *
-dirname (path)
- char *path;
+dir_name (const char *path)
{
char *newpath;
char *slash;
}
else
{
- char *lim = path;
-
+ /* Remove any trailing slashes from the result. */
#ifdef MSDOS
- /* If canonicalized "d:/path", leave alone the root case "d:/". */
- lim = (ISALPHA (path[0]) && path[1] == ':') ? path + 2 : path;
-#endif
+ char *lim = (path[0] >= 'A' && path[0] <= 'z' && path[1] == ':')
+ ? path + 2 : path;
- /* Remove any trailing slashes from the result. */
+ /* If canonicalized "d:/path", leave alone the root case "d:/". */
+ while (slash > lim && *slash == '/')
+ --slash;
+#else
while (slash > path && *slash == '/')
--slash;
+#endif
length = slash - path + 1;
}