aboutsummaryrefslogtreecommitdiff
path: root/coreutils/basename.c
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2003-03-19 09:13:01 +0000
committerManuel Novoa III <mjn3@codepoet.org>2003-03-19 09:13:01 +0000
commitcad5364599eb5062d59e0c397ed638ddd61a8d5d (patch)
treea318d0f03aa076c74b576ea45dc543a5669e8e91 /coreutils/basename.c
parente01f9662a5bd5d91be4f6b3941b57fff73cd5af1 (diff)
downloadbusybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.gz
busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.bz2
busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.zip
Major coreutils update.
Diffstat (limited to 'coreutils/basename.c')
-rw-r--r--coreutils/basename.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/coreutils/basename.c b/coreutils/basename.c
index bdbcec17a..71bb9b3bd 100644
--- a/coreutils/basename.c
+++ b/coreutils/basename.c
@@ -21,32 +21,43 @@
21 * 21 *
22 */ 22 */
23 23
24/* getopt not needed */ 24/* BB_AUDIT SUSv3 compliant */
25/* http://www.opengroup.org/onlinepubs/007904975/utilities/basename.html */
26
27
28/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
29 *
30 * Changes:
31 * 1) Now checks for too many args. Need at least one and at most two.
32 * 2) Don't check for options, as per SUSv3.
33 * 3) Save some space by using strcmp(). Calling strncmp() here was silly.
34 */
25 35
26#include <stdlib.h> 36#include <stdlib.h>
27#include "busybox.h" 37#include <stdio.h>
28#include <string.h> 38#include <string.h>
39#include "busybox.h"
29 40
30extern int basename_main(int argc, char **argv) 41extern int basename_main(int argc, char **argv)
31{ 42{
32 int m, n; 43 size_t m, n;
33 char *s; 44 char *s;
34 45
35 if ((argc < 2) || (**(argv + 1) == '-')) { 46 if (((unsigned int)(argc-2)) >= 2) {
36 show_usage(); 47 bb_show_usage();
37 } 48 }
38 49
39 argv++; 50 s = bb_get_last_path_component(*++argv);
40
41 s = get_last_path_component(*argv);
42 51
43 if (argc>2) { 52 if (*++argv) {
44 argv++;
45 n = strlen(*argv); 53 n = strlen(*argv);
46 m = strlen(s); 54 m = strlen(s);
47 if (m>n && strncmp(s+m-n, *argv, n)==0) 55 if ((m > n) && ((strcmp)(s+m-n, *argv) == 0)) {
48 s[m-n] = '\0'; 56 s[m-n] = '\0';
57 }
49 } 58 }
59
50 puts(s); 60 puts(s);
51 return EXIT_SUCCESS; 61
62 bb_fflush_stdout_and_exit(EXIT_SUCCESS);
52} 63}