]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
Replace index() by strchr()
authorVincent Bernat <bernat@luffy.cx>
Thu, 9 Jul 2009 19:56:17 +0000 (21:56 +0200)
committerVincent Bernat <bernat@luffy.cx>
Tue, 29 Sep 2009 14:44:58 +0000 (16:44 +0200)
strchr() is POSIX while index() is deprecated.

src/lldpctl.c
src/lldpd.c

index c5e924db774455842fad27d1d13300de02483a6d..e0509a39fc8f8c573ad37f2133415d8cb7d00604 100644 (file)
@@ -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++;
index 20bd73b2e2e4b6c72f1506a53098e3f965e0308d..19edad42deef6cc4872141bfbb65d13e05f6e5e1 100644 (file)
@@ -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;