Staging: Fixed coding style issues
PATCH 2/2 Staging: Fixed coding style issues
From: Hatim Muhammed <[email protected]>
Signed-off-by Hatim Muhammed <[email protected]>
Removed unneccessary spaces
Use (unsigned int) instead of plain (int) conversions Removed assignments inside if conditions
--- usr/gen_init_cpio.c | 97 +++++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 47 deletions(-)
usr/gen_init_cpio.c +50 -47
@@ -39,7 +39,7 @@ static void push_string(const char *name) offset += name_len; } -static void push_pad (void ) +static void push_pad (void ) {while (offset &3 ) {putchar (0 );
@@ -73,23 +73,22 @@ static void push_hdr(const char *s)static void cpio_trailer (void ) {char s[256 ]; -const char name[] ="TRAILER!!!" ; +static const char name[] ="TRAILER!!!" ; -sprintf (s,"%s%08X%08X%08lX%08lX%08X%08lX" -"%08X%08X%08X%08X%08X%08X%08X" , +sprintf (s,"%s%08X%08X%08lX%08lX%08X%08lX%08X%08X%08X%08X%08X%08X%08X" ,"070701" ,/* magic */ 0 ,/* ino */ 0 ,/* mode */ - (long )0 ,/* uid */ - (long )0 ,/* gid */ +0L ,/* uid */ +0L ,/* gid */ 1 ,/* nlink */ - (long )0 ,/* mtime */ +0L ,/* mtime */ 0 ,/* filesize */ 0 ,/* major */ 0 ,/* minor */ 0 ,/* rmajor */ 0 ,/* rminor */ - (unsigned )strlen (name)+1 ,/* namesize */ + (unsigned int )strlen (name)+1 ,/* namesize */ 0 );/* chksum */ push_hdr (s);push_rest (name);
@@ -107,8 +106,7 @@ static int cpio_mkslink(const char *name, const char *target,if (name[0 ] =='/' ) name++; - sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX" - "%08X%08X%08X%08X%08X%08X%08X", + sprintf(s, "%s%08X%08X%08lX%08lX%08X%08lX%08X%08X%08X%08X%08X%08X%08X", "070701", /* magic */ ino++, /* ino */ S_IFLNK | mode, /* mode */
@@ -116,12 +114,12 @@ static int cpio_mkslink(const char *name, const char *target, (long ) gid,/* gid */ 1 ,/* nlink */ (long ) default_mtime,/* mtime */ - (unsigned )strlen (target)+1 ,/* filesize */ + (unsigned int )strlen (target)+1 ,/* filesize */ 3 ,/* major */ 1 ,/* minor */ 0 ,/* rmajor */ 0 ,/* rminor */ - (unsigned )strlen (name) +1 ,/* namesize */ + (unsigned int )strlen (name) +1 ,/* namesize */ 0); /* chksum */push_hdr (s);push_string (name);
@@ -140,7 +138,7 @@ static int cpio_mkslink_line(const char *line)int gid;int rc =-1 ; - if (5 != sscanf(line, "%" str(PATH_MAX) "s %" str(PATH_MAX) "s %o %d %d", name, target, &mode, &uid, &gid)) { + if (sscanf(line, "%" str(PATH_MAX) "s %" str(PATH_MAX) "s %o %d %d", name, target, &mode, &uid, &gid) != 5) { fprintf(stderr, "Unrecognized dir format '%s'", line); goto fail; }
@@ -156,8 +154,7 @@ static int cpio_mkgeneric(const char *name, unsigned int mode,if (name[0 ] =='/' ) name++; - sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX" - "%08X%08X%08X%08X%08X%08X%08X", + sprintf(s, "%s%08X%08X%08lX%08lX%08X%08lX%08X%08X%08X%08X%08X%08X%08X", "070701", /* magic */ ino++, /* ino */ mode, /* mode */
@@ -170,7 +167,7 @@ static int cpio_mkgeneric(const char *name, unsigned int mode,1 ,/* minor */ 0 ,/* rmajor */ 0 ,/* rminor */ - (unsigned )strlen (name) +1 ,/* namesize */ + (unsigned int )strlen (name) +1 ,/* namesize */ 0); /* chksum */push_hdr (s);push_rest (name);
@@ -211,7 +208,7 @@ static int cpio_mkgeneric_line(const char *line, enum generic_types gt)int gid;int rc =-1 ; - if (4 != sscanf(line, "%" str(PATH_MAX) "s %o %d %d", name, &mode, &uid, &gid)) { + if (sscanf(line, "%" str(PATH_MAX) "s %o %d %d", name, &mode, &uid, &gid) != 4) {fprintf (stderr,"Unrecognized %s format '%s'" , line, generic_type_table[gt].type); goto fail;
@@ -250,8 +247,7 @@ static int cpio_mknod(const char *name, unsigned int mode,if (name[0 ] =='/' ) name++; - sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX" - "%08X%08X%08X%08X%08X%08X%08X", + sprintf(s, "%s%08X%08X%08lX%08lX%08X%08lX%08X%08X%08X%08X%08X%08X%08X", "070701", /* magic */ ino++, /* ino */ mode, /* mode */
@@ -264,7 +260,7 @@ static int cpio_mknod(const char *name, unsigned int mode,1 ,/* minor */ maj,/* rmajor */ min,/* rminor */ - (unsigned )strlen (name) +1 ,/* namesize */ + (unsigned int )strlen (name) +1 ,/* namesize */ 0); /* chksum */push_hdr (s);push_rest (name);
@@ -282,8 +278,8 @@ static int cpio_mknod_line(const char *line)unsigned int min;int rc =-1 ; - if (7 != sscanf(line, "%" str(PATH_MAX) "s %o %d %d %c %u %u", - name, &mode, &uid, &gid, &dev_type, &maj, &min)) { + if (sscanf(line, "%" str(PATH_MAX) "s %o %d %d %c %u %u", + name, &mode, &uid, &gid, &dev_type, &maj, &min) !=7 ) {fprintf (stderr,"Unrecognized nod format '%s'" , line); goto fail; }
@@ -308,9 +304,9 @@ static int cpio_mkfile(const char *name, const char *location, mode |=S_IFREG ; - file =open (location,O_RDONLY ); + file =open (location,O_RDONLY );if (file <0 ) { -fprintf (stderr,"File %s could not be opened for reading\n" , location); +fprintf (stderr,"File %s could not be opened for reading\n" , location); goto error; }
@@ -328,26 +324,26 @@ static int cpio_mkfile(const char *name, const char *location, filebuf =malloc (buf.st_size);if (!filebuf) { -fprintf (stderr,"out of memory\n" ); +fprintf (stderr,"out of memory\n" ); goto error; } - retval =read (file, filebuf, buf.st_size); + retval =read (file, filebuf, buf.st_size);if (retval <0 ) { -fprintf (stderr,"Can not read %s file\n" , location); +fprintf (stderr,"Can not read %s file\n" , location); goto error; } size =0 ;for (i =1 ; i <= nlinks; i++) {/* data goes on last link */ -if (i == nlinks) size = buf.st_size; +if (i == nlinks) + size = buf.st_size;if (name[0 ] =='/' ) name++; namesize =strlen (name) +1 ; - sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX" - "%08lX%08X%08X%08X%08X%08X%08X", + sprintf(s, "%s%08X%08X%08lX%08lX%08X%08lX%08lX%08X%08X%08X%08X%08X%08X", "070701", /* magic */ ino, /* ino */ mode, /* mode */
@@ -379,10 +375,12 @@ static int cpio_mkfile(const char *name, const char *location, } ino++; rc =0 ; - + error: -if (filebuf)free (filebuf); -if (file >=0 )close (file); +if (filebuf) +free (filebuf); +if (file >=0 ) +close (file);return rc; }
@@ -395,7 +393,7 @@ static char *cpio_replace_env(char *new_location) (end = strchr(start + 2, '}'))) { *start = *end =0 ; var =getenv (start +2 ); -snprintf (expanded,sizeof expanded,"%s%s%s" , +snprintf (expanded,sizeof (expanded),"%s%s%s" , new_location, var ? var :"" , end +1 );strcpy (new_location, expanded); }
@@ -415,9 +413,9 @@ static int cpio_mkfile_line(const char *line)int end =0 , dname_len =0 ;int rc =-1 ; - if (5 > sscanf(line, "%" str(PATH_MAX) "s %" str(PATH_MAX) + if (sscanf(line, "%" str(PATH_MAX) "s %" str(PATH_MAX) "s %o %d %d %n", - name, location, &mode, &uid, &gid, &end)) { + name, location, &mode, &uid, &gid, &end) <5 ) {fprintf (stderr,"Unrecognized file format '%s'" , line); goto fail; }
@@ -427,7 +425,7 @@ static int cpio_mkfile_line(const char *line) dname =malloc (strlen (line));if (!dname) { -fprintf (stderr,"out of memory (%d)\n" , dname_len); +fprintf (stderr,"out of memory (%d)\n" , dname_len); goto fail; }
@@ -449,9 +447,10 @@ static int cpio_mkfile_line(const char *line) dname = name; } rc =cpio_mkfile (dname,cpio_replace_env (location), - mode, uid, gid, nlinks); + mode, uid, gid, nlinks); fail: -if (dname_len)free (dname); +if (dname_len) +free (dname);return rc; }
@@ -524,7 +523,7 @@ static const struct file_handler file_handler_table[] = {#define LINE_SIZE (2 * PATH_MAX + 50) -int main (int argc,char *argv[]) +int main (int argc,char *argv[]) {FILE *cpio_list;char line[LINE_SIZE ];
@@ -572,9 +571,10 @@ int main (int argc, char *argv[])exit (1 ); } filename = argv[optind]; + cpio_list =fopen (filename,"r" );if (!strcmp (filename,"-" )) cpio_list = stdin; -else if (!(cpio_list =fopen (filename,"r" ))) { +else if (!cpio_list) {fprintf (stderr,"ERROR: unable to open '%s': %s\n\n" , filename,strerror (errno));usage (argv[0 ]);
@@ -591,8 +591,8 @@ int main (int argc, char *argv[])/* comment - skip to next line */ continue ; } - -if (! (type =strtok (line," \t" ))) { + type =strtok (line," \t" ); +if (!type) {fprintf (stderr,"ERROR: incorrect format, could not locate file type line %d: '%s'\n" , line_nr, line);
@@ -610,7 +610,8 @@ int main (int argc, char *argv[])continue ; } -if (! (args =strtok (NULL ,"\n" ))) { + args =strtok (NULL ,"\n" ); +if (!args) {fprintf (stderr,"ERROR: incorrect format, newline required line %d: '%s'\n" , line_nr, line);
@@ -619,8 +620,10 @@ int main (int argc, char *argv[])for (type_idx =0 ; file_handler_table[type_idx].type; type_idx++) {int rc; -if (!strcmp (line, file_handler_table[type_idx].type)) { -if ((rc = file_handler_table[type_idx].handler (args))) { + +if (!strcmp (line, file_handler_table[type_idx].type)) { + rc = file_handler_table[type_idx].handler (args); +if (rc) { ec = rc;fprintf (stderr," line %d\n" , line_nr); }
@@ -628,7 +631,7 @@ int main (int argc, char *argv[]) } } -if (NULL == file_handler_table[type_idx].type) { +if (file_handler_table[type_idx].type ==NULL ) {fprintf (stderr,"unknown file type line %d: '%s'\n" , line_nr, line); }
Signature · 1 line
2.35.1