|
|
1.1 ! root 1: /* x_cp.c - x_cp */ ! 2: ! 3: #include <conf.h> ! 4: #include <kernel.h> ! 5: #include <shell.h> ! 6: ! 7: LOCAL char errfmt[] = "Cannot open %s\n"; ! 8: ! 9: /*------------------------------------------------------------------------ ! 10: * x_cp - (copy command) copy one file to another ! 11: *------------------------------------------------------------------------ ! 12: */ ! 13: COMMAND x_cp(stdin, stdout, stderr, nargs, args) ! 14: int stdin, stdout, stderr, nargs; ! 15: char *args[]; ! 16: { ! 17: char *buf; ! 18: int from, to; ! 19: int ret; ! 20: int len; ! 21: ! 22: if (nargs != 3) { ! 23: fprintf(stderr, "usage: cp file1 file2\n"); ! 24: return(SYSERR); ! 25: } ! 26: if ( (from=open(NAMESPACE, args[1], "ro")) == SYSERR) { ! 27: fprintf(stderr, errfmt, args[1]); ! 28: return(SYSERR); ! 29: } ! 30: if ( (to=open(NAMESPACE, args[2], "w")) == SYSERR) { ! 31: close(from); ! 32: fprintf(stderr, errfmt, args[2]); ! 33: return(SYSERR); ! 34: } ! 35: if ( ((int) (buf = (char *)getmem(512)) ) == SYSERR) { ! 36: fprintf(stderr, "no memory\n"); ! 37: ret = SYSERR; ! 38: } else { ! 39: while ( (len = read(from, buf, 512)) > 0 ) ! 40: write(to, buf, len); ! 41: freemem(buf, 512); ! 42: ret = OK; ! 43: } ! 44: close(from); ! 45: close(to); ! 46: return(ret); ! 47: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.