Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 19 Dec 2007 03:17:21 GMT
From:      John Birrell <jb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 131204 for review
Message-ID:  <200712190317.lBJ3HLYT006625@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=131204

Change 131204 by jb@jb_freebsd1 on 2007/12/19 03:17:12

	getopt(3) returns an integer. Even on Solaris.
	
	The use of EOF is inappropriate. getopt(3) returns nothing associated
	with a stream file.
	
	On FreeBSD/arm, char is unsigned, so using the wrong variable type
	cases a valid compiler warning.
	
	This is a good example of why all code should compile cleanly.

Affected files ...

.. //depot/projects/dtrace/src/contrib/opensolaris/cmd/dtrace/dtrace.c#11 edit

Differences ...

==== //depot/projects/dtrace/src/contrib/opensolaris/cmd/dtrace/dtrace.c#11 (text) ====

@@ -1202,8 +1202,8 @@
 
 	g_ofp = stdout;
 	int done = 0, mode = 0;
-	int err, i;
-	char c, *p, **v;
+	int err, i, c;
+	char *p, **v;
 	struct ps_prochandle *P;
 	pid_t pid;
 
@@ -1230,7 +1230,7 @@
 	 * options into g_argv[], and abort if any invalid options are found.
 	 */
 	for (optind = 1; optind < argc; optind++) {
-		while ((c = getopt(argc, argv, DTRACE_OPTSTR)) != EOF) {
+		while ((c = getopt(argc, argv, DTRACE_OPTSTR)) != -1) {
 			switch (c) {
 			case '3':
 				if (strcmp(optarg, "2") != 0) {
@@ -1413,7 +1413,7 @@
 	 * this time; these will compiled as part of the fourth processing pass.
 	 */
 	for (optind = 1; optind < argc; optind++) {
-		while ((c = getopt(argc, argv, DTRACE_OPTSTR)) != EOF) {
+		while ((c = getopt(argc, argv, DTRACE_OPTSTR)) != -1) {
 			switch (c) {
 			case 'a':
 				if (dtrace_setopt(g_dtp, "grabanon", 0) != 0)
@@ -1570,7 +1570,7 @@
 	 * may been affected by any library options set by the second pass.
 	 */
 	for (optind = 1; optind < argc; optind++) {
-		while ((c = getopt(argc, argv, DTRACE_OPTSTR)) != EOF) {
+		while ((c = getopt(argc, argv, DTRACE_OPTSTR)) != -1) {
 			switch (c) {
 			case 'c':
 				if ((v = make_argv(optarg)) == NULL)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200712190317.lBJ3HLYT006625>