Date: Mon, 7 Oct 2002 20:52:07 -0700 (PDT) From: Tim Kientzle <kientzle@acm.org> To: freebsd-gnats-submit@FreeBSD.org Subject: bin/43810: 'echo' is too big Message-ID: <200210080352.g983q7bl050253@www.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 43810 >Category: bin >Synopsis: 'echo' is too big >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon Oct 07 21:00:11 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Tim Kientzle >Release: FreeBSD-CURRENT >Organization: >Environment: >Description: Compiled, statically linked, and stripped, 'echo' is over 40k!! A few space-conscious edits reduce that to just over 5k. >How-To-Repeat: ls -l /bin/echo <gasp in amazement> >Fix: Following patch reduces 'echo' to just over 5k with _no_lost_functionality_ (even that obscure \c hack still works): diff --context echo.c-original echo.c *** echo.c-original Mon Oct 7 20:44:50 2002 --- echo.c Mon Oct 7 20:44:15 2002 *************** *** 45,52 **** #include <sys/cdefs.h> __FBSDID("$FreeBSD: src/bin/echo/echo.c,v 1.13 2002/06/30 05:13:53 obrien Exp $"); - #include <stdio.h> - #include <stdlib.h> #include <string.h> /* ARGSUSED */ --- 45,50 ---- *************** *** 56,62 **** int nflag; /* if not set, output a trailing newline. */ /* This utility may NOT do getopt(3) option parsing. */ ! if (*++argv && !strcmp(*argv, "-n")) { ++argv; nflag = 1; } --- 54,60 ---- int nflag; /* if not set, output a trailing newline. */ /* This utility may NOT do getopt(3) option parsing. */ ! if (*++argv && argv[0][0]=='-' && argv[0][1]=='n') { ++argv; nflag = 1; } *************** *** 64,69 **** --- 62,69 ---- nflag = 0; while (argv[0] != NULL) { + size_t len; + len = strlen(argv[0]); /* * If the next argument is NULL then this is this *************** *** 71,93 **** * for a trailing \c. */ if (argv[1] == NULL) { - size_t len; - - len = strlen(argv[0]); /* is there room for a '\c' and is there one? */ if (len >= 2 && argv[0][len - 2] == '\\' && argv[0][len - 1] == 'c') { /* chop it and set the no-newline flag. */ - argv[0][len - 2] = '\0'; nflag = 1; } } ! (void)printf("%s", argv[0]); if (*++argv) ! putchar(' '); } if (!nflag) ! putchar('\n'); return 0; } --- 71,90 ---- * for a trailing \c. */ if (argv[1] == NULL) { /* is there room for a '\c' and is there one? */ if (len >= 2 && argv[0][len - 2] == '\\' && argv[0][len - 1] == 'c') { /* chop it and set the no-newline flag. */ nflag = 1; + len -= 2; } } ! (void)write(1,argv[0],len); if (*++argv) ! write(1," ",1); } if (!nflag) ! write(1,"\n",1); return 0; } >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200210080352.g983q7bl050253>