mirror of
https://github.com/ps5-payload-dev/ftpsrv.git
synced 2026-10-18 18:03:30 -05:00
io: add alternative to sendflie
This commit is contained in:
1 parent
1917ea7d12
commit
c82212bcf0
2 files changed
+39
No files matched your search
@@ -57,6 +57,39 @@ io_nwrite(int fd, const void* buf, size_t n) {
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
io_ncopy(int fd_in, int fd_out, size_t size) {
|
||||
size_t copied = 0;
|
||||
void* buf;
|
||||
ssize_t n;
|
||||
|
||||
if(!(buf=malloc(IO_COPY_BUFSIZE))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
while(copied < size) {
|
||||
n = size - copied;
|
||||
if(n > IO_COPY_BUFSIZE) {
|
||||
n = IO_COPY_BUFSIZE;
|
||||
}
|
||||
|
||||
if(io_nread(fd_in, buf, n)) {
|
||||
free(buf);
|
||||
return -1;
|
||||
}
|
||||
if(io_nwrite(fd_out, buf, n)) {
|
||||
free(buf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
copied += n;
|
||||
}
|
||||
|
||||
free(buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
io_pread(int fd, void* buf, size_t n, off_t off) {
|
||||
int r;
|
||||
|
||||
@@ -37,6 +37,12 @@ int io_nread(int fd, void* buf, size_t n);
|
||||
int io_nwrite(int fd, const void* buf, size_t n);
|
||||
|
||||
|
||||
/**
|
||||
* Copy exactly N bytes from one file descriptor to another.
|
||||
**/
|
||||
int io_ncopy(int fd_in, int fd_out, size_t size);
|
||||
|
||||
|
||||
/**
|
||||
* Copy exactly N bytes from a file descriptor to a socket.
|
||||
**/
|
||||
|
||||
Reference in new issue
Block a user