… | |
… | |
499 | |
499 | |
500 | if (res < 0 && sbytes) |
500 | if (res < 0 && sbytes) |
501 | res = sbytes; |
501 | res = sbytes; |
502 | } |
502 | } |
503 | |
503 | |
|
|
504 | # endif |
504 | # else |
505 | #else |
505 | res = -1; |
506 | res = -1; |
506 | errno = ENOSYS; |
507 | errno = ENOSYS; |
507 | # endif |
|
|
508 | #endif |
508 | #endif |
509 | |
509 | |
510 | if (res < 0 |
510 | if (res < 0 |
511 | && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK |
511 | && (errno == ENOSYS || errno == EINVAL || errno == ENOTSOCK |
512 | #if __solaris |
512 | #if __solaris |
… | |
… | |
517 | { |
517 | { |
518 | /* emulate sendfile. this is a major pain in the ass */ |
518 | /* emulate sendfile. this is a major pain in the ass */ |
519 | char buf[4096]; |
519 | char buf[4096]; |
520 | res = 0; |
520 | res = 0; |
521 | |
521 | |
522 | for (;;) |
522 | while (count) |
523 | { |
523 | { |
524 | ssize_t cnt; |
524 | ssize_t cnt; |
525 | |
525 | |
526 | cnt = pread (ifd, buf, 4096, offset); |
526 | cnt = pread (ifd, buf, count > 4096 ? 4096 : count, offset); |
527 | |
527 | |
528 | if (cnt <= 0) |
528 | if (cnt <= 0) |
529 | { |
529 | { |
530 | if (cnt && !res) res = -1; |
530 | if (cnt && !res) res = -1; |
531 | break; |
531 | break; |
… | |
… | |
539 | break; |
539 | break; |
540 | } |
540 | } |
541 | |
541 | |
542 | offset += cnt; |
542 | offset += cnt; |
543 | res += cnt; |
543 | res += cnt; |
|
|
544 | count -= cnt; |
544 | } |
545 | } |
545 | } |
546 | } |
546 | |
547 | |
547 | return res; |
548 | return res; |
548 | } |
549 | } |