techo.c - plan9port - [fork] Plan 9 from user space
git clone git://src.adamsgaard.dk/plan9port
Log
Files
Refs
README
LICENSE
---
techo.c (551B)
---
     1 #include 
     2 #include 
     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 
    37         exits((char *)0);
    38 }