[PATCH] For posix compliance: replace index with strchr

Cheng Renquan crquan at gmail.com
Wed Apr 1 09:22:35 GMT 2009


When compiled with other posix conforming libc, like uclibc,
it will fail with the lack of "index" function, in fact, index
is really legacy, and dropped in POSIX.1-2008

>From index(3):

  CONFORMING TO
       4.3BSD; marked as LEGACY in POSIX.1-2001.  POSIX.1-2008
       removes the specifications of index() and rindex().

Signed-off-by: Cheng Renquan <crquan at gmail.com>
---
 source/client/cifs.upcall.c     |    4 ++--
 source/registry/reg_perfcount.c |    6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/source/client/cifs.upcall.c b/source/client/cifs.upcall.c
index 4110de3..2393faa 100644
--- a/source/client/cifs.upcall.c
+++ b/source/client/cifs.upcall.c
@@ -99,7 +99,7 @@ decode_key_description(const char *desc, int *ver, secType_t * sec,
 	const char *tkn = desc;
 
 	do {
-		pos = index(tkn, ';');
+		pos = strchr(tkn, ';');
 		if (strncmp(tkn, "host=", 5) == 0) {
 			int len;
 
@@ -164,7 +164,7 @@ cifs_resolver(const key_serial_t key, const char *key_descr)
 	const char *keyend = key_descr;
 	/* skip next 4 ';' delimiters to get to description */
 	for (c = 1; c <= 4; c++) {
-		keyend = index(keyend+1, ';');
+		keyend = strchr(keyend+1, ';');
 		if (!keyend) {
 			syslog(LOG_WARNING, "invalid key description: %s",
 					key_descr);
diff --git a/source/registry/reg_perfcount.c b/source/registry/reg_perfcount.c
index e608847..4cf8e3c 100644
--- a/source/registry/reg_perfcount.c
+++ b/source/registry/reg_perfcount.c
@@ -616,14 +616,14 @@ static bool _reg_perfcount_add_counter(PERF_DATA_BLOCK *block,
 	obj = NULL;
 	memset(buf, 0, PERFCOUNT_MAX_LEN);
 	memcpy(buf, data.dptr, data.dsize);
-	begin = index(buf, '[');
-	end = index(buf, ']');
+	begin = strchr(buf, '[');
+	end = strchr(buf, ']');
 	if(begin == NULL || end == NULL)
 		return False;
 	start = begin+1;
 
 	while(start < end) {
-		stop = index(start, ',');
+		stop = strchr(start, ',');
 		if(stop == NULL)
 			stop = end;
 		*stop = '\0';
-- 
1.6.0.6



More information about the samba-technical mailing list