From 6e75bff67d6a4b6b96523be31bf581c2feae43c9 Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Fri, 8 Apr 2005 20:48:40 +0000 Subject: 2005-04-08 Jeff Johnston * libc/include/libgen.h: New file. 2005-04-08 Shaun Jackman * libc/unix/Makefile.am: Add support for basename and dirname. * libc/unix/Makefile.in: Regenerated. * libc/unix/basename.c: New file. * libc/unix/dirname.c: New file. --- newlib/libc/unix/dirname.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 newlib/libc/unix/dirname.c (limited to 'newlib/libc/unix/dirname.c') diff --git a/newlib/libc/unix/dirname.c b/newlib/libc/unix/dirname.c new file mode 100644 index 000000000..f026e3056 --- /dev/null +++ b/newlib/libc/unix/dirname.c @@ -0,0 +1,28 @@ +/* Copyright 2005 Shaun Jackman + * Permission to use, copy, modify, and distribute this software + * is freely granted, provided that this notice is preserved. + */ + +#include +#include + +char * +_DEFUN (dirname, (path), + char *path) +{ + char *p; + if( path == NULL || *path == '\0' ) + return "."; + p = path + strlen(path) - 1; + while( *p == '/' ) { + if( p == path ) + return path; + *p-- = '\0'; + } + while( p >= path && *p != '/' ) + p--; + return + p < path ? "." : + p == path ? "/" : + (*p = '\0', path); +} -- cgit v1.2.3