dtprintinfo: Coverity 89561
[oweals/cde.git] / cde / programs / dtstyle / ColorFile.c
index a601b5eff24a1780371676fe96fc8434ce100003..28bc4287c94f724ca96a52f02f379b4857ee4121 100644 (file)
 
 #ifdef __hpux
 #include <ndir.h>               /*   opendir(), directory(3C) */
-#else
-#if SVR4 || sco
+#elif defined(SVR4) || defined(CSRG_BASED)
 #include <dirent.h>             /* opendir(), directory(3C) */
 #else
 #include <sys/dir.h>
-#ifdef __apollo
-#include <X11/apollosys.h>      /* needed for S_ISDIR macro */
-#endif
 #endif
-#endif
-
 
 #include <Xm/Xm.h>
 
@@ -254,7 +248,9 @@ ReadPalette(
 
     /* load the filename into the name element */
       p = strstr (in_filename, PALETTE_SUFFIX);
-      *p = '\0';
+      if(p) {
+          *p = '\0';
+      }
       strcpy(new_palette->name, in_filename);
 
 /* 
@@ -445,7 +441,7 @@ WriteOutPalette(
    strcat(filename, PALETTE_SUFFIX);
 
    /* open the file for writing */
-#if defined(linux)
+#if defined(__linux__)
    if( (fd = open( filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) == -1)
 #else
    if( (fd = open( filename, O_RDWR | O_CREAT)) == -1)
@@ -530,7 +526,10 @@ WriteOutDesc(
    if (hm_pl_DB )
      XrmPutFileDatabase(hm_pl_DB, desc_file);
    /* make the file read, write */
-   chmod(desc_file,438);
+   if(chmod(desc_file,438) == -1) {
+      fprintf(stderr, "failed to chmod '%s', %s\n", desc_file, strerror(errno));
+   }
+
    XtFree(desc_file);
    XtFree(desc_name);
 
@@ -1116,7 +1115,7 @@ CheckFileType( void )
 {
    char *filename1 = "abcdefghijklmno";
    char *filename2 = "abcdefghijklmn";
-   int  fd, fd1;
+   int  fd = -1, fd1 = -1;
    char *tmpfile1, *tmpfile2;
  
   /* get the $HOME environment varible and constuct the full file name */
@@ -1128,7 +1127,7 @@ CheckFileType( void )
    strcat(tmpfile1, DT_PAL_DIR);
    strcat(tmpfile1, filename1);
 
-#if defined(linux)
+#if defined(__linux__)
    if( (fd = open( tmpfile1, O_CREAT, S_IRUSR | S_IWUSR)) == -1)
 #else
    if( (fd = open( tmpfile1, O_CREAT)) == -1)
@@ -1148,7 +1147,7 @@ CheckFileType( void )
    strcat(tmpfile2, DT_PAL_DIR);
    strcat(tmpfile2, filename2);
 
-#if defined(linux)
+#if defined(__linux__)
    if( (fd1 = open(tmpfile2, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR)) == -1)
 #else
    if( (fd1 = open(tmpfile2, O_CREAT | O_EXCL)) == -1)
@@ -1166,7 +1165,9 @@ CheckFileType( void )
    XtFree(tmpfile1);
    XtFree(tmpfile2);
    close(fd);
-   close(fd1);
+   if(fd1 != -1) {
+      close(fd1);
+   }
    
 }