From d67052321ec17d82bd7da35ae3fd87eecd7b376f Mon Sep 17 00:00:00 2001 From: Yaakov Selkowitz Date: Wed, 25 Mar 2015 18:19:38 -0500 Subject: string: add GNU basename(3) * libc/include/libgen.h (_BASENAME_DEFINED): Define. * libc/include/string.h (basename): Declare. * libc/string/Makefile.am (ELIX_4_SOURCES): Add gnu_basename.c. * libc/string/Makefile.in: Regenerate. * libc/string/gnu_basename.c: New file. --- newlib/libc/string/gnu_basename.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 newlib/libc/string/gnu_basename.c (limited to 'newlib/libc/string/gnu_basename.c') diff --git a/newlib/libc/string/gnu_basename.c b/newlib/libc/string/gnu_basename.c new file mode 100644 index 000000000..46b92d0fd --- /dev/null +++ b/newlib/libc/string/gnu_basename.c @@ -0,0 +1,26 @@ +#ifndef _NO_BASENAME +/* Copyright 2015 Red Hat, Inc. + * Permission to use, copy, modify, and distribute this software + * is freely granted, provided that this notice is preserved. + */ + +/* The differences with the POSIX version (unix/basename.c): + * - declared in (instead of ); + * - the argument is never modified, and therefore is marked const; + * - the empty string is returned if path is an empty string, "/", or ends + * with a trailing slash. + */ + +#include + +char * +_DEFUN (__gnu_basename, (path), + const char *path) +{ + char *p; + if ((p = strrchr (path, '/'))) + return p + 1; + return path; +} + +#endif /* !_NO_BASENAME */ -- cgit v1.2.3