66 lines
1.3 KiB
C
66 lines
1.3 KiB
C
|
|
#ifndef __UTIL_STRING_H__
|
||
|
|
#define __UTIL_STRING_H__
|
||
|
|
|
||
|
|
#include <string.h>
|
||
|
|
#include <stdio.h>
|
||
|
|
#include <stdint.h>
|
||
|
|
|
||
|
|
#ifndef STRLEN
|
||
|
|
#define STRLEN(STR) ((int)strlen((const char *)STR))
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifndef ISALNUM
|
||
|
|
#define ISALNUM(S) (isalnum((const char)S))
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifndef STRCMP
|
||
|
|
#define STRCMP(S,D) (strcmp((const char *)S, (const char *)D))
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifndef STRSTR
|
||
|
|
#define STRSTR(D,S) (strstr((const char *)D,(const char *)S))
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifndef STRNCMP
|
||
|
|
#define STRNCMP(S,D,L) (strncmp((const char *)S, (const char *)D, L))
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifndef STRCAT
|
||
|
|
#define STRCAT(D,S) (strcat((char *)D, (const char *)S))
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifndef FOREVER
|
||
|
|
#define FOREVER for(;;)
|
||
|
|
#endif
|
||
|
|
|
||
|
|
typedef struct atomic {
|
||
|
|
volatile int counter;
|
||
|
|
} atomic_t;
|
||
|
|
|
||
|
|
struct value_string {
|
||
|
|
unsigned int value;
|
||
|
|
const char *strptr;
|
||
|
|
};
|
||
|
|
|
||
|
|
extern const char*
|
||
|
|
val_to_str(const unsigned int val, const struct value_string *vs);
|
||
|
|
|
||
|
|
typedef struct{
|
||
|
|
#define ATOMIC64_SIZE sizeof(long long)
|
||
|
|
int64_t counter;
|
||
|
|
}atomic64_t;
|
||
|
|
|
||
|
|
#define ATOMIC_INIT(i) { (i) }
|
||
|
|
|
||
|
|
#define atomic_read(v) (*(volatile int *)&(v)->counter)
|
||
|
|
#define atomic64_read(v) (*(volatile int64_t *)&(v)->counter)
|
||
|
|
|
||
|
|
#define atomic_add(x, y) (__sync_add_and_fetch((&(((atomic_t *)x)->counter)), (y)))
|
||
|
|
#define atomic64_add(x, y) (__sync_add_and_fetch((&(((atomic64_t *)x)->counter)), (y)))
|
||
|
|
|
||
|
|
static inline void atomic_set(atomic_t *v, int32_t val)
|
||
|
|
{
|
||
|
|
v->counter = val;
|
||
|
|
}
|
||
|
|
#endif
|