MCPcopy Create free account
hub / github.com/FreeFem/FreeFem-sources / copyfile

Function copyfile

plugin/seq/shell.cpp:249–299  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

247}
248
249long copyfile(string *const &filecp, string *const &target) {
250 int tagetisdir = ff_isdir(target);
251 string filein = *filecp;
252 string filetarget = *target;
253
254 if (verbosity > 9) {
255 cout << " cpfile :" << filein << "-> " << filetarget << " " << tagetisdir << endl;
256 }
257
258 if (tagetisdir == 1) {
259 int i, l = filein.length( );
260
261 for (i = l - 1; i >= 0; i--) {
262 if (filein[i] == sepdir) {
263 break;
264 }
265 }
266
267 if (i < 0) {
268 i = 0;
269 }
270
271 filetarget += sepdir;
272 filetarget += filein.substr(i);
273 }
274
275 FILE *source = fopen(filein.c_str( ), "rb");
276 FILE *dest = fopen(filetarget.c_str( ), "wb");
277 if (verbosity > 1) {
278 cout << " cpfile :" << filein << "-> " << filetarget << endl;
279 }
280
281 if (!source && !dest) {
282 cout << " erreur copy file form " << endl;
283 cout << " file in : " << filein << " " << source << endl;
284 cout << " file taget : " << filetarget << " " << dest << endl;
285 ffassert(0);
286 return -1; // erreur
287 }
288
289 char buf[BUFSIZ];
290 size_t size;
291
292 while ((size = fread(buf, 1, BUFSIZ, source))) {
293 fwrite(buf, 1, size, dest);
294 }
295
296 fclose(source);
297 fclose(dest);
298 return 0;
299}
300
301extern mylex *zzzfff;
302static void init( ) {

Callers

nothing calls this directly

Calls 2

ff_isdirFunction · 0.85
lengthMethod · 0.45

Tested by

no test coverage detected