GNUmakefile: rdoc 2.5.x compatibility
[unicorn.git] / ext / unicorn_http / ext_help.h
blob888bd3694d079099d28ce4fbcd7bdc0647a7427d
1 #ifndef ext_help_h
2 #define ext_help_h
4 #ifndef RSTRING_PTR
5 #define RSTRING_PTR(s) (RSTRING(s)->ptr)
6 #endif /* !defined(RSTRING_PTR) */
7 #ifndef RSTRING_LEN
8 #define RSTRING_LEN(s) (RSTRING(s)->len)
9 #endif /* !defined(RSTRING_LEN) */
11 #ifndef RUBINIUS
12 # define rb_str_update(x) do {} while (0)
13 # define rb_str_flush(x) do {} while (0)
14 #endif /* !RUBINIUS */
16 #ifndef HAVE_RB_STR_SET_LEN
17 # ifdef RUBINIUS
18 # define rb_str_set_len(str,len) rb_str_resize(str,len)
19 # else /* 1.8.6 optimized version */
20 /* this is taken from Ruby 1.8.7, 1.8.6 may not have it */
21 static void rb_18_str_set_len(VALUE str, long len)
23 RSTRING(str)->len = len;
24 RSTRING(str)->ptr[len] = '\0';
25 rb_str_flush(str);
27 # define rb_str_set_len(str,len) rb_18_str_set_len(str,len)
28 # endif /* ! RUBINIUS */
29 #endif /* !defined(HAVE_RB_STR_SET_LEN) */
31 /* not all Ruby implementations support frozen objects (Rubinius does not) */
32 #if defined(OBJ_FROZEN)
33 # define assert_frozen(f) assert(OBJ_FROZEN(f) && "unfrozen object")
34 #else
35 # define assert_frozen(f) do {} while (0)
36 #endif /* !defined(OBJ_FROZEN) */
38 #if !defined(OFFT2NUM)
39 # if SIZEOF_OFF_T == SIZEOF_LONG
40 # define OFFT2NUM(n) LONG2NUM(n)
41 # else
42 # define OFFT2NUM(n) LL2NUM(n)
43 # endif
44 #endif /* ! defined(OFFT2NUM) */
46 #ifndef HAVE_RB_STR_MODIFY
47 # define rb_str_modify(x) do {} while (0)
48 #endif /* ! defined(HAVE_RB_STR_MODIFY) */
50 static inline int str_cstr_eq(VALUE val, const char *ptr, long len)
52 return (RSTRING_LEN(val) == len && !memcmp(ptr, RSTRING_PTR(val), len));
55 #define STR_CSTR_EQ(val, const_str) \
56 str_cstr_eq(val, const_str, sizeof(const_str) - 1)
58 /* strcasecmp isn't locale independent */
59 static int str_cstr_case_eq(VALUE val, const char *ptr, long len)
61 if (RSTRING_LEN(val) == len) {
62 const char *v = RSTRING_PTR(val);
64 for (; len--; ++ptr, ++v) {
65 if ((*ptr == *v) || (*v >= 'A' && *v <= 'Z' && (*v | 0x20) == *ptr))
66 continue;
67 return 0;
69 return 1;
71 return 0;
74 #define STR_CSTR_CASE_EQ(val, const_str) \
75 str_cstr_case_eq(val, const_str, sizeof(const_str) - 1)
77 #endif /* ext_help_h */