Annotation of xinu/sys/shell/x_cat.c, revision 1.1.1.1

1.1       root        1: /* x_cat.c - x_cat */
                      2: 
                      3: #include <conf.h>
                      4: #include <kernel.h>
                      5: #include <shell.h>
                      6: 
                      7: /*------------------------------------------------------------------------
                      8:  *  x_cat  -  (command cat) concatenate files and write on stdout
                      9:  *------------------------------------------------------------------------
                     10:  */
                     11: COMMAND        x_cat(stdin, stdout, stderr, nargs, args)
                     12: int    stdin, stdout, stderr, nargs;
                     13: char   *args[];
                     14: {
                     15:        int     device;
                     16:        char    *buf;
                     17:        int     ret;
                     18:        int     len;
                     19:        int     i;
                     20: 
                     21:        if ( (buf = (char *)getmem(512)) == (char *)SYSERR) {
                     22:                fprintf(stderr, "no memory\n");
                     23:                return(SYSERR);
                     24:        }
                     25:        ret = OK;
                     26:        if (nargs == 1) {
                     27:                while ( (len=read(stdin, buf, 512)) > 0)
                     28:                        write(stdout, buf, len);
                     29:        }
                     30:        for (i=1 ; i<nargs ; i++) {
                     31:                if ( (device = open(NAMESPACE,args[i],"ro")) == SYSERR) {
                     32:                        fprintf(stderr, "Cannot open %s\n", args[i]);
                     33:                        ret = SYSERR;
                     34:                        break;
                     35:                }
                     36:                while ( (len=read(device, buf, 512)) > 0)
                     37:                        write (stdout, buf, len);
                     38:                close(device);
                     39:        }
                     40:        freemem(buf, 512);
                     41:        return(ret);
                     42: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.