Put echo on a diet, removing unnecessary use of stdio and getopt.
Before... -r-xr-xr-x 1 root wheel 58636 Oct 28 05:16 /bin/echo After... -rwxr-xr-x 1 root wheel 12824 Nov 12 17:39 /usr/obj/usr/src/bin/echo/echo Submitted by: Tim Kientzle <kientzle@acm.org>
This commit is contained in:
parent
0ac1a67828
commit
ef3e71dac3
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=106835
@ -45,8 +45,7 @@ static char sccsid[] = "@(#)echo.c 8.1 (Berkeley) 5/31/93";
|
|||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__FBSDID("$FreeBSD$");
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
@ -64,6 +63,9 @@ main(int argc __unused, char *argv[])
|
|||||||
nflag = 0;
|
nflag = 0;
|
||||||
|
|
||||||
while (argv[0] != NULL) {
|
while (argv[0] != NULL) {
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
len = strlen(argv[0]);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the next argument is NULL then this is this
|
* If the next argument is NULL then this is this
|
||||||
@ -71,23 +73,20 @@ main(int argc __unused, char *argv[])
|
|||||||
* for a trailing \c.
|
* for a trailing \c.
|
||||||
*/
|
*/
|
||||||
if (argv[1] == NULL) {
|
if (argv[1] == NULL) {
|
||||||
size_t len;
|
|
||||||
|
|
||||||
len = strlen(argv[0]);
|
|
||||||
/* is there room for a '\c' and is there one? */
|
/* is there room for a '\c' and is there one? */
|
||||||
if (len >= 2 &&
|
if (len >= 2 &&
|
||||||
argv[0][len - 2] == '\\' &&
|
argv[0][len - 2] == '\\' &&
|
||||||
argv[0][len - 1] == 'c') {
|
argv[0][len - 1] == 'c') {
|
||||||
/* chop it and set the no-newline flag. */
|
/* chop it and set the no-newline flag. */
|
||||||
argv[0][len - 2] = '\0';
|
len -= 2;
|
||||||
nflag = 1;
|
nflag = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(void)printf("%s", argv[0]);
|
write(STDOUT_FILENO, argv[0], len);
|
||||||
if (*++argv)
|
if (*++argv)
|
||||||
putchar(' ');
|
write(STDOUT_FILENO, " ", 1);
|
||||||
}
|
}
|
||||||
if (!nflag)
|
if (!nflag)
|
||||||
putchar('\n');
|
write(STDOUT_FILENO, "\n", 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user