return;
}
- size_t filelen = statbuf.st_size;
- sprintf(buf, "%zd\n", filelen);
+ size_t datalen = statbuf.st_size;
+ if (start > 0) {
+ if (start >= datalen) {
+ datalen = 0;
+ } else {
+ lseek(file, start, SEEK_SET);
+ datalen -= start;
+ }
+ }
+ if (len > 0 && len < datalen) {
+ datalen = len;
+ }
+
+ sprintf(buf, "%zd\n", datalen);
write_data(fd, buf, strlen(buf));
- while (filelen > 0) {
- size_t needed = filelen > sizeof(buf) ? sizeof(buf) : filelen;
+ while (datalen > 0) {
+ size_t needed = datalen > sizeof(buf) ? sizeof(buf) : datalen;
ssize_t bytes = read(file, buf, needed);
if (bytes < 0 && errno == EINTR)
continue;
bytes = needed;
}
write_data(fd, buf, bytes);
- filelen -= bytes;
+ datalen -= bytes;
}
close(file);