diff options
author | Jeff Johnston <jjohnstn@redhat.com> | 2005-04-08 20:48:40 +0000 |
---|---|---|
committer | Jeff Johnston <jjohnstn@redhat.com> | 2005-04-08 20:48:40 +0000 |
commit | 6e75bff67d6a4b6b96523be31bf581c2feae43c9 (patch) | |
tree | df95f5011ba2266371f8447aa54bfcd68d996522 /newlib/libc/unix/basename.c | |
parent | c400419414d491bb1e907da89be634c5f4ce3749 (diff) | |
download | cygnal-6e75bff67d6a4b6b96523be31bf581c2feae43c9.tar.gz cygnal-6e75bff67d6a4b6b96523be31bf581c2feae43c9.tar.bz2 cygnal-6e75bff67d6a4b6b96523be31bf581c2feae43c9.zip |
2005-04-08 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/libgen.h: New file.
2005-04-08 Shaun Jackman <sjackman@gmail.com>
* 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.
Diffstat (limited to 'newlib/libc/unix/basename.c')
-rw-r--r-- | newlib/libc/unix/basename.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/newlib/libc/unix/basename.c b/newlib/libc/unix/basename.c new file mode 100644 index 000000000..703e532d5 --- /dev/null +++ b/newlib/libc/unix/basename.c @@ -0,0 +1,25 @@ +/* Copyright 2005 Shaun Jackman + * Permission to use, copy, modify, and distribute this software + * is freely granted, provided that this notice is preserved. + */ + +#include <libgen.h> +#include <string.h> + +char* +_DEFUN (basename, (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 + 1; +} |