From 05efaee7172171e9015b368d5adc037000577426 Mon Sep 17 00:00:00 2001 From: jjohnstn Date: Fri, 8 Apr 2005 20:48:38 +0000 Subject: [PATCH] 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/ChangeLog | 11 +++++++++++ newlib/libc/include/libgen.h | 23 +++++++++++++++++++++++ newlib/libc/unix/Makefile.am | 2 ++ newlib/libc/unix/Makefile.in | 2 +- newlib/libc/unix/basename.c | 25 +++++++++++++++++++++++++ newlib/libc/unix/dirname.c | 28 ++++++++++++++++++++++++++++ 6 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 newlib/libc/include/libgen.h create mode 100644 newlib/libc/unix/basename.c create mode 100644 newlib/libc/unix/dirname.c diff --git a/newlib/ChangeLog b/newlib/ChangeLog index c28f3bf180..f6b9d7fdc3 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,14 @@ +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. + 2005-04-07 Shaun Jackman * libc/sys/linux/inode.c (lchown): New function. diff --git a/newlib/libc/include/libgen.h b/newlib/libc/include/libgen.h new file mode 100644 index 0000000000..abfab0e5c7 --- /dev/null +++ b/newlib/libc/include/libgen.h @@ -0,0 +1,23 @@ +/* + * libgen.h - defined by XPG4 + */ + +#ifndef _LIBGEN_H_ +#define _LIBGEN_H_ + +#include "_ansi.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + +char *_EXFUN(basename, (char *)); +char *_EXFUN(dirname, (char *)); + +#ifdef __cplusplus +} +#endif + +#endif /* _LIBGEN_H_ */ + diff --git a/newlib/libc/unix/Makefile.am b/newlib/libc/unix/Makefile.am index a5d57cf875..6ecee1397a 100644 --- a/newlib/libc/unix/Makefile.am +++ b/newlib/libc/unix/Makefile.am @@ -15,6 +15,8 @@ ELIX_2_OBJS = \ ttyname.$(oext) ELIX_4_OBJS = \ + basename.$(oext) \ + dirname.$(oext) \ getlogin.$(oext) \ getpass.$(oext) \ getpwent.$(oext) \ diff --git a/newlib/libc/unix/Makefile.in b/newlib/libc/unix/Makefile.in index a3bb1b02ed..7d049ce142 100644 --- a/newlib/libc/unix/Makefile.in +++ b/newlib/libc/unix/Makefile.in @@ -116,7 +116,7 @@ GENERAL_SOURCES = getcwd.c pread.c pwrite.c sigset.c ELIX_2_OBJS = ttyname.$(oext) -ELIX_4_OBJS = getlogin.$(oext) getpass.$(oext) getpwent.$(oext) getut.$(oext) +ELIX_4_OBJS = basename.$(oext) dirname.$(oext) getlogin.$(oext) getpass.$(oext) getpwent.$(oext) getut.$(oext) @ELIX_LEVEL_1_TRUE@LIB_OBJS = @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_TRUE@LIB_OBJS = $(ELIX_2_OBJS) diff --git a/newlib/libc/unix/basename.c b/newlib/libc/unix/basename.c new file mode 100644 index 0000000000..703e532d5b --- /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 +#include + +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; +} diff --git a/newlib/libc/unix/dirname.c b/newlib/libc/unix/dirname.c new file mode 100644 index 0000000000..f026e3056b --- /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); +} -- 2.11.0