From 5af8aa41153ffde79a404e3a33ba774c28ea9ea3 Mon Sep 17 00:00:00 2001
From: Hannes Reinecke <hare@suse.de>
Date: Mon, 14 Apr 2014 16:35:04 +0200
Subject: [PATCH] Sanitize source code

Sanitize source code to comply with our build checks.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 aecs.c     | 109 ++++++++++++++++++++++++++++++-------------------------------
 cmsfs.h    |   4 +++
 cmsfsany.c |  17 +++++-----
 cmsfscat.c |  12 ++++---
 cmsfsck.c  |   6 ++--
 cmsfscp.c  |  13 ++++----
 cmsfsext.c |  44 ++++++++++++-------------
 cmsfslst.c |  12 +++----
 cmsfsusa.c |  18 +++++-----
 cmsfsvol.c |  10 +++---
 10 files changed, 122 insertions(+), 123 deletions(-)

diff --git a/aecs.c b/aecs.c
index 99432b7..fdd0cee 100644
--- a/aecs.c
+++ b/aecs.c
@@ -1,56 +1,53 @@
-/* ----------------------------------------------------------------- ÆCS 
- * ASCII to EBCDIC and vice-versa code conversion routines. 
- * Tables included here are based on ASCII conforming to the ISO8859-1 
- * Latin 1 character set and EBCDIC conforming to the IBM Code Page 37 
- * Latin 1 character set (except for three pairs of characters in 037). 
- * This C source requires header file AECS.H. 
- */ 
- 
-#include "aecs.h" 
- 
-/* ------------------------------------------------------------- CHRATOE 
- * Translate an ASCII character into EBCDIC. 
- */ 
-int chratoe(unsigned int c) 
-  { 
-    c &= 0xFF; 
-    return (ebc8859[c]); 
-  } 
- 
-/* ------------------------------------------------------------- STRATOE 
- * Translate an ASCII string into EBCDIC in place. Return length. 
- */ 
-int stratoe(string) 
-  unsigned char *string; 
-  { 
-    int 	i; 
- 
-    for ( i = 0 ; string[i] != 0x00 ; i++) 
-	string[i] = ebc8859[(int)string[i]]; 
-    string[i] = ebc8859[(int)string[i]]; 
-    return (i); 
-  } 
- 
-/* ------------------------------------------------------------- CHRETOA 
- * Translate an EBCDIC character into ASCII. 
- */ 
-int chretoa(unsigned int c) 
-  { 
-    c &= 0xFF; 
-    return asc8859[c]; 
-  } 
- 
-/* ------------------------------------------------------------- STRETOA 
- * Translate an EBCDIC string into ASCII in place. Return length. 
- */ 
-int stretoa(unsigned char *s) 
-  { 
-    int 	i; 
- 
-    for ( i = 0 ; s[i] != 0x00 ; i++ ) 
-	s[i] = asc8859[(int)s[i]]; 
-    s[i] = asc8859[(int)s[i]]; 
-    return i; 
-  } 
- 
- 
+/* ----------------------------------------------------------------- ÆCS
+ * ASCII to EBCDIC and vice-versa code conversion routines.
+ * Tables included here are based on ASCII conforming to the ISO8859-1
+ * Latin 1 character set and EBCDIC conforming to the IBM Code Page 37
+ * Latin 1 character set (except for three pairs of characters in 037).
+ * This C source requires header file AECS.H.
+ */
+
+#include "aecs.h"
+
+/* ------------------------------------------------------------- CHRATOE
+ * Translate an ASCII character into EBCDIC.
+ */
+int chratoe(unsigned int c)
+{
+    c &= 0xFF;
+    return (ebc8859[c]);
+}
+
+/* ------------------------------------------------------------- STRATOE
+ * Translate an ASCII string into EBCDIC in place. Return length.
+ */
+int stratoe(unsigned char *string)
+{
+    int	i;
+
+    for ( i = 0 ; string[i] != 0x00 ; i++)
+	string[i] = ebc8859[(int)string[i]];
+    string[i] = ebc8859[(int)string[i]];
+    return (i);
+}
+
+/* ------------------------------------------------------------- CHRETOA
+ * Translate an EBCDIC character into ASCII.
+ */
+int chretoa(unsigned int c)
+{
+    c &= 0xFF;
+    return asc8859[c];
+}
+
+/* ------------------------------------------------------------- STRETOA
+ * Translate an EBCDIC string into ASCII in place. Return length.
+ */
+int stretoa(unsigned char *s)
+{
+    int	i;
+
+    for ( i = 0 ; s[i] != 0x00 ; i++ )
+	s[i] = asc8859[(int)s[i]];
+    s[i] = asc8859[(int)s[i]];
+    return i;
+}
diff --git a/cmsfs.h b/cmsfs.h
index 9e93565..41b7dde 100644
--- a/cmsfs.h
+++ b/cmsfs.h
@@ -499,6 +499,10 @@ void cmsfs_xdump(unsigned char *,int);
  *  Function Prototypes used by the driver are presently              *
  *  all contained within one compilation unit.                        *
  * ------------------------------------------------------------------ */
