Add support for chroot to Worker#user
[unicorn.git] / ext / unicorn_http / ext_help.h
blob747c36cf0aa2d9b83f537d3c1fe6b19909e0af87
1 #ifndef ext_help_h
2 #define ext_help_h
4 /* not all Ruby implementations support frozen objects (Rubinius does not) */
5 #if defined(OBJ_FROZEN)
6 # define assert_frozen(f) assert(OBJ_FROZEN(f) && "unfrozen object")
7 #else
8 # define assert_frozen(f) do {} while (0)
9 #endif /* !defined(OBJ_FROZEN) */
11 #if !defined(OFFT2NUM)
12 # if SIZEOF_OFF_T == SIZEOF_LONG
13 # define OFFT2NUM(n) LONG2NUM(n)
14 # else
15 # define OFFT2NUM(n) LL2NUM(n)
16 # endif
17 #endif /* ! defined(OFFT2NUM) */
19 #if !defined(SIZET2NUM)
20 # if SIZEOF_SIZE_T == SIZEOF_LONG
21 # define SIZET2NUM(n) ULONG2NUM(n)
22 # else
23 # define SIZET2NUM(n) ULL2NUM(n)
24 # endif
25 #endif /* ! defined(SIZET2NUM) */
27 #if !defined(NUM2SIZET)
28 # if SIZEOF_SIZE_T == SIZEOF_LONG
29 # define NUM2SIZET(n) ((size_t)NUM2ULONG(n))
30 # else
31 # define NUM2SIZET(n) ((size_t)NUM2ULL(n))
32 # endif
33 #endif /* ! defined(NUM2SIZET) */
35 static inline int str_cstr_eq(VALUE val, const char *ptr, long len)
37 return (RSTRING_LEN(val) == len && !memcmp(ptr, RSTRING_PTR(val), len));
40 #define STR_CSTR_EQ(val, const_str) \
41 str_cstr_eq(val, const_str, sizeof(const_str) - 1)
43 /* strcasecmp isn't locale independent */
44 static int str_cstr_case_eq(VALUE val, const char *ptr, long len)
46 if (RSTRING_LEN(val) == len) {
47 const char *v = RSTRING_PTR(val);
49 for (; len--; ++ptr, ++v) {
50 if ((*ptr == *v) || (*v >= 'A' && *v <= 'Z' && (*v | 0x20) == *ptr))
51 continue;
52 return 0;
54 return 1;
56 return 0;
59 #define STR_CSTR_CASE_EQ(val, const_str) \
60 str_cstr_case_eq(val, const_str, sizeof(const_str) - 1)
62 #endif /* ext_help_h */