From: Philip Homburg Date: Thu, 25 Aug 2005 11:33:43 +0000 (+0000) Subject: Added basename(3) X-Git-Tag: v3.1.0~284 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/verify-sign/verify.pl?a=commitdiff_plain;h=a61e8f28c7946c96e605d622cd867cef866be47b;p=minix.git Added basename(3) --- diff --git a/include/libgen.h b/include/libgen.h new file mode 100644 index 000000000..5aa3705a0 --- /dev/null +++ b/include/libgen.h @@ -0,0 +1,9 @@ +/* +libgen.h +*/ + +#include + +/* Open Group Base Specifications Issue 6 (not complete) */ +_PROTOTYPE( char *basename, (char *_path) ); + diff --git a/lib/other/Makefile b/lib/other/Makefile index 1d3d81f13..c1dc8b544 100755 --- a/lib/other/Makefile +++ b/lib/other/Makefile @@ -21,6 +21,7 @@ OBJECTS = \ $(LIBRARY)(_devctl.o) \ $(LIBRARY)(_findproc.o) \ $(LIBRARY)(asynchio.o) \ + $(LIBRARY)(basename.o) \ $(LIBRARY)(configfile.o) \ $(LIBRARY)(crypt.o) \ $(LIBRARY)(ctermid.o) \ @@ -106,6 +107,9 @@ $(LIBRARY)(_getsysinfo.o): _getsysinfo.c $(LIBRARY)(asynchio.o): asynchio.c $(CC1) asynchio.c +$(LIBRARY)(basename.o): basename.c + $(CC1) basename.c + $(LIBRARY)(bcmp.o): bcmp.c $(CC1) bcmp.c diff --git a/lib/other/basename.c b/lib/other/basename.c new file mode 100644 index 000000000..5de8f7af5 --- /dev/null +++ b/lib/other/basename.c @@ -0,0 +1,30 @@ +/* +basename.c +*/ + +#include +#include + +char *basename(path) +char *path; +{ + size_t len; + char *cp; + + if (path == NULL) + return "."; + len= strlen(path); + if (len == 0) + return "."; + while (path[len-1] == '/') + { + if (len == 1) + return path; /* just "/" */ + len--; + path[len]= '\0'; + } + cp= strrchr(path, '/'); + if (cp != NULL) + return cp+1; + return path; +}