FreeCalypso > hg > freecalypso-sw
diff rvinterf/etmsync/fswrite.c @ 293:ffeea2f9d149
fc-fsio: fwrite from file implemented, but no 0 length file handling yet
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sat, 01 Mar 2014 03:53:49 +0000 |
parents | 3aa03b9519c0 |
children | 797468042b32 |
line wrap: on
line diff
--- a/rvinterf/etmsync/fswrite.c Sat Mar 01 03:09:10 2014 +0000 +++ b/rvinterf/etmsync/fswrite.c Sat Mar 01 03:53:49 2014 +0000 @@ -140,8 +140,42 @@ fwrite_from_file(pathname, srcfile) char *pathname, *srcfile; { - fprintf(stderr, "This function is not yet implemented\n"); - return(ERROR_BUG); + u_char buf[240]; + FILE *srcf; + int rc, cc, first, tfd; + + srcf = fopen(srcfile, "r"); + if (!srcf) { + perror(srcfile); + return(ERROR_UNIX); + } + for (first = 1; cc = fread(buf, 1, sizeof buf, srcf); first = 0) { + if (first) { + if (cc < sizeof buf && + cc <= max_short_file_write(pathname)) { + fclose(srcf); + return do_short_fwrite(pathname, buf, cc); + } + rc = fd_open(pathname, + FFS_O_WRONLY | FFS_O_CREATE | FFS_O_TRUNC, + &tfd); + if (rc) { + fclose(srcf); + return(rc); + } + } + rc = fd_write(tfd, buf, cc); + if (rc) { + fclose(srcf); + fd_close(tfd); + return(rc); + } + } + fclose(srcf); + if (first) + return(0); + else + return fd_close(tfd); } cmd_fwrite(argc, argv)