/* lseek - executable wrapper for the C lseek() function usage: lseek fd offset origin types: int fd; long offset; int origin; fd can be 0 for stdin 1 for stdout 2 for stderr n for fd n offset is the number of bytes from the origin origin can be 0 for SEEK_SET (beginning of file) 1 for SEEK_CUR (current position in file) 2 for SEEK_END (end of file) example sh usage: # RESTORE FD exec 3</dev/null # lseek 3 0 2 note that dd seek does not work */ #include /* lseek */ #include long lseek(int fd, long offset, int origin); int fd; long offset; int origin; /* SEEK_SET=0; SEEK_CUR=1; SEEK_END=2; */ int main(int argc, char ** argv) { if(argc!=4) return 1; sscanf(argv[1], "%d", &fd); sscanf(argv[2], "%ld", &offset); sscanf(argv[3], "%d", &origin); offset=lseek(fd, offset, origin); printf("%ld\n", offset); return offset==-1 ? 2 : 0; } /* can use this as a goto with . /dev/stdin