]> git.draconx.ca Git - gob-dx.git/commitdiff
Use "remove" to delete files.
authorNick Bowler <nbowler@draconx.ca>
Fri, 25 Feb 2022 04:26:39 +0000 (23:26 -0500)
committerNick Bowler <nbowler@draconx.ca>
Fri, 25 Feb 2022 04:41:26 +0000 (23:41 -0500)
The standard C library has a function to delete files, let's not pull
in unix headers just to get "unlink" when standard C will do fine.

src/main.c

index 73920ae0727f04ee1418438087e6f3335875b662..16f59dda0591e06a8ed060bd07658d21def3d1f5 100644 (file)
@@ -28,9 +28,7 @@
 #include <stdio.h>
 #include <errno.h>
 #include <string.h>
-#include <unistd.h>
 #include <stdlib.h>
-#include <sys/stat.h>
 #include <limits.h>
 #include <getopt.h>
 
@@ -4774,25 +4772,27 @@ compare_and_move (const char *old_filename)
                if (error)
                        goto end;
 
-               if (! equal && unlink (old_filename) != 0) {
-                       error_printf (GOB_ERROR, 0, "Can't remove %s: %s",
-                                     old_filename, g_strerror (errno));
+               if (!equal && remove(old_filename) != 0) {
+                       error_printf(GOB_ERROR, 0, "Can't remove %s: %s",
+                                    old_filename, g_strerror (errno));
                        goto end;
                }
        }
 
        if (equal) {
-               if (unlink (new_filename) != 0)
-                       error_printf (GOB_ERROR, 0, "Can't remove %s: %s",
-                                     new_filename, g_strerror (errno));
+               if (remove(new_filename) != 0) {
+                       error_printf(GOB_ERROR, 0, "Can't remove %s: %s",
+                                    new_filename, g_strerror(errno));
+               }
        } else {
-               if (rename (new_filename, old_filename) != 0)
-                       error_printf (GOB_ERROR, 0, "Can't rename %s to %s: %s",
-                                     new_filename, old_filename,
-                                     g_strerror (errno));
+               if (rename(new_filename, old_filename) != 0) {
+                       error_printf(GOB_ERROR, 0, "Can't rename %s to %s: %s",
+                                    new_filename, old_filename,
+                                    g_strerror(errno));
+               }
        }
 
- end:
+end:
        g_free (new_filename);
 }