svn commit: r358777 - stable/12/contrib/elftoolchain/strings

Ed Maste emaste at FreeBSD.org
Sun Mar 8 20:09:21 UTC 2020


Author: emaste
Date: Sun Mar  8 20:09:19 2020
New Revision: 358777
URL: https://svnweb.freebsd.org/changeset/base/358777

Log:
  MFC r340746, r340750 (oshogbo): strings: fix style nits

Modified:
  stable/12/contrib/elftoolchain/strings/strings.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/contrib/elftoolchain/strings/strings.c
==============================================================================
--- stable/12/contrib/elftoolchain/strings/strings.c	Sun Mar  8 20:05:34 2020	(r358776)
+++ stable/12/contrib/elftoolchain/strings/strings.c	Sun Mar  8 20:09:19 2020	(r358777)
@@ -24,8 +24,8 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/stat.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 
 #include <ctype.h>
 #include <err.h>
@@ -64,7 +64,7 @@ enum encoding_style {
 };
 
 #define PRINTABLE(c)						\
-      ((c) >= 0 && (c) <= 255 && 				\
+      ((c) >= 0 && (c) <= 255 &&				\
 	  ((c) == '\t' || isprint((c)) ||			\
 	      (encoding == ENCODING_8BIT && (c) > 127)))
 
@@ -109,8 +109,8 @@ main(int argc, char **argv)
 		    elf_errmsg(-1));
 
 	while ((ch = getopt_long(argc, argv, "1234567890ae:fhn:ot:Vv",
-	    strings_longopts, NULL)) != -1)
-		switch((char)ch) {
+	    strings_longopts, NULL)) != -1) {
+		switch ((char)ch) {
 		case 'a':
 			entire_file = 1;
 			break;
@@ -183,14 +183,15 @@ main(int argc, char **argv)
 			usage();
 			/* NOTREACHED */
 		}
+	}
 	argc -= optind;
 	argv += optind;
 
-	if (!min_len)
+	if (min_len == 0)
 		min_len = 4;
-	if (!*argv)
+	if (*argv == NULL)
 		rc = find_strings("{standard input}", 0, 0);
-	else while (*argv) {
+	else while (*argv != NULL) {
 		if (handle_file(*argv) != 0)
 			rc = 1;
 		argv++;
@@ -226,10 +227,10 @@ handle_binary(const char *name, int fd)
 {
 	struct stat buf;
 
-	memset(&buf, 0, sizeof(struct stat));
-	(void) lseek(fd, (off_t)0, SEEK_SET);
+	memset(&buf, 0, sizeof(buf));
+	(void)lseek(fd, 0, SEEK_SET);
 	if (!fstat(fd, &buf))
-		return (find_strings(name, (off_t)0, buf.st_size));
+		return (find_strings(name, 0, buf.st_size));
 	return (1);
 }
 
@@ -253,21 +254,21 @@ handle_elf(const char *name, int fd)
 	if (entire_file)
 		return (handle_binary(name, fd));
 
-	(void) lseek(fd, (off_t)0, SEEK_SET);
+	(void)lseek(fd, 0, SEEK_SET);
 	elf = elf_begin(fd, ELF_C_READ, NULL);
 	if (elf_kind(elf) != ELF_K_ELF) {
-		(void) elf_end(elf);
+		(void)elf_end(elf);
 		return (handle_binary(name, fd));
 	}
 
 	if (gelf_getehdr(elf, &elfhdr) == NULL) {
-		(void) elf_end(elf);
+		(void)elf_end(elf);
 		warnx("%s: ELF file could not be processed", name);
 		return (1);
 	}
 
 	if (elfhdr.e_shnum == 0 && elfhdr.e_type == ET_CORE) {
-		(void) elf_end(elf);
+		(void)elf_end(elf);
 		return (handle_binary(name, fd));
 	} else {
 		scn = NULL;
@@ -281,7 +282,7 @@ handle_elf(const char *name, int fd)
 			}
 		}
 	}
-	(void) elf_end(elf);
+	(void)elf_end(elf);
 	return (rc);
 }
 
@@ -304,7 +305,7 @@ getcharacter(void)
 		buf[i] = c;
 	}
 
