X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcommon.c;h=2598036ddff77d0c7aac985771658ce67c1bc788;hb=1f3624e551c233c72121e4bf868c849f74e58058;hp=1ddb71ddcd1077f211eeb5b904748ddc8204fc22;hpb=5528a3df5cc55d083b5aa1926843e810467070a5;p=collectd.git diff --git a/src/common.c b/src/common.c index 1ddb71dd..2598036d 100644 --- a/src/common.c +++ b/src/common.c @@ -48,6 +48,10 @@ #include #include +#if HAVE_NETINET_IN_H +# include +#endif + #ifdef HAVE_LIBKSTAT extern kstat_ctl_t *kc; #endif @@ -664,6 +668,7 @@ long long get_kstat_value (kstat_t *ksp, char *name) } #endif /* HAVE_LIBKSTAT */ +#ifndef HAVE_HTONLL unsigned long long ntohll (unsigned long long n) { #if BYTE_ORDER == BIG_ENDIAN @@ -681,6 +686,7 @@ unsigned long long htonll (unsigned long long n) return (((unsigned long long) htonl (n)) << 32) + htonl (n >> 32); #endif } /* unsigned long long htonll */ +#endif /* HAVE_HTONLL */ #if FP_LAYOUT_NEED_NOTHING /* Well, we need nothing.. */ @@ -1004,7 +1010,7 @@ int notification_init (notification_t *n, int severity, const char *message, } /* int notification_init */ int walk_directory (const char *dir, dirwalk_callback_f callback, - void *user_data) + void *user_data, int include_hidden) { struct dirent *ent; DIR *dh; @@ -1025,9 +1031,18 @@ int walk_directory (const char *dir, dirwalk_callback_f callback, while ((ent = readdir (dh)) != NULL) { int status; - - if (ent->d_name[0] == '.') - continue; + + if (include_hidden) + { + if ((strcmp (".", ent->d_name) == 0) + || (strcmp ("..", ent->d_name) == 0)) + continue; + } + else /* if (!include_hidden) */ + { + if (ent->d_name[0]=='.') + continue; + } status = (*callback) (dir, ent->d_name, user_data); if (status != 0) @@ -1129,3 +1144,21 @@ int service_name_to_port_number (const char *service_name) return (service_number); return (-1); } /* int service_name_to_port_number */ + +int strtoderive (const char *string, derive_t *ret_value) /* {{{ */ +{ + derive_t tmp; + char *endptr; + + if ((string == NULL) || (ret_value == NULL)) + return (EINVAL); + + errno = 0; + endptr = NULL; + tmp = (derive_t) strtoll (string, &endptr, /* base = */ 0); + if ((endptr == string) || (errno != 0)) + return (-1); + + *ret_value = tmp; + return (0); +} /* }}} int strtoderive */