dthelp: Change to ANSI function definitions
[oweals/cde.git] / cde / programs / dtfile / Trash.c
index b49c66ba6fc3b1417e16639716932d6c929d622d..ad792753770d597bfc47152eeb64f618bcb92aa9 100644 (file)
@@ -16,7 +16,7 @@
  * details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with these librararies and programs; if not, write
+ * License along with these libraries and programs; if not, write
  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  * Floor, Boston, MA 02110-1301 USA
  */
 #include <dirent.h>
 #include <unistd.h>
 #include <string.h>
+#include <stdint.h>
 #if defined(CSRG_BASED)
 #include <sys/param.h>
 #include <sys/mount.h>
@@ -2712,7 +2713,7 @@ MoveToTrashProcess(
    DIR * dirp;
    struct dirent * entry;
    Boolean success;
-   int i, rc;
+   int i, rc, rv;
    char savechar;
 
    for (i = 0; i < file_count; i++)
@@ -2727,8 +2728,8 @@ MoveToTrashProcess(
          pipe_msg = PIPEMSG_OTHER_ERROR;
          rc = BAD_FILE_ERROR;
          DPRINTF(("MoveToTrashProcess: sending BAD_FILE_ERROR\n"));
-         write(pipe_fd, &pipe_msg, sizeof(short));
-         write(pipe_fd, &rc, sizeof(int));
+         rv = write(pipe_fd, &pipe_msg, sizeof(short));
+         rv = write(pipe_fd, &rc, sizeof(int));
          continue;
       }
       if (path && MatchesSacredDirectory(path))
@@ -2738,8 +2739,8 @@ MoveToTrashProcess(
          pipe_msg = PIPEMSG_OTHER_ERROR;
          rc = BAD_FILE_SACRED;
          DPRINTF(("MoveToTrashProcess: sending BAD_FILE_SACRED\n"));
-         write(pipe_fd, &pipe_msg, sizeof(short));
-         write(pipe_fd, &rc, sizeof(int));
+         rv = write(pipe_fd, &pipe_msg, sizeof(short));
+         rv = write(pipe_fd, &rc, sizeof(int));
          continue;
       }
 
@@ -2777,8 +2778,8 @@ MoveToTrashProcess(
            XtFree(path);
            pipe_msg = PIPEMSG_OTHER_ERROR;
            DPRINTF(("MoveToTrashProcess: sending BAD_TRASH message\n"));
-           write(pipe_fd, &pipe_msg, sizeof(short));
-           write(pipe_fd, &rc, sizeof(int));
+           rv = write(pipe_fd, &pipe_msg, sizeof(short));
+           rv = write(pipe_fd, &rc, sizeof(int));
            continue;
          }
          else if (CheckAccess(path, W_OK) != 0 && !S_ISLNK(s1.st_mode))
@@ -2788,8 +2789,8 @@ MoveToTrashProcess(
             pipe_msg = PIPEMSG_OTHER_ERROR;
             rc = VERIFY_FILE;
             DPRINTF(("MoveToTrashProcess: sending VERIFY_FILE\n"));
-            write(pipe_fd, &pipe_msg, sizeof(short));
-            write(pipe_fd, &rc, sizeof(int));
+            rv = write(pipe_fd, &pipe_msg, sizeof(short));
+            rv = write(pipe_fd, &rc, sizeof(int));
             continue;
          }
 
@@ -2823,8 +2824,8 @@ MoveToTrashProcess(
                pipe_msg = PIPEMSG_OTHER_ERROR;
                rc = VERIFY_DIR;
                DPRINTF(("MoveToTrashProcess: sending VERIFY_DIR\n"));
-               write(pipe_fd, &pipe_msg, sizeof(short));
-               write(pipe_fd, &rc, sizeof(int));
+               rv = write(pipe_fd, &pipe_msg, sizeof(short));
+               rv = write(pipe_fd, &rc, sizeof(int));
                continue;
             }
          }
