00001
00002
00003
00004
00005
00006
00007 #ifndef _NM_H
00008 #define _NM_H
00009
00010
00011
00012
00013
00014 #define NM_CDECL_BEGIN extern "C" {
00015 #ifdef __cplusplus
00016 NM_CDECL_BEGIN
00017 #endif
00018
00019 typedef unsigned char nm_u8_t;
00020 typedef unsigned short nm_u16_t;
00021 typedef unsigned int nm_u32_t;
00022 typedef unsigned long long nm_u64_t;
00023
00024 #define NM_BIT(__b) (1 << __b)
00025 #define NM_ARRAY_SZ(__a) (sizeof(__a) / sizeof(__a[0]))
00026
00027
00028 #define nm_offsetof(type,member) ((size_t) &((type *)0)->member)
00029
00038 #define nm_container_of(ptr, type, member) ({ \
00039 const __typeof__(((type *)0)->member ) *__mptr = (ptr); \
00040 (type *)((char *)__mptr - nm_offsetof(type,member));})
00041
00042
00043 #define nm_roundup2(c,a) ((c + (a-1)) & ~(a-1))
00044
00051 static inline int nm_strncpy(char *dst, const char *src, int n)
00052 {
00053 int i;
00054 for (i = 0; *src && i < (n - 1); i++)
00055 *dst++ = *src++;
00056 *dst = '\0';
00057 return i;
00058 }
00059
00064 struct nm_sz_map {
00065 int count;
00066 int width;
00067 void *map;
00068
00069
00070 };
00071
00083 int nm_sz_map(const struct nm_sz_map *tbl, const char *key, void **v);
00084
00085 #define NM_CDECL_END }
00086 #ifdef __cplusplus
00087 NM_CDECL_END
00088 #endif
00089
00090 #endif