X-Git-Url: http://git.openwrt.org/?a=blobdiff_plain;f=utils.h;h=dacac6e41092e2b395f3867fa6dd91812a40acf8;hb=d27acfe416d67f9425d40b5e758949cd7ff9acfa;hp=019d817fed5f3b3c8ae80902114635cc674b3dec;hpb=6eff829d788b36939325557066f58aafd6a05321;p=project%2Flibubox.git diff --git a/utils.h b/utils.h index 019d817..dacac6e 100644 --- a/utils.h +++ b/utils.h @@ -19,6 +19,7 @@ #ifndef __LIBUBOX_UTILS_H #define __LIBUBOX_UTILS_H +#include #include #include #include @@ -142,6 +143,22 @@ int clock_gettime(int type, struct timespec *tv); #if __BYTE_ORDER == __LITTLE_ENDIAN +#define const_cpu_to_be64(x) __constant_swap64(x) +#define const_cpu_to_be32(x) __constant_swap32(x) +#define const_cpu_to_be16(x) __constant_swap16(x) + +#define const_be64_to_cpu(x) __constant_swap64(x) +#define const_be32_to_cpu(x) __constant_swap32(x) +#define const_be16_to_cpu(x) __constant_swap16(x) + +#define const_cpu_to_le64(x) (x) +#define const_cpu_to_le32(x) (x) +#define const_cpu_to_le16(x) (x) + +#define const_le64_to_cpu(x) (x) +#define const_le32_to_cpu(x) (x) +#define const_le16_to_cpu(x) (x) + #define cpu_to_be64(x) __eval_safe(__constant_swap64, x) #define cpu_to_be32(x) __eval_safe(__constant_swap32, x) #define cpu_to_be16(x) __eval_safe(__constant_swap16, x) @@ -160,6 +177,22 @@ int clock_gettime(int type, struct timespec *tv); #else /* __BYTE_ORDER == __LITTLE_ENDIAN */ +#define const_cpu_to_le64(x) __constant_swap64(x) +#define const_cpu_to_le32(x) __constant_swap32(x) +#define const_cpu_to_le16(x) __constant_swap16(x) + +#define const_le64_to_cpu(x) __constant_swap64(x) +#define const_le32_to_cpu(x) __constant_swap32(x) +#define const_le16_to_cpu(x) __constant_swap16(x) + +#define const_cpu_to_be64(x) (x) +#define const_cpu_to_be32(x) (x) +#define const_cpu_to_be16(x) (x) + +#define const_be64_to_cpu(x) (x) +#define const_be32_to_cpu(x) (x) +#define const_be16_to_cpu(x) (x) + #define cpu_to_le64(x) __eval_safe(__constant_swap64, x) #define cpu_to_le32(x) __eval_safe(__constant_swap32, x) #define cpu_to_le16(x) __eval_safe(__constant_swap16, x) @@ -194,6 +227,18 @@ int clock_gettime(int type, struct timespec *tv); #define __hidden __attribute__((visibility("hidden"))) #endif +#ifndef __has_attribute +# define __has_attribute(x) 0 +#endif + +#ifndef fallthrough +# if __has_attribute(__fallthrough__) +# define fallthrough __attribute__((__fallthrough__)) +# else +# define fallthrough do {} while (0) /* fallthrough */ +# endif +#endif + int b64_encode(const void *src, size_t src_len, void *dest, size_t dest_len); @@ -220,5 +265,6 @@ static inline unsigned long cbuf_size(int order) void *cbuf_alloc(unsigned int order); void cbuf_free(void *ptr, unsigned int order); +int mkdir_p(char *dir, mode_t mask); #endif