summaryrefslogtreecommitdiff
path: root/usr/src/lib/libcmd/common/basename.c
diff options
context:
space:
mode:
authorAndy Fiddaman <omnios@citrus-it.co.uk>2020-12-27 17:47:37 +0000
committerAndy Fiddaman <omnios@citrus-it.co.uk>2021-01-30 17:13:33 +0000
commitb30d193948be5a7794d7ae3ba0ed9c2f72c88e0f (patch)
tree6a37e590faffb9bb9af66887de645c546445036c /usr/src/lib/libcmd/common/basename.c
parentdf36e06d12cbf655ddf22339ef8c39fa2b83ebf8 (diff)
downloadillumos-joyent-b30d193948be5a7794d7ae3ba0ed9c2f72c88e0f.tar.gz
13405 ksh93 update to 2012-08-01
13434 sh: mishandles backslash as last character of a block of input 11750 ksh mkdir builtin doesn't honor special file permissions 9199 ksh93 builtin *grep -v mishandles blank lines, blows up libgcrypt-config 6756 sh (and ksh) have issues with ${1+"$@"} 6520 ksh: sleep could wait forever 4860 ksh93: core in printf 3791 /bin/sh's builtin 'rm' busted: 'rm -f' without arguments returns error 1047 ksh overwrites child core files 880 ksh93 coredumps on 'unset' 499 "interrupted system call" when using "tee" builtin in ksh Reviewed by: Robert Mustacchi <rm@fingolfin.org> Reviewed by: Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org> Reviewed by: Dominik Hassler <hadfl@omnios.org> Approved by: Rich Lowe <richlowe@richlowe.net>
Diffstat (limited to 'usr/src/lib/libcmd/common/basename.c')
-rw-r--r--usr/src/lib/libcmd/common/basename.c116
1 files changed, 0 insertions, 116 deletions
diff --git a/usr/src/lib/libcmd/common/basename.c b/usr/src/lib/libcmd/common/basename.c
deleted file mode 100644
index 74da190ce8..0000000000
--- a/usr/src/lib/libcmd/common/basename.c
+++ /dev/null
@@ -1,116 +0,0 @@
-/***********************************************************************
-* *
-* This software is part of the ast package *
-* Copyright (c) 1992-2010 AT&T Intellectual Property *
-* and is licensed under the *
-* Common Public License, Version 1.0 *
-* by AT&T Intellectual Property *
-* *
-* A copy of the License is available at *
-* http://www.opensource.org/licenses/cpl1.0.txt *
-* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
-* *
-* Information and Software Systems Research *
-* AT&T Research *
-* Florham Park NJ *
-* *
-* Glenn Fowler <gsf@research.att.com> *
-* David Korn <dgk@research.att.com> *
-* *
-***********************************************************************/
-#pragma prototyped
-/*
- * David Korn
- * AT&T Bell Laboratories
- *
- * namebase pathname [suffix]
- *
- * print the namebase of a pathname
- */
-
-static const char usage[] =
-"[-?\n@(#)$Id: basename (AT&T Research) 1999-04-10 $\n]"
-USAGE_LICENSE
-"[+NAME?basename - strip directory and suffix from filenames]"
-"[+DESCRIPTION?\bbasename\b removes all leading directory components "
- "from the file name defined by \astring\a. If the file name "
- "defined by \astring\a has a suffix that ends in \asuffix\a, "
- "it is removed as well.]"
-"[+?If \astring\a consists solely of \b/\b characters the output will "
- "be a single \b/\b unless \bPATH_LEADING_SLASHES\b returned by "
- "\bgetconf\b(1) is \b1\b and \astring\a consists of multiple "
- "\b/\b characters in which case \b//\b will be output. "
- "Otherwise, trailing \b/\b characters are removed, and if "
- "there are any remaining \b/\b characters in \astring\a, "
- "all characters up to and including the last \b/\b are removed. "
- "Finally, if \asuffix\a is specified, and is identical the end "
- "of \astring\a, these characters are removed. The characters "
- "not removed from \astring\a will be written to standard output.]"
-"\n"
-"\n string [suffix]\n"
-"\n"
-"[+EXIT STATUS?]{"
- "[+0?Successful Completion.]"
- "[+>0?An error occurred.]"
-"}"
-"[+SEE ALSO?\bdirname\b(1), \bgetconf\b(1), \bbasename\b(3)]"
-;
-
-
-#include <cmd.h>
-
-static void namebase(Sfio_t *outfile, register char *pathname, char *suffix)
-{
- register char *first, *last;
- register int n=0;
- for(first=last=pathname; *last; last++);
- /* back over trailing '/' */
- if(last>first)
- while(*--last=='/' && last > first);
- if(last==first && *last=='/')
- {
- /* all '/' or "" */
- if(*first=='/')
- if(*++last=='/') /* keep leading // */
- last++;
- }
- else
- {
- for(first=last++;first>pathname && *first!='/';first--);
- if(*first=='/')
- first++;
- /* check for trailing suffix */
- if(suffix && (n=strlen(suffix)) && n<(last-first))
- {
- if(memcmp(last-n,suffix,n)==0)
- last -=n;
- }
- }
- if(last>first)
- sfwrite(outfile,first,last-first);
- sfputc(outfile,'\n');
-}
-
-int
-b_basename(int argc,register char *argv[], void* context)
-{
- register int n;
-
- cmdinit(argc, argv, context, ERROR_CATALOG, 0);
- while (n = optget(argv, usage)) switch (n)
- {
- case ':':
- error(2, "%s", opt_info.arg);
- break;
- case '?':
- error(ERROR_usage(2), "%s", opt_info.arg);
- break;
- }
- argv += opt_info.index;
- argc -= opt_info.index;
- if(error_info.errors || argc < 1 || argc > 2)
- error(ERROR_usage(2), "%s", optusage(NiL));
- namebase(sfstdout,argv[0],argv[1]);
- return(0);
-}
-