Package: klibc Severity: minor The attached patch adds the "basename" function to klibc. A "basename" utility is also implemented.
-- System Information: Debian Release: testing/unstable APT prefers unstable APT policy: (500, 'unstable') Architecture: i386 (i686) Shell: /bin/sh linked to /bin/bash Kernel: Linux 2.6.16-mm1-michich Locale: LANG=cs_CZ.UTF-8, LC_CTYPE=cs_CZ.UTF-8 (charmap=UTF-8)
diff -Nurp klibc-1.2.4/include/libgen.h klibc-1.2.4.mich/include/libgen.h --- klibc-1.2.4/include/libgen.h 1970-01-01 01:00:00.000000000 +0100 +++ klibc-1.2.4.mich/include/libgen.h 2006-03-28 00:06:15.000000000 +0200 @@ -0,0 +1,13 @@ +/* + * libgen.h + */ + +#ifndef _LIBGEN_H +#define _LIBGEN_H + +#include <klibc/extern.h> + +__extern char *dirname(char *); + +#endif /* _LIBGEN_H */ + diff -Nurp klibc-1.2.4/klibc/basename.c klibc-1.2.4.mich/klibc/basename.c --- klibc-1.2.4/klibc/basename.c 1970-01-01 01:00:00.000000000 +0100 +++ klibc-1.2.4.mich/klibc/basename.c 2006-03-28 00:02:50.000000000 +0200 @@ -0,0 +1,28 @@ +/* + * basename.c + */ + +char *basename(char *p) +{ + char *last_component; + int was_slash; + + last_component = p; + was_slash = (*p++ == '/'); + + while (*p) { + if (*p == '/') { + *p = '\0'; + was_slash = 1; + } else { + if (was_slash) { + last_component = p; + was_slash = 0; + } + } + p++; + } + + return last_component; +} + diff -Nurp klibc-1.2.4/klibc/Kbuild klibc-1.2.4.mich/klibc/Kbuild --- klibc-1.2.4/klibc/Kbuild 2006-02-23 04:49:32.000000000 +0100 +++ klibc-1.2.4.mich/klibc/Kbuild 2006-03-28 00:04:23.000000000 +0200 @@ -30,6 +30,7 @@ libc-y := vsnprintf.o snprintf.o vsprint strncat.o strlcpy.o strlcat.o \ strstr.o strncmp.o strncpy.o strrchr.o \ strxspn.o strspn.o strcspn.o strpbrk.o strsep.o strtok.o \ + basename.o \ gethostname.o getdomainname.o getcwd.o \ seteuid.o setegid.o \ getenv.o setenv.o putenv.o __put_env.o unsetenv.o \ diff -Nurp klibc-1.2.4/utils/basename.c klibc-1.2.4.mich/utils/basename.c --- klibc-1.2.4/utils/basename.c 1970-01-01 01:00:00.000000000 +0100 +++ klibc-1.2.4.mich/utils/basename.c 2006-03-28 00:07:05.000000000 +0200 @@ -0,0 +1,18 @@ +/* basename.c - strip directory from filenames */ + +/* Written 2006 by Michal Schmidt */ + +#include <stdio.h> +#include <libgen.h> + +int main(int argc, char **argv) +{ + if (argc != 2) { + fprintf(stderr,"Usage: %s filename\n",argv[0]); + return 1; + } + + printf("%s\n", basename(argv[1])); + return 0; +} + diff -Nurp klibc-1.2.4/utils/Kbuild klibc-1.2.4.mich/utils/Kbuild --- klibc-1.2.4/utils/Kbuild 2006-03-28 00:37:46.000000000 +0200 +++ klibc-1.2.4.mich/utils/Kbuild 2006-03-28 00:10:56.000000000 +0200 @@ -4,7 +4,7 @@ progs := chroot dd mkdir mkfifo mount pivot_root umount progs += true false sleep ln nuke minips cat -progs += insmod uname +progs += insmod uname basename static-y := $(addprefix static/, $(progs)) shared-y := $(addprefix shared/, $(progs)) @@ -42,6 +42,8 @@ static/insmod-y := insmod.o shared/insmod-y := insmod.o static/uname-y := uname.o shared/uname-y := uname.o +static/basename-y := basename.o +shared/basename-y := basename.o # Clean deletes the static and shared dir clean-dirs := static shared