From c7f30fdded5fd31696fbc2ff9b4428edc8aae48b Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 14 Aug 2016 20:52:47 +0100 Subject: [PATCH] posix: replace bzero() and index() with modern equivelants Replace bzero() with memset() and index() with strchr(). The earlier functions are marked as legacy in posix. Reference: http://pubs.opengroup.org/onlinepubs/009695399/functions/index.html Reference: http://pubs.opengroup.org/onlinepubs/009695399/functions/bzero.html --- curses.c | 2 +- mtr.c | 4 ++-- report.c | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/curses.c b/curses.c index b4201d8..e7555fa 100644 --- a/curses.c +++ b/curses.c @@ -288,7 +288,7 @@ int mtr_curses_keyaction(void) return ActionNone; } if (tolower(c) == 'j') { - if( index(fld_active, 'N') ) { + if( strchr(fld_active, 'N') ) { strcpy(fld_active, "DR AGJMXI"); /* GeoMean and jitter */ } else { strcpy(fld_active, "LS NABWV"); /* default */ diff --git a/mtr.c b/mtr.c index f4bbf10..4085236 100644 --- a/mtr.c +++ b/mtr.c @@ -723,7 +723,7 @@ int main(int argc, char **argv) #ifdef ENABLE_IPV6 /* gethostbyname2() is deprecated so we'll use getaddrinfo() instead. */ - bzero( &hints, sizeof hints ); + memset( &hints, 0, sizeof hints ); hints.ai_family = af; hints.ai_socktype = SOCK_DGRAM; error = getaddrinfo( Hostname, NULL, &hints, &res ); @@ -741,7 +741,7 @@ int main(int argc, char **argv) } /* Convert the first addrinfo into a hostent. */ host = &trhost; - bzero( host, sizeof trhost ); + memset( host, 0, sizeof trhost ); host->h_name = res->ai_canonname; host->h_aliases = NULL; host->h_addrtype = res->ai_family; diff --git a/report.c b/report.c index b47a855..f33626c 100644 --- a/report.c +++ b/report.c @@ -162,7 +162,7 @@ void report_close(void) if (j < 0) continue; /* 1000.0 is a temporay hack for stats usec to ms, impacted net_loss. */ - if( index( data_fields[j].format, 'f' ) ) { + if( strchr( data_fields[j].format, 'f' ) ) { snprintf( buf + len, sizeof(buf), data_fields[j].format, data_fields[j].net_xxx(at) /1000.0 ); } else { @@ -318,7 +318,7 @@ void json_close(void) /* Format value */ const char *format; format = data_fields[j].format; - if( index(format, 'f') ) { + if( strchr(format, 'f') ) { format = "%.2f"; } else { format = "%d"; @@ -329,7 +329,7 @@ void json_close(void) strcat(name, format); /* Output json line */ - if(index(data_fields[j].format, 'f')) { + if(strchr(data_fields[j].format, 'f')) { /* 1000.0 is a temporay hack for stats usec to ms, impacted net_loss. */ printf(name, data_fields[j].title, @@ -401,7 +401,7 @@ void xml_close(void) } /* 1000.0 is a temporay hack for stats usec to ms, impacted net_loss. */ - if( index( data_fields[j].format, 'f' ) ) { + if( strchr( data_fields[j].format, 'f' ) ) { printf( name, title, data_fields[j].net_xxx(at) /1000.0, @@ -471,7 +471,7 @@ void csv_close(time_t now) if (j < 0) continue; /* 1000.0 is a temporay hack for stats usec to ms, impacted net_loss. */ - if( index( data_fields[j].format, 'f' ) ) { + if( strchr( data_fields[j].format, 'f' ) ) { printf( ",%.2f", data_fields[j].net_xxx(at) / 1000.0); } else { printf( ",%d", data_fields[j].net_xxx(at) );