Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/planix-v0/sys/src/cmd/echo.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include <u.h>
2
#include <libc.h>
3
 
4
void
5
main(int argc, char *argv[])
6
{
7
	int nflag;
8
	int i, len;
9
	char *buf, *p;
10
 
11
	nflag = 0;
12
	if(argc > 1 && strcmp(argv[1], "-n") == 0)
13
		nflag = 1;
14
 
15
	len = 1;
16
	for(i = 1+nflag; i < argc; i++)
17
		len += strlen(argv[i])+1;
18
 
19
	buf = malloc(len);
20
	if(buf == 0)
21
		exits("no memory");
22
 
23
	p = buf;
24
	for(i = 1+nflag; i < argc; i++){
25
		strcpy(p, argv[i]);
26
		p += strlen(p);
27
		if(i < argc-1)
28
			*p++ = ' ';
29
	}
30
 
31
	if(!nflag)
32
		*p++ = '\n';
33
 
34
	if(write(1, buf, p-buf) < 0){
35
		fprint(2, "echo: write error: %r\n");
36
		exits("write error");
37
	}
38
 
39
	exits((char *)0);
40
}