1 /* vi: set sw=4 ts=4: */
3 * Mini basename implementation for busybox
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
11 /* BB_AUDIT SUSv3 compliant */
12 /* http://www.opengroup.org/onlinepubs/007904975/utilities/basename.html */
15 /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
18 * 1) Now checks for too many args. Need at least one and at most two.
19 * 2) Don't check for options, as per SUSv3.
20 * 3) Save some space by using strcmp(). Calling strncmp() here was silly.
28 int basename_main(int argc, char **argv)
33 if (((unsigned int)(argc-2)) >= 2) {
37 s = bb_get_last_path_component(*++argv);
42 if ((m > n) && ((strcmp)(s+m-n, *argv) == 0)) {
49 bb_fflush_stdout_and_exit(EXIT_SUCCESS);