public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCHv5 1/7] mkenvimage: correct and clarify comments and error messages
@ 2012-01-13 23:27 David Wagner
  2012-01-13 23:27 ` [U-Boot] [PATCHv5 2/7] mkenvimage: Correct an include and add a missing one David Wagner
                   ` (7 more replies)
  0 siblings, 8 replies; 24+ messages in thread
From: David Wagner @ 2012-01-13 23:27 UTC (permalink / raw)
  To: u-boot

Also, don't split error messages over several lines as per a coding style
exception making them easier to grep.

Signed-off-by: David Wagner <david.wagner@free-electrons.com>
---
 tools/mkenvimage.c |   41 +++++++++++++++--------------------------
 1 files changed, 15 insertions(+), 26 deletions(-)

diff --git a/tools/mkenvimage.c b/tools/mkenvimage.c
index f781731..c95f7f5 100644
--- a/tools/mkenvimage.c
+++ b/tools/mkenvimage.c
@@ -45,12 +45,9 @@
 
 static void usage(const char *exec_name)
 {
-	fprintf(stderr, "%s [-h] [-r] [-b] [-p <byte>] "
-	       "-s <environment partition size> -o <output> <input file>\n"
+	fprintf(stderr, "%s [-h] [-r] [-b] [-p <byte>] -s <environment partition size> -o <output> <input file>\n"
 	       "\n"
-	       "This tool takes a key=value input file (same as would a "
-	       "`printenv' show) and generates the corresponding environment "
-	       "image, ready to be flashed.\n"
+	       "This tool takes a key=value input file (same as would a `printenv' show) and generates the corresponding environment image, ready to be flashed.\n"
 	       "\n"
 	       "\tThe input file is in format:\n"
 	       "\t\tkey1=value1\n"
@@ -58,8 +55,7 @@ static void usage(const char *exec_name)
 	       "\t\t...\n"
 	       "\t-r : the environment has multiple copies in flash\n"
 	       "\t-b : the target is big endian (default is little endian)\n"
-	       "\t-p <byte> : fill the image with <byte> bytes instead of "
-	       "0xff bytes\n"
+	       "\t-p <byte> : fill the image with <byte> bytes instead of 0xff bytes\n"
 	       "\t-V : print version information and exit\n"
 	       "\n"
 	       "If the input file is \"-\", data is read from standard input\n",
@@ -100,8 +96,7 @@ int main(int argc, char **argv)
 		case 'o':
 			bin_filename = strdup(optarg);
 			if (!bin_filename) {
-				fprintf(stderr, "Can't strdup() the output "
-						"filename\n");
+				fprintf(stderr, "Can't strdup() the output filename\n");
 				return EXIT_FAILURE;
 			}
 			break;
@@ -118,7 +113,7 @@ int main(int argc, char **argv)
 			usage(prg);
 			return EXIT_SUCCESS;
 		case 'V':
-			printf("%s version %s\n", prg, PLAIN_VERSION);
+			printf("%s version %s\n", argv[0], PLAIN_VERSION);
 			return EXIT_SUCCESS;
 		case ':':
 			fprintf(stderr, "Missing argument for option -%c\n",
@@ -134,22 +129,21 @@ int main(int argc, char **argv)
 
 	/* Check datasize and allocate the data */
 	if (datasize == 0) {
-		fprintf(stderr,
-			"Please specify the size of the environment "
-			"partition.\n");
+		fprintf(stderr, "Please specify the size of the environment partition.\n");
 		usage(prg);
 		return EXIT_FAILURE;
 	}
 
 	dataptr = malloc(datasize * sizeof(*dataptr));
 	if (!dataptr) {
-		fprintf(stderr, "Can't alloc dataptr.\n");
+		fprintf(stderr, "Can't alloc %d bytes for dataptr.\n",
+				datasize);
 		return EXIT_FAILURE;
 	}
 
 	/*
 	 * envptr points to the beginning of the actual environment (after the
-	 * crc and possible `redundant' bit
+	 * crc and possible `redundant' byte
 	 */
 	envsize = datasize - (CRC_SIZE + redundant);
 	envptr = dataptr + CRC_SIZE + redundant;
@@ -185,8 +179,8 @@ int main(int argc, char **argv)
 		/* ... and check it */
 		ret = fstat(txt_fd, &txt_file_stat);
 		if (ret == -1) {
-			fprintf(stderr, "Can't stat() on \"%s\": "
-					"%s\n", txt_filename, strerror(errno));
+			fprintf(stderr, "Can't stat() on \"%s\": %s\n",
+					txt_filename, strerror(errno));
 			return EXIT_FAILURE;
 		}
 
@@ -200,13 +194,9 @@ int main(int argc, char **argv)
 		}
 		ret = close(txt_fd);
 	}
-	/*
-	 * The right test to do is "=>" (not ">") because of the additional
-	 * ending \0. See below.
-	 */
-	if (filesize >= envsize) {
-		fprintf(stderr, "The input file is larger than the "
-				"environment partition size\n");
+	/* The +1 is for the additionnal ending \0. See below. */
+	if (filesize + 1 > envsize) {
+		fprintf(stderr, "The input file is larger than the environment partition size\n");
 		return EXIT_FAILURE;
 	}
 
@@ -255,8 +245,7 @@ int main(int argc, char **argv)
 		 * check the env size again to make sure we have room for two \0
 		 */
 		if (ep >= envsize) {
-			fprintf(stderr, "The environment file is too large for "
-					"the target environment storage\n");
+			fprintf(stderr, "The environment file is too large for the target environment storage\n");
 			return EXIT_FAILURE;
 		}
 		envptr[ep] = '\0';
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2012-03-27 20:37 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-13 23:27 [U-Boot] [PATCHv5 1/7] mkenvimage: correct and clarify comments and error messages David Wagner
2012-01-13 23:27 ` [U-Boot] [PATCHv5 2/7] mkenvimage: Correct an include and add a missing one David Wagner
2012-01-15  1:23   ` Mike Frysinger
2012-03-27  8:50   ` Anatolij Gustschin
2012-01-13 23:27 ` [U-Boot] [PATCHv5 3/7] mkenvimage: More error handling David Wagner
2012-01-15  1:24   ` Mike Frysinger
2012-03-27  8:51   ` Anatolij Gustschin
2012-01-13 23:27 ` [U-Boot] [PATCHv5 4/7] mkenvimage: Read/Write from/to stdin/out by default or if the filename is "-" David Wagner
2012-01-15  1:25   ` Mike Frysinger
2012-03-27  8:52   ` Anatolij Gustschin
2012-01-13 23:27 ` [U-Boot] [PATCHv5 5/7] mkenvimage: Use mmap() when reading from a regular file David Wagner
2012-01-15  1:25   ` Mike Frysinger
2012-03-27  8:52   ` Anatolij Gustschin
2012-01-13 23:27 ` [U-Boot] [PATCHv5 6/7] mkenvimage: Don't try to detect comments in the input file David Wagner
2012-01-15  1:26   ` Mike Frysinger
2012-03-27  8:53   ` Anatolij Gustschin
2012-01-13 23:27 ` [U-Boot] [PATCHv5 7/7] mkenvimage: Really set the redundant byte when applicable David Wagner
2012-01-15  1:26   ` Mike Frysinger
2012-03-27  8:53   ` Anatolij Gustschin
2012-01-15  1:22 ` [U-Boot] [PATCHv5 1/7] mkenvimage: correct and clarify comments and error messages Mike Frysinger
2012-02-26  0:19   ` David Wagner
2012-03-27  8:32     ` Anatolij Gustschin
2012-03-27 20:37       ` David Wagner
2012-03-27  8:48 ` Anatolij Gustschin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox