Utility for copying and renaming files.

Utility for copying and renaming files.

Files at this revision

API Documentation at this revision

Comitter:
ollie8
Date:
Mon Jan 26 08:28:04 2015 +0000
Parent:
1:1f1e0c92b3f8
Commit message:
Fixed bug where rename would always return true.

Changed in this revision

FileUtils.h Show annotated file Show diff for this revision Revisions of this file
--- a/FileUtils.h	Mon Dec 30 20:40:50 2013 +0000
+++ b/FileUtils.h	Mon Jan 26 08:28:04 2015 +0000
@@ -1,6 +1,8 @@
 
+#define DEBUG
+#include "logger.h"
 /** fcopy: Copies a file
- *            Checks to insure destination file was created.
+ *            Checks to ensure destination file was created.
  *            Returns -1 = error; 0 = success
  */
 int fcopy (const char *src, const char *dst) { 
@@ -16,23 +18,27 @@
     int retval = 0;
     fpdst = fopen(dst, "r");
     if (fpdst == NULL) {
-        retval = -1;
+        retval = 0;
     } else {
         fclose(fpdst); 
-        retval = 0;
+        retval = 1;
     }
     return retval;
 }
 
 /** frename: renames a file (via copy & delete).
  *    Moves data instead of adjusting the file name in the
- *    file directory. Checks to insure the file was renamed.
+ *    file directory. Checks to ensure the file was renamed.
  *    Returns -1 = error; 0 = success
  */
 int frename(const char *oldfname, const char *newfname) {
-    int retval = 0;
+    int retval = -1;
+    INFO("Renaming");
     if (fcopy(oldfname, newfname)) {
+        INFO("Deleting");
         remove(oldfname);    
+        retval = 0;
     }     
+    INFO("Done");
     return retval;
 }
\ No newline at end of file