[ofw] [PATCH v2] getopt: add use of const to interface

Sean Hefty sean.hefty at intel.com
Tue Feb 24 21:37:49 PST 2009


Add const to getopt argv argument, and allow getopt to be included by
c++.

This allows the ib-diags to call getopt without build warnings.

Signed-off-by: Sean Hefty <sean.hefty at intel.com>
---
changes from v1: removed unrelated fixes from adding the const
I will commit this change if there are no other issues with it.

Index: etc/user/getopt.c
===================================================================
--- etc/user/getopt.c	(revision 1953)
+++ etc/user/getopt.c	(working copy)
@@ -39,7 +39,7 @@
 int opterr = 1;
 int optopt = '?';
 
-int getopt(int argc, char **argv, char const *opts)
+int getopt(int argc, char * const argv[], char const *opts)
 {
 	char *loc;
 
@@ -88,7 +88,7 @@
 	return optopt;
 }
 
-int getopt_long(int argc, char **argv, char const *opts,
+int getopt_long(int argc, char * const argv[], char const *opts,
 				const struct option *longopts, int *longindex)
 {
 	char arg[256];
Index: inc/user/getopt.h
===================================================================
--- inc/user/getopt.h	(revision 1953)
+++ inc/user/getopt.h	(working copy)
@@ -31,6 +31,11 @@
 #ifndef _GETOPT_H_
 #define _GETOPT_H_
 
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
 extern char *optarg;
 extern int optind;
 extern int opterr;
@@ -51,8 +56,12 @@
 	optional_argument
 };
 
-extern int getopt(int argc, char **argv, char const *opts);
-extern int getopt_long(int argc, char **argv, char const *opts,
+extern int getopt(int argc, char * const argv[], char const *opts);
+extern int getopt_long(int argc, char * const argv[], char const *opts,
 					   const struct option *longopts, int *longindex);
 
+#ifdef __cplusplus
+}	// extern "C"
 #endif
+
+#endif





More information about the ofw mailing list