From: Vincent Bernat Date: Thu, 9 Jul 2009 19:56:17 +0000 (+0200) Subject: Replace index() by strchr() X-Git-Tag: 0.5.0~37^2~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f0bd3505f46dbe13ac9fd5ba616542ec4262d93c;p=thirdparty%2Flldpd.git Replace index() by strchr() strchr() is POSIX while index() is deprecated. --- diff --git a/src/lldpctl.c b/src/lldpctl.c index c5e924db..e0509a39 100644 --- a/src/lldpctl.c +++ b/src/lldpctl.c @@ -305,7 +305,7 @@ static void pretty_print(char *string) { char *s = NULL; - if (((s = index(string, '\n')) == NULL) && (strlen(string) < 60)) { + if (((s = strchr(string, '\n')) == NULL) && (strlen(string) < 60)) { printf("%s\n", string); return; } else @@ -315,7 +315,7 @@ pretty_print(char *string) printf(" %s\n", string); *s = '\n'; string = s + 1; - s = index(string, '\n'); + s = strchr(string, '\n'); } printf(" %s\n", string); } @@ -895,7 +895,7 @@ lldpd_parse_location(struct lldpd_port *port, const char *location) if ((l = strdup(location)) == NULL) fatal(NULL); s = l; - if ((e = index(s, ':')) == NULL) + if ((e = strchr(s, ':')) == NULL) goto invalid_location; *e = '\0'; type = atoi(s); @@ -912,12 +912,12 @@ lldpd_parse_location(struct lldpd_port *port, const char *location) /* Latitude and longitude */ for (i = 0; i < 2; i++) { s = e+1; - if ((e = index(s, ':')) == NULL) + if ((e = strchr(s, ':')) == NULL) goto invalid_location; *e = '\0'; ll = atof(s); s = e + 1; - if ((e = index(s, ':')) == NULL) + if ((e = strchr(s, ':')) == NULL) goto invalid_location; *e = '\0'; intpart = (int)ll; @@ -947,12 +947,12 @@ lldpd_parse_location(struct lldpd_port *port, const char *location) /* Altitude */ s = e+1; - if ((e = index(s, ':')) == NULL) + if ((e = strchr(s, ':')) == NULL) goto invalid_location; *e = '\0'; altitude = atof(s); s = e+1; - if ((e = index(s, ':')) == NULL) + if ((e = strchr(s, ':')) == NULL) goto invalid_location; *e = '\0'; if (altitude < 0) { @@ -981,7 +981,7 @@ lldpd_parse_location(struct lldpd_port *port, const char *location) /* Datum */ s = e + 1; - if (index(s, ':') != NULL) + if (strchr(s, ':') != NULL) goto invalid_location; *(u_int8_t *)data = atoi(s); break; @@ -989,19 +989,19 @@ lldpd_parse_location(struct lldpd_port *port, const char *location) /* Civic address */ port->p_med_location[1].data_len = 4; s = e+1; - if ((s = index(s, ':')) == NULL) + if ((s = strchr(s, ':')) == NULL) goto invalid_location; s = s+1; do { - if ((s = index(s, ':')) == NULL) + if ((s = strchr(s, ':')) == NULL) break; s = s+1; /* s is the beginning of the word */ - if ((n = index(s, ':')) == NULL) + if ((n = strchr(s, ':')) == NULL) n = s + strlen(s); /* n is the end of the word */ port->p_med_location[1].data_len += (n - s) + 2; - if ((s = index(s, ':')) == NULL) + if ((s = strchr(s, ':')) == NULL) break; s = s+1; } while (1); @@ -1016,7 +1016,7 @@ lldpd_parse_location(struct lldpd_port *port, const char *location) data++; *(u_int8_t *)data = 2; /* Client location */ data++; - if ((e = index(s, ':')) == NULL) + if ((e = strchr(s, ':')) == NULL) goto invalid_location; if ((e - s) != 2) goto invalid_location; @@ -1024,13 +1024,13 @@ lldpd_parse_location(struct lldpd_port *port, const char *location) data += 2; while (*e != '\0') { s=e+1; - if ((e = index(s, ':')) == NULL) + if ((e = strchr(s, ':')) == NULL) goto invalid_location; *e = '\0'; *(u_int8_t *)data = atoi(s); data++; s=e+1; - if ((e = index(s, ':')) == NULL) + if ((e = strchr(s, ':')) == NULL) e = s + strlen(s); *(u_int8_t *)data = e - s; data++; diff --git a/src/lldpd.c b/src/lldpd.c index 20bd73b2..19edad42 100644 --- a/src/lldpd.c +++ b/src/lldpd.c @@ -751,7 +751,7 @@ lldpd_main(int argc, char *argv[]) /* * Get and parse command line options */ - popt = index(opts, '@'); + popt = strchr(opts, '@'); for (i=0; protos[i].mode != 0; i++) { if (protos[i].enabled == 1) continue; *(popt++) = protos[i].arg;