-	switch(encoding) {
+	switch (encoding) {
 	case ENCODING_7BIT:
 	case ENCODING_8BIT:
 		rt = buf[0];
@@ -317,12 +318,12 @@ getcharacter(void)
 		 break;
 	case ENCODING_32BIT_BIG:
 		rt = ((long) buf[0] << 24) | ((long) buf[1] << 16) |
-           	    ((long) buf[2] << 8) | buf[3];
-           	break;
+		    ((long) buf[2] << 8) | buf[3];
+		break;
 	case ENCODING_32BIT_LITTLE:
 		rt = buf[0] | ((long) buf[1] << 8) | ((long) buf[2] << 16) |
-        	    ((long) buf[3] << 24);
-           	break;
+		    ((long) buf[3] << 24);
+		break;
 	}
 	return (rt);
 }
@@ -341,63 +342,60 @@ find_strings(const char *name, off_t offset, off_t siz
 	int i;
 
 	if ((obuf = (char*)calloc(1, min_len + 1)) == NULL) {
-		(void) fprintf(stderr, "Unable to allocate memory: %s\n",
-		     strerror(errno));
+		fprintf(stderr, "Unable to allocate memory: %s\n",
+		    strerror(errno));
 		return (1);
 	}
 
-	(void) fseeko(stdin, offset, SEEK_SET);
+	(void)fseeko(stdin, offset, SEEK_SET);
 	cur_off = offset;
 	start_off = 0;
-	while(1) {
+	for (;;) {
 		if ((offset + size) && (cur_off >= offset + size))
 			break;
 		start_off = cur_off;
-		memset(obuf, 0, min_len+1);
+		memset(obuf, 0, min_len + 1);
 		for(i = 0; i < min_len; i++) {
 			c = getcharacter();
 			if (c == EOF && feof(stdin))
 				goto _exit1;
-		 	if (PRINTABLE(c)) {
-		 		obuf[i] = c;
-		 		obuf[i+1] = 0;
-		 		cur_off += encoding_size;
-		 	} else {
+			if (PRINTABLE(c)) {
+				obuf[i] = c;
+				obuf[i + 1] = 0;
+				cur_off += encoding_size;
+			} else {
 				if (encoding == ENCODING_8BIT &&
 				    (uint8_t)c > 127) {
-			 		obuf[i] = c;
-			 		obuf[i+1] = 0;
-			 		cur_off += encoding_size;
-			 		continue;
-			 	}
-	 			cur_off += encoding_size;
-	 			break;
-		 	}
+					obuf[i] = c;
+					obuf[i + 1] = 0;
+					cur_off += encoding_size;
+					continue;
+				}
+				cur_off += encoding_size;
+				break;
+			}
 		}
 
 		if (i >= min_len && ((cur_off <= offset + size) ||
 		    !(offset + size))) {
 			if (show_filename)
-				printf ("%s: ", name);
+				printf("%s: ", name);
 			if (show_loc) {
-				switch(radix) {
+				switch (radix) {
 				case RADIX_DECIMAL:
-					(void) printf("%7ju ",
-					    (uintmax_t)start_off);
+					printf("%7ju ", (uintmax_t)start_off);
 					break;
 				case RADIX_HEX:
-					(void) printf("%7jx ",
-					    (uintmax_t)start_off);
+					printf("%7jx ", (uintmax_t)start_off);
 					break;
 				case RADIX_OCTAL:
-					(void) printf("%7jo ",
-					    (uintmax_t)start_off);
+					printf("%7jo ", (uintmax_t)start_off);
 					break;
 				}
 			}
 			printf("%s", obuf);
 
-			while(1) {
+			for (;;) {
 				if ((offset + size) &&
 				    (cur_off >= offset + size))
 					break;
@@ -405,9 +403,9 @@ find_strings(const char *name, off_t offset, off_t siz
 				cur_off += encoding_size;
 				if (encoding == ENCODING_8BIT &&
 				    (uint8_t)c > 127) {
-			 		putchar(c);
-			 		continue;
-			 	}
+					putchar(c);
+					continue;
+				}
 				if (!PRINTABLE(c) || c == EOF)
 					break;
 				putchar(c);
@@ -436,13 +434,15 @@ Usage: %s [options] [file...]\n\
 void
 usage(void)
 {
-	(void) fprintf(stderr, USAGE_MESSAGE, ELFTC_GETPROGNAME());
+
+	fprintf(stderr, USAGE_MESSAGE, ELFTC_GETPROGNAME());
 	exit(EXIT_FAILURE);
 }
 
 void
 show_version(void)
 {
-        (void) printf("%s (%s)\n", ELFTC_GETPROGNAME(), elftc_version());
+
+        printf("%s (%s)\n", ELFTC_GETPROGNAME(), elftc_version());
         exit(EXIT_SUCCESS);
 }


More information about the svn-src-all mailing list