+int cmsfsrd2(struct CMSINODE *inode,void *buffer,int block);
+int stretoa(unsigned char *string);
+int chretoa(unsigned int c);
+int chratoe(unsigned int c);
 
 /* ------------------------------------------------------------------ *
  *  Global Static (tough on radio reception, eh?)                     *
diff --git a/cmsfsany.c b/cmsfsany.c
index 18efffb..db95186 100644
--- a/cmsfsany.c
+++ b/cmsfsany.c
@@ -175,8 +175,7 @@ int cmsfs_find_label(struct CMSSUPER *vol,struct CMSFSADT *adt)
 int cmsfs_map_ADT(struct CMSSUPER *vol)
   {
     int         i,      /*  a counter  */
-                rc,     /*  a return code  */
-                bktry;  /*  a trial blocksize  */
+                rc;     /*  a return code  */
 
     /*  partial "ADT" structure (per IBM)  */
     static
@@ -604,8 +603,8 @@ void cmsfs_map_EXT(struct CMSINODE * fi)
     /*  step through the known types list,  looking for a match  */
     for (i = 0 ; fi->cmssuper->cmsfsext[i].ftype[0] != ' ' ; i++)
       {
-        if (strncmp(fi->ftype,
-            fi->cmssuper->cmsfsext[i].ftype,8) == 0x0000)
+          if (strncmp((char *)fi->ftype,
+                      (char *)fi->cmssuper->cmsfsext[i].ftype,8) == 0x0000)
           {
             fi->flags = fi->cmssuper->cmsfsext[i].flags;
 #ifdef  CMSFS_DEBUG
@@ -659,7 +658,7 @@ cmsfs_error(cmsfs_ermsg);
     if (rc != inode->cmssuper->blksz)
       {
         (void) sprintf((char*)cmsfs_ermsg,
-        "cmsfsrd2(): cmsfs_bread(,,%d,%d) returned %d",
+        "cmsfsrd2(): cmsfs_bread(,,%d,%ld) returned %d",
                         inode->origin-1+b1,inode->cmssuper->blksz,rc);
         cmsfs_error(cmsfs_ermsg);
         return rc;
@@ -690,7 +689,7 @@ cmsfs_error(cmsfs_ermsg);
         if (rc != inode->cmssuper->blksz)
           {
             (void) sprintf((char*)cmsfs_ermsg,
-            "cmsfsrd2(): cmsfs_bread(,,%d,%d) returned %d",
+            "cmsfsrd2(): cmsfs_bread(,,%d,%ld) returned %d",
                         inode->origin-1+b1,inode->cmssuper->blksz,rc);
             cmsfs_error(cmsfs_ermsg);
             return rc;
@@ -745,7 +744,7 @@ cmsfs_lookup(struct CMSINODE * di,unsigned char * fn)
       }
 
     /*  if we're opening the directory as a file, then ...  */
-    if (strncmp(fn,".dir",4) == 0)
+    if (strncmp((char *)fn,".dir",4) == 0)
       {
 #ifdef  CMSFS_DEBUG
         (void) cmsfs_error(
@@ -826,7 +825,7 @@ static  unsigned char buff[4096];
           }
         pp = &buff[j*di->cmssuper->fstsz];
         /*  compare  */
-        rc = strncmp(pp,umatch,16);
+        rc = strncmp((char *)pp,(char *)umatch,16);
         if (rc == 0)    /*  found it??  */
           {
             /*  map the inode for the file  */
@@ -976,7 +975,7 @@ cmsfs_error(cmsfs_ermsg);
     if (l > reclen)
       {
         (void) sprintf((char*)cmsfs_ermsg,
-            "cmsfs_read(): record (%d) is longer than buffer (%d)",
+            "cmsfs_read(): record (%d) is longer than buffer (%ld)",
             l,reclen);
         cmsfs_error(cmsfs_ermsg);
 /* ADDED FOR DIAGNOSTICS */
diff --git a/cmsfscat.c b/cmsfscat.c
index 0d03f83..c9df55e 100644
--- a/cmsfscat.c
+++ b/cmsfscat.c
@@ -22,6 +22,7 @@
 
 #include        <stdlib.h>
 #include        <stdio.h>
+#include        <unistd.h>
 /* cheezy way to get time_t def'd */
 #include        <utime.h>
 
@@ -30,17 +31,17 @@
 #define  USAGE  "Usage: %s [ -d cmsvol ] [ -a | -i ] cmsfile [cmsfile ...]\n"
 
 /* ------------------------------------------------------------------ */
-int main(int argc,unsigned char *argv[])
+int main(int argc,char *argv[])
   {
-    int         i, rc, j, k, l, catflags;
-    unsigned char *devname, *filename;
+    int         i, rc, catflags;
+    char        *devname, *filename;
     unsigned  char  *buffer;
 
     struct  CMSINODE  *cmsfile;         /*  CMS file handle  */
     int         buflen;
 
     /*  default empty strings  */
-    devname = filename = (unsigned char *) "";
+    devname = filename = (char *) "";
     /*  DRAT COMPILERS THAT DON'T GROK UNSIGNED CHAR!  */
     catflags = CMSFSANY;
 
@@ -91,7 +92,8 @@ int main(int argc,unsigned char *argv[])
         filename = argv[i];
 
         /*  open the source file (CMS file)  */
-        cmsfile = cmsfs_open(filename,catflags,devname);
+        cmsfile = cmsfs_open((unsigned char *)filename,catflags,
+                             (unsigned char *)devname);
         if (cmsfile == NULL) return -1;
 
         /*  allocate a buffer to hold the largest possible  "record"  */
diff --git a/cmsfsck.c b/cmsfsck.c
index a4d3f38..5cc7972 100644
--- a/cmsfsck.c
+++ b/cmsfsck.c
@@ -17,9 +17,9 @@
 
 #define  USAGE  "Usage: %s cmsvol [ cmsvol ... ] \n"
 
-int main(int argc,unsigned char *argv[])
+int main(int argc,char *argv[])
   {
-    int         i, j, k, rc, percent;
+    int         i, rc;
     struct  CMSSUPER  *tempvols;
 
     /*  process options  */
@@ -55,7 +55,7 @@ int main(int argc,unsigned char *argv[])
     while (i < argc)
       {
         /*  'mount'  it to validate the ADT and directory FST  */
-        tempvols = cmsfs_vopen(argv[i]);
+          tempvols = cmsfs_vopen((unsigned char *)argv[i]);
         if (tempvols == NULL)
           {
             (void) fprintf(stderr,"'%s' is not a CMS volume.\n",argv[i]);
diff --git a/cmsfscp.c b/cmsfscp.c
index c6035b0..b8ffa75 100644
--- a/cmsfscp.c
+++ b/cmsfscp.c
@@ -28,12 +28,13 @@
 #include        <sys/stat.h>
 #include        <stdio.h>
 #include        <string.h>
+#include        <unistd.h>
 
 #include        "cmsfs.h"
 
 #define  USAGE  "Usage: %s [ -d cmsvol ] [ -a | -i ] cmsfile unixfile\n"
 
-int main(int argc,unsigned char *argv[])
+int main(int argc,char *argv[])
   {
     struct  utimbuf  stdtime;
     struct  CMSINODE  *cmsfile;         /*  CMS file handle  */
@@ -61,7 +62,7 @@ int main(int argc,unsigned char *argv[])
         (void) fprintf(stderr,USAGE,argv[0]);
                         return 0;
             case 'd':
-            case 'f':   devname = argv[++i] ;
+              case 'f':   devname = (unsigned char *)argv[++i] ;
                         break;
             case 'a':   /* ASCII (plain text) */
                         cmsflags |= CMSFSTXT;
@@ -101,7 +102,7 @@ int main(int argc,unsigned char *argv[])
 
     /*  target practice:  if more than three args,
         then the last arg (the "target") must be a directory  */
-    target = argv[argc-1];
+    target = (unsigned char *)argv[argc-1];
     rc = stat((char*)target,&targstat);
 
     /*  if stat() failed,  then file probably does not exist,
@@ -118,7 +119,7 @@ int main(int argc,unsigned char *argv[])
     /*  for each source file ...  */
     for ( ; i < argl ; i++ )
       {
-        source = argv[i];
+          source = (unsigned char *)argv[i];
 
         /*  open the source file (CMS file)  */
         cmsfile = cmsfs_open(source,cmsflags,devname);
@@ -135,7 +136,7 @@ int main(int argc,unsigned char *argv[])
                 _bname++;
               }
             if (*sbname == '/') sbname++;
-            if (strlen(target) + strlen(sbname) > 254)
+            if (strlen((char *)target) + strlen((char *)sbname) > 254)
               {
                 (void) fprintf(stderr,"filename too long\n");
                 return -1;
@@ -144,7 +145,7 @@ int main(int argc,unsigned char *argv[])
           }
         else
           {
-            if (strlen(target) > 255)
+            if (strlen((char *)target) > 255)
               {
                 (void) fprintf(stderr,"filename too long\n");
                 return -1;
diff --git a/cmsfsext.c b/cmsfsext.c
index a4812d7..556af07 100644
--- a/cmsfsext.c
+++ b/cmsfsext.c
@@ -1,7 +1,7 @@
 /*
  *
  *        Name: cmsfsext.c
- *		CMS FS file EXTensions table 
+ *		CMS FS file EXTensions table
  *      Author: Rick Troth, BMC Software, Inc., Houston, Texas, USA
  *        Date: 2000-Sep-10 (Sun)
  *
@@ -14,20 +14,20 @@
  *              by Rick Troth for the CMS FS util/driver.
  *              The table is ultimately replaceable via ioctl().
  *
- *		See cmsfs.h for constants, typically one of 
- *		CMSFSTXT, CMSFSBIN, or CMSFSRAW. 
+ *		See cmsfs.h for constants, typically one of
+ *		CMSFSTXT, CMSFSBIN, or CMSFSRAW.
  */
- 
- 
-/* cheezy way to get time def'ns in cmsfs.h to work */ 
-#include	<time.h> 
-/* cheezy way to get time ssize_t in cmsfs.h to work */ 
-#include	<fcntl.h> 
- 
-#include	"cmsfs.h" 
- 
-    struct CMSFSEXT cmsfsext[] = { 
- 
+
+
+/* cheezy way to get time def'ns in cmsfs.h to work */
+#include	<time.h>
+/* cheezy way to get time ssize_t in cmsfs.h to work */
+#include	<fcntl.h>
+
+#include	"cmsfs.h"
+
+struct CMSFSEXT cmsfsext[] = {
+
 /*  Well-known ASCII (plain text) file extensions  */
 /* text files */
   "TXT     ", CMSFSTXT,
@@ -103,7 +103,7 @@
   "VCF     ", CMSFSTXT,         /*  VCard  */
   "VCARD   ", CMSFSTXT,
   "SYNONYM ", CMSFSTXT,
- 
+
 /*  Well-known IMAGE (binary) file extensions  */
   "BIN     ", CMSFSBIN,
   "EXE     ", CMSFSBIN,
@@ -132,16 +132,14 @@
   "TGZ     ", CMSFSBIN,
   "PGP     ", CMSFSBIN,
   "RPM     ", CMSFSBIN,
- 
+
 /*  Well-known record-oriented file extensions  */
   "LIST3820", CMSFSRAW,
   "MODULE  ", CMSFSRAW,
   "LOADLIB ", CMSFSRAW,
- 
-/* the terminator */ 
+
+/* the terminator */
   "ALLOCMAP", CMSFSBIN,
-  "DIRECTOR", CMSFSBIN		/*  better be F 64  */ 
- 
-		} ; 
- 
- 
+  "DIRECTOR", CMSFSBIN		/*  better be F 64  */
+
+} ;
diff --git a/cmsfslst.c b/cmsfslst.c
index 4c38ab8..9ad1246 100644
--- a/cmsfslst.c
+++ b/cmsfslst.c
@@ -15,16 +15,16 @@
 #define  USAGE  "Usage: %s -d cmsvol\n"
 
 /* ------------------------------------------------------------------ */
-int main(int argc,unsigned char *argv[])
+int main(int argc,char *argv[])
   {
-    int         i, j, k, rc, percent;
-    unsigned char  *devname;
+    int         i, j, k, rc;
+    char  *devname;
     struct  CMSSUPER  *tempvols;
     struct  CMSINODE  *dirinode, tmpinode;
     struct tm *ftime;
 
     /*  default empty strings  */
-    devname = (unsigned char *) "";
+    devname = (char *) "";
 
     /*  process options  */
     for (i = 1 ; i < argc && argv[i][0] == '-' ; i++)
@@ -57,7 +57,7 @@ int main(int argc,unsigned char *argv[])
       }
 
     /*  open the volume  */
-    tempvols = cmsfs_vopen(devname);
+    tempvols = cmsfs_vopen((unsigned char *)devname);
     if (tempvols == NULL) return -1;
 
     /*  report on the volume  */
@@ -80,7 +80,7 @@ BLKSZ   FILES  BLKS USED-(%) BLKS LEFT  BLK TOTAL\n");
     if (dirinode->items != tempvols->files)
       {
         (void) fprintf(stderr,
-            "corrupted filesystem; #files (%d) != #dir items (%d)\n",
+            "corrupted filesystem; #files (%ld) != #dir items (%d)\n",
             tempvols->files,dirinode->items);
         (void) cmsfs_fclose(dirinode);
         (void) cmsfs_vclose(tempvols);
diff --git a/cmsfsusa.c b/cmsfsusa.c
index f2299e8..4649745 100644
--- a/cmsfsusa.c
+++ b/cmsfsusa.c
@@ -14,8 +14,10 @@
 #include        <time.h>
 #include        <stdio.h>
 #include        <fcntl.h>
+#include        <unistd.h>
 #include        <errno.h>
 #include        <string.h>
+#include        <ctype.h>
 
 #include        "cmsfs.h"
 /* #include     "aecs.h" */
@@ -274,8 +276,6 @@ cmsfs_fopen(unsigned char * fn,struct CMSSUPER * cmssuper,int flag)
     int         rc, i, j, k;
     struct  CMSINODE  *cmsinode;
     unsigned char  umatch[18], xmatch[18], *p;
-    struct  CMSFSFST  cmsfst;   /*  "FST" structure (per IBM)  */
-    int         start;
 
     /*  utility mode "file open" operation  */
 #ifdef  CMSFS_DEBUG
@@ -313,7 +313,7 @@ cmsfs_fopen(unsigned char * fn,struct CMSSUPER * cmssuper,int flag)
       }
 
     /*  if we're opening the directory as a file, then ...  */
-    if (strncmp(fn,".dir",4) == 0)
+    if (strncmp((char *)fn,".dir",4) == 0)
       {
 #ifdef  CMSFS_DEBUG
         cmsfs_error(
@@ -412,7 +412,7 @@ cmsfs_fopen(unsigned char * fn,struct CMSSUPER * cmssuper,int flag)
           }
         pp = &buff[j*cmssuper->fstsz];
         /*  compare  */
-        rc = strncmp(pp,umatch,16);
+        rc = strncmp((char *)pp,(char *)umatch,16);
         if (rc == 0)    /*  found it??  */
           {
             /*  map the inode for the file  */
@@ -489,7 +489,7 @@ struct CMSINODE * cmsfs_open(unsigned char * filepath,int flag,
     vn = (unsigned char*) dn;
 
     /*  allocate a work buffer for volid & fileid parsing  */
-    filetemp = cmsfs_malloc(strlen(filepath)+1);
+    filetemp = cmsfs_malloc(strlen((char *)filepath)+1);
     if (filetemp == NULL) return NULL;
 
     /*  copy the string,  looking for slashes  (std path delim)  */
@@ -589,23 +589,23 @@ void cmsfs_xdump(unsigned char *p,int l)
                 (char*)q,"%02X%02X%02X%02X %02X%02X%02X%02X ",
                 p[i]&0xFF,p[i+1]&0xFF,p[i+2]&0xFF,p[i+3]&0xFF,
                 p[i+4]&0xFF,p[i+5]&0xFF,p[i+6]&0xFF,p[i+7]&0xFF);
-        i += 8;  q += strlen(cmsfs_ermsg);
+        i += 8;  q += strlen((char *)cmsfs_ermsg);
         (void) sprintf(
                 (char*)q,"%02X%02X%02X%02X %02X%02X%02X%02X  ",
                 p[i]&0xFF,p[i+1]&0xFF,p[i+2]&0xFF,p[i+3]&0xFF,
                 p[i+4]&0xFF,p[i+5]&0xFF,p[i+6]&0xFF,p[i+7]&0xFF);
-        i += 8;  q += strlen(cmsfs_ermsg);
+        i += 8;  q += strlen((char *)cmsfs_ermsg);
 
         (void) sprintf(
                 (char*)q,"%02X%02X%02X%02X %02X%02X%02X%02X ",
                 p[i]&0xFF,p[i+1]&0xFF,p[i+2]&0xFF,p[i+3]&0xFF,
                 p[i+4]&0xFF,p[i+5]&0xFF,p[i+6]&0xFF,p[i+7]&0xFF);
-        i += 8;  q += strlen(cmsfs_ermsg);
+        i += 8;  q += strlen((char *)cmsfs_ermsg);
         (void) sprintf(
                 (char*)q,"%02X%02X%02X%02X %02X%02X%02X%02X",
                 p[i]&0xFF,p[i+1]&0xFF,p[i+2]&0xFF,p[i+3]&0xFF,
                 p[i+4]&0xFF,p[i+5]&0xFF,p[i+6]&0xFF,p[i+7]&0xFF);
-        i += 8;  q += strlen(cmsfs_ermsg);
+        i += 8;  q += strlen((char *)cmsfs_ermsg);
 
         cmsfs_error(cmsfs_ermsg);
       }
diff --git a/cmsfsvol.c b/cmsfsvol.c
index a2d3481..3971100 100644
--- a/cmsfsvol.c
+++ b/cmsfsvol.c
@@ -15,12 +15,10 @@
 #define  USAGE  "Usage: %s [ -d ] cmsvol [cmsvol ...]\n"
 
 /* ------------------------------------------------------------------ */
-int main(int argc,unsigned char *argv[])
+int main(int argc,char *argv[])
   {
     int         i, percent;
     struct  CMSSUPER  *tempvols;
-    struct  CMSINODE  dirinode, tmpinode;
-    struct tm *ftime;
 
     /*  process options  */
     for (i = 1 ; i < argc && argv[i][0] == '-' ; i++)
@@ -57,7 +55,7 @@ BLKSZ   FILES  BLKS USED-(%%) BLKS LEFT  BLK TOTAL\n");
     for (      ; i < argc ; i++)
       {
         /*  open the volume  */
-        tempvols = cmsfs_vopen(argv[i]);
+        tempvols = cmsfs_vopen((unsigned char *)argv[i]);
         if (tempvols == NULL)
           {
             (void) fprintf(stderr,"'%s' is not a CMS volume.\n",argv[i]);
@@ -66,8 +64,8 @@ BLKSZ   FILES  BLKS USED-(%%) BLKS LEFT  BLK TOTAL\n");
 
         /*  report on the volume  */
         percent = ( tempvols->bkused * 100 ) / tempvols->blocks;
-        (void) printf("%-6s .... ... R/O %5d .... %4d %8d %10d-%02d %10d \
-%10d\n",tempvols->volid,tempvols->ncyls,tempvols->blksz,tempvols->files,
+        (void) printf("%-6s .... ... R/O %5d .... %4ld %8ld %10ld-%02d %10ld \
+%10ld\n",tempvols->volid,tempvols->ncyls,tempvols->blksz,tempvols->files,
 tempvols->bkused,percent,tempvols->bkfree,tempvols->blocks);
 
         /*  close the volume  */
-- 
1.8.1.4

