comparison 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
comparison
equal deleted inserted replaced
292:3aa03b9519c0 293:ffeea2f9d149
138 } 138 }
139 139
140 fwrite_from_file(pathname, srcfile) 140 fwrite_from_file(pathname, srcfile)
141 char *pathname, *srcfile; 141 char *pathname, *srcfile;
142 { 142 {
143 fprintf(stderr, "This function is not yet implemented\n"); 143 u_char buf[240];
144 return(ERROR_BUG); 144 FILE *srcf;
145 int rc, cc, first, tfd;
146
147 srcf = fopen(srcfile, "r");
148 if (!srcf) {
149 perror(srcfile);
150 return(ERROR_UNIX);
151 }
152 for (first = 1; cc = fread(buf, 1, sizeof buf, srcf); first = 0) {
153 if (first) {
154 if (cc < sizeof buf &&
155 cc <= max_short_file_write(pathname)) {
156 fclose(srcf);
157 return do_short_fwrite(pathname, buf, cc);
158 }
159 rc = fd_open(pathname,
160 FFS_O_WRONLY | FFS_O_CREATE | FFS_O_TRUNC,
161 &tfd);
162 if (rc) {
163 fclose(srcf);
164 return(rc);
165 }
166 }
167 rc = fd_write(tfd, buf, cc);
168 if (rc) {
169 fclose(srcf);
170 fd_close(tfd);
171 return(rc);
172 }
173 }
174 fclose(srcf);
175 if (first)
176 return(0);
177 else
178 return fd_close(tfd);
145 } 179 }
146 180
147 cmd_fwrite(argc, argv) 181 cmd_fwrite(argc, argv)
148 char **argv; 182 char **argv;
149 { 183 {