mirror of
https://github.com/troglobit/finit.git
synced 2026-10-20 11:19:35 +00:00
libite: Minor style cleanup of fsendfile()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
9f91b4c050
commit
e81c2f2f90
1 file changed
+10
-11
+10
-11
@@ -240,33 +240,32 @@ exit:
|
|||||||
*/
|
*/
|
||||||
size_t fsendfile (FILE *out, FILE *in, size_t sz)
|
size_t fsendfile (FILE *out, FILE *in, size_t sz)
|
||||||
{
|
{
|
||||||
char *buf = malloc(BUFSIZ);
|
char *buf;
|
||||||
size_t blk = BUFSIZ, ret = 0, tot = 0;
|
size_t blk = BUFSIZ, num = 0, tot = 0;
|
||||||
|
|
||||||
|
buf = (char *)malloc(BUFSIZ);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
while (!sz || tot < sz)
|
while (!sz || tot < sz) {
|
||||||
{
|
|
||||||
if (sz && ((sz - tot) < BUFSIZ))
|
if (sz && ((sz - tot) < BUFSIZ))
|
||||||
blk = sz - tot;
|
blk = sz - tot;
|
||||||
|
|
||||||
ret = fread(buf, 1, blk, in);
|
num = fread(buf, 1, blk, in);
|
||||||
if (ret <= 0)
|
if (num == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (out && (fwrite(buf, ret, 1, out) != 1))
|
if (out && (fwrite(buf, num, 1, out) != 1)) {
|
||||||
{
|
num = -1;
|
||||||
ret = -1;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
tot += ret;
|
tot += num;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
return (ret == (size_t)-1)? (size_t)-1 : tot;
|
return (num == (size_t)-1) ? (size_t)-1 : tot;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Tests if dst is a directory, if so, reallocates dst and appends src filename returning 1 */
|
/* Tests if dst is a directory, if so, reallocates dst and appends src filename returning 1 */
|
||||||
|
|||||||
Reference in new issue
Block a user