-// 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>
#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)
}
*/
+
// http://isthe.com/chongo/tech/comp/fnv/#FNV-1a
uint32_t simple_hash(const char *name) {
unsigned char *s = (unsigned 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)
{
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
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);
+}
+