]> arthur.barton.de Git - netdata.git/blobdiff - src/common.c
build: migrate to autotools
[netdata.git] / src / common.c
index a76b78f227b935c715170d3231cf9fa885bc6729..2df676f90216253f4e7584e242ba697d6e354d1f 100755 (executable)
@@ -1,6 +1,7 @@
-// enable O_NOATIME
-#define _GNU_SOURCE
-
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <sys/syscall.h>
 #include <string.h>
 #include <ctype.h>
 #include <errno.h>
@@ -14,6 +15,8 @@
 #include "log.h"
 #include "common.h"
 
+char *global_host_prefix = "";
+
 /*
 // http://stackoverflow.com/questions/7666509/hash-function-for-string
 uint32_t simple_hash(const char *name)
@@ -30,6 +33,7 @@ uint32_t simple_hash(const char *name)
 }
 */
 
+
 // http://isthe.com/chongo/tech/comp/fnv/#FNV-1a
 uint32_t simple_hash(const char *name) {
        unsigned char *s = (unsigned char *)name;
@@ -49,6 +53,28 @@ uint32_t simple_hash(const char *name) {
        return hval;
 }
 
+/*
+// http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx
+// one at a time hash
+uint32_t simple_hash(const char *name) {
+       unsigned char *s = (unsigned char *)name;
+       uint32_t h = 0;
+
+       while(*s) {
+               h += *s++;
+               h += (h << 10);
+               h ^= (h >> 6);
+       }
+
+       h += (h << 3);
+       h ^= (h >> 11);
+       h += (h << 15);
+
+       // fprintf(stderr, "HASH: %u = %s\n", h, name);
+
+       return h;
+}
+*/
 
 void strreverse(char* begin, char* end)
 {
@@ -64,44 +90,6 @@ char *mystrsep(char **ptr, char *s)
        return(p);
 }
 
-// like strsep() but:
-// it trims spaces before and after each value
-// it accepts quoted values in single or double quotes
-char *qstrsep(char **ptr)
-{
-       if(!*ptr || !**ptr) return NULL;
-       
-       char *s, *p = *ptr;
-
-       // skip leading spaces
-       while(isspace(*p)) p++;
-
-       // if the first char is a quote, assume quoted
-       if(*p == '"' || *p == '\'') {
-               char q = *p;
-               s = ++p;
-               while(*p && *p != q) p++;
-
-               if(*p == q) {
-                       *p = '\0';
-                       p++;
-               }
-
-               *ptr = p;
-               return s;
-       }
-
-       s = p;
-       while(*p && !isspace(*p)) p++;
-       if(!*p) *ptr = NULL;
-       else {
-               *p = '\0';
-               *ptr = ++p;
-       }
-
-       return s;
-}
-
 char *trim(char *s)
 {
        // skip leading spaces
@@ -183,3 +171,26 @@ int fd_is_valid(int fd) {
     return fcntl(fd, F_GETFD) != -1 || errno != EBADF;
 }
 
+/*
+ ***************************************************************************
+ * Get number of clock ticks per second.
+ ***************************************************************************
+ */
+unsigned int hz;
+
+void get_HZ(void)
+{
+       long ticks;
+
+       if ((ticks = sysconf(_SC_CLK_TCK)) == -1) {
+               perror("sysconf");
+       }
+
+       hz = (unsigned int) ticks;
+}
+
+pid_t gettid(void)
+{
+       return syscall(SYS_gettid);
+}
+