@@ -2840,7 +2841,7 @@ MoveToTrashProcess(
       {
          pipe_msg = PIPEMSG_DONE;
          DPRINTF(("MoveToTrashProcess: sending DONE\n"));
-         write(pipe_fd, &pipe_msg, sizeof(short));
+         rv = write(pipe_fd, &pipe_msg, sizeof(short));
          PipeWriteString(pipe_fd, path);
          PipeWriteString(pipe_fd, to);
       }
@@ -3447,7 +3448,7 @@ RestoreProcess(
        int *rc,
        Boolean CheckedAlready)
 {
-   int i, j;
+   int i, j, rv;
    char *full_dirname;
    char *from, *to;
    char *ptr;
@@ -3468,8 +3469,8 @@ RestoreProcess(
         pipe_msg = PIPEMSG_DONE;
         rc[0] = -1;
         DPRINTF(("RestoreProcess: Unable to Resolve local path name\n"));
-        write(pipe_fd, &pipe_msg, sizeof(short));
-        write(pipe_fd, rc, sizeof(int));
+        rv = write(pipe_fd, &pipe_msg, sizeof(short));
+        rv = write(pipe_fd, rc, sizeof(int));
         return;
       }
    }
@@ -3539,8 +3540,8 @@ RestoreProcess(
    /* send return codes back trough the pipe */
    pipe_msg = PIPEMSG_DONE;
    DPRINTF(("RestoreProcess: sending DONE\n"));
-   write(pipe_fd, &pipe_msg, sizeof(short));
-   write(pipe_fd, rc, file_count * sizeof(int));
+   rv = write(pipe_fd, &pipe_msg, sizeof(short));
+   rv = write(pipe_fd, rc, file_count * sizeof(int));
 
    XtFree(full_dirname);
 }
@@ -3831,7 +3832,7 @@ EmptyTrashProcess(
        int del_count,
        int *rc)
 {
-   int i;
+   int i, rv;
    short pipe_msg;
 
    /*
@@ -3847,8 +3848,8 @@ EmptyTrashProcess(
    /* send return codes back trough the pipe */
    pipe_msg = PIPEMSG_DONE;
    DPRINTF(("EmptyTrashProcess: sending DONE\n"));
-   write(pipe_fd, &pipe_msg, sizeof(short));
-   write(pipe_fd, rc, del_count * sizeof(int));
+   rv = write(pipe_fd, &pipe_msg, sizeof(short));
+   rv = write(pipe_fd, rc, del_count * sizeof(int));
 }
 
 
@@ -4167,12 +4168,23 @@ CheckDeletePermission(
     if (FileSysType(statbuf.st_dev) < 0)  /* Root user and nfs */
 #endif
     {
+       int fd = -1;
        char *tmpfile;
-       tmpfile = tempnam(parentdir,"quang");
-       if (creat(tmpfile,O_RDONLY)< 0)         /* Create a temporary file */
-          return -1;
+       tmpfile = tempnam(parentdir,"dtfile");
+       if (!tmpfile)
+           return -1;
+       if ((fd = creat(tmpfile,O_RDONLY)) < 0)  /* Create a temporary file */
+       {
+           free(tmpfile);
+           return -1;
+       }
+       close(fd);
        if (remove(tmpfile) < 0)                /* Delete the created file */
-          return -1;
+       {
+           free(tmpfile);
+           return -1;
+       }
+       free(tmpfile);
     }
 
     /* root user can delete anything */
@@ -4222,8 +4234,10 @@ CheckDeletePermissionRecur(
       if (first_file)
       {
         /* check for write permission in this directory */
-        if (CheckAccess(destinationPath, W_OK|X_OK) < 0)
+        if (CheckAccess(destinationPath, W_OK|X_OK) < 0) {
+          closedir(dirp);
           return -1;
+        }
 
         /* append a '/' to the end of directory name */
         fnamep = destinationPath + strlen(destinationPath);
@@ -4237,10 +4251,16 @@ CheckDeletePermissionRecur(
 
       /* recursively check permission on this file */
       if (CheckDeletePermissionRecur(destinationPath))
-        return -1;
+      {
+          closedir(dirp);
+          return -1;
+      }
+
     }
   }
 
+  closedir(dirp);
+
   return 0;
 }
 
@@ -4270,7 +4290,8 @@ RestoreObject(
 {
   struct stat statsrc,stattar;
   Boolean status;
-  char *localdir,*chrptr;
+  char *localdir = NULL,*chrptr;
+  int rv;
 
   if(!CheckedAlready)
   {
@@ -4290,14 +4311,19 @@ RestoreObject(
     }
     if(stat(target,&stattar) >= 0)  /* Target exists  */
     {
-       if(CheckDeletePermission(localdir,target))
+       if(CheckDeletePermission(localdir,target)) {
+         free(localdir);
          return ((int)False);
-       else
+       } else {
+         free(localdir);
          return SKIP_FILE;
+       }
     }
   }
+
+  free(localdir);
   return ((int )FileManip((Widget)w, MOVE_FILE, source, target, TRUE,
-                                  FileOpError, False, NOT_DESKTOP));
+                          FileOpError, False, NOT_DESKTOP));
 }
 static void
 CreateRestoreDialog(