[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: which echo.c would you choose?
- To: misc_(_at_)_openbsd_(_dot_)_org
- Subject: Re: which echo.c would you choose?
- From: Uwe Ohse <uwe_(_at_)_ohse_(_dot_)_de>
- Date: Wed, 1 Dec 1999 23:04:52 +0100
On Wed, Dec 01, 1999 at 09:54:39AM -0800, Jonathan Cline wrote:
> Tell me, which version is the best and why?
version e, the one with the
fflush(stdout);
exit(ferror(stdout)!=0);
at the end.
int
main(int argc,char **av)
{
int i=1;
int n=0;
char sep=' ';
int nosep=0;
#ifdef OVERFEATURED
/* careful: this can open a can of worms: usually i install that as Echo */
char *e=getenv("ECHO");
if (e) {
while (*e) {
if (*e=='n' || *e=='N') n=1; /* noNewline */
if (*e=='f' || *e=='F') sep='\n'; /* lineFeed */
if (*e=='s' || *e=='S') if (strpbrk(e,"sS")) nosep=1;
if (*e=='0') sep='\0';
e++;
}
} else
#endif
n=(argc>1 && av[i][0]=='-' && av[i][1]=='n' && !av[i][2] && i++);
while (av[i]) {
fputs(av[i],stdout);
if (av[++i] && !nosep) putchar(sep);
}
if (!n) putchar('\n');
fflush(stdout);
exit(ferror(stdout)!=0);
}
Regards, Uwe
Visit your host, monkey.org