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
This commit is contained in:
Sami Kerola 2016-08-14 20:52:47 +01:00
parent 73e17d9a02
commit c7f30fdded
No known key found for this signature in database
GPG Key ID: A9553245FDE9B739
3 changed files with 8 additions and 8 deletions

View File

@ -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 */

4
mtr.c
View File

@ -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;

View File

@ -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) );