Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/coreutils/basename.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/coreutils/basename.c
r1765 r2725 5 5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> 6 6 * 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 8 * 7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 9 8 */ 10 11 /* BB_AUDIT SUSv3 compliant */12 /* http://www.opengroup.org/onlinepubs/007904975/utilities/basename.html */13 14 9 15 10 /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org) … … 21 16 */ 22 17 18 /* BB_AUDIT SUSv3 compliant */ 19 /* http://www.opengroup.org/onlinepubs/007904975/utilities/basename.html */ 20 21 //kbuild:lib-$(CONFIG_BASENAME) += basename.o 22 23 //config:config BASENAME 24 //config: bool "basename" 25 //config: default y 26 //config: help 27 //config: basename is used to strip the directory and suffix from filenames, 28 //config: leaving just the filename itself. Enable this option if you wish 29 //config: to enable the 'basename' utility. 30 23 31 #include "libbb.h" 24 32 25 33 /* This is a NOFORK applet. Be very careful! */ 26 34 27 int basename_main(int argc, char **argv) ;35 int basename_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 28 36 int basename_main(int argc, char **argv) 29 37 { … … 31 39 char *s; 32 40 33 if (( (unsigned int)(argc-2)) >= 2) {41 if ((unsigned)(argc-2) >= 2) { 34 42 bb_show_usage(); 35 43 } 36 44 37 s = bb_get_last_path_component(*++argv); 45 /* It should strip slash: /abc/def/ -> def */ 46 s = bb_get_last_path_component_strip(*++argv); 38 47 48 m = strlen(s); 39 49 if (*++argv) { 40 50 n = strlen(*argv); 41 m = strlen(s);42 if ((m > n) && ((strcmp)(s+m-n, *argv) == 0)) {43 s[m-n] = '\0';51 if ((m > n) && (strcmp(s+m-n, *argv) == 0)) { 52 m -= n; 53 /*s[m] = '\0'; - redundant */ 44 54 } 45 55 } 46 56 47 puts(s); 48 49 return fflush(stdout); 57 /* puts(s) will do, but we can do without stdio this way: */ 58 s[m++] = '\n'; 59 /* NB: != is correct here: */ 60 return full_write(STDOUT_FILENO, s, m) != (ssize_t)m; 50 61 }
Note:
See TracChangeset
for help on using the changeset viewer.