/* $Header: /CVSROOT/debris/cmds/get.c,v 1.2 2005/08/15 01:04:52 tino Exp $ * * DebRIS: DEBian Remote Install Scripter * *get * * $Log: get.c,v $ * Revision 1.2 2005/08/15 01:04:52 tino * all functions now have a prefix (dris_) * * Revision 1.1 2005/08/13 22:59:12 tino * additional functions, see ChangeLog */ static int driscmd_get(char *args) { const char *n; int fd, got; long long pos; char *end; long len; char buf[BUFSIZ*10]; n = dris_nextarg(&args); pos = strtoull(n, &end, 0); if (*end || !*n || pos<0) return dris_err("get: debris sends funny offset %s", n); n = dris_nextarg(&args); len = strtoul(n, &end, 0); if (*end || !*n || len<0) return dris_err("get: debris sends funny length %s", n); if ((fd=open(args, O_RDONLY))<0) return dris_err("get: cannot open %s", args); if (lseek(fd, (off_t)pos, SEEK_SET)!=pos) return dris_err("get: cannot seek to %lld", pos); while ((got=dris_readall(fd, buf, sizeof buf))>0) dris_buf_add(config.out, buf, got); if (close(fd)) return dris_err("get: cannot close %s", args); if (got<0) return dris_err("get: read error %s", args); return 0; }