mirror of
https://github.com/troglobit/libite.git
synced 2026-10-27 12:11:06 +00:00
fcopyfile: Westermo fixes and code simplification
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
1a9d3bd91b
commit
cd073f5221
1 file changed
+9
-13
+9
-13
@@ -237,27 +237,23 @@ int movefile(char *src, char *dst)
|
|||||||
*/
|
*/
|
||||||
int fcopyfile(FILE *src, FILE *dst)
|
int fcopyfile(FILE *src, FILE *dst)
|
||||||
{
|
{
|
||||||
int ret;
|
char *buf;
|
||||||
char *buffer;
|
|
||||||
|
|
||||||
if (!src || !dst) {
|
if (!src || !dst) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = malloc(BUFSIZ);
|
buf = malloc(BUFSIZ);
|
||||||
if (!buffer)
|
if (!buf)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
ret = do_copy(fileno(src), fileno(dst), BUFSIZ, buffer, BUFSIZ);
|
while (fgets(buf, BUFSIZ, src))
|
||||||
if (ret > 0)
|
fputs(buf, dst);
|
||||||
ret = 0;
|
|
||||||
else if (errno)
|
free(buf);
|
||||||
ret = -1;
|
|
||||||
|
|
||||||
free(buffer);
|
return 0;
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef UNITTEST
|
#ifdef UNITTEST
|
||||||
@@ -267,7 +263,7 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char *files[] = {
|
char *files[] = {
|
||||||
"/etc/passwd", "/tmp/tok", "/tmp/tok",
|
"/etc/passwd", "/tmp/mypwd", "/tmp/mypwd",
|
||||||
"/etc/passwd", "/tmp/", "/tmp/passwd",
|
"/etc/passwd", "/tmp/", "/tmp/passwd",
|
||||||
"/etc/passwd", "/tmp", "/tmp/passwd",
|
"/etc/passwd", "/tmp", "/tmp/passwd",
|
||||||
NULL
|
NULL
|
||||||
|
|||||||
Reference in new issue
Block a user