unicorn_http: add helpful macros
[unicorn.git] / ext / unicorn_http / ext_help.h
blob8ccb2b9870871d142daac8db40be5a88c7753ee3
1 #ifndef ext_help_h
2 #define ext_help_h
4 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
6 #ifndef RSTRING_PTR
7 #define RSTRING_PTR(s) (RSTRING(s)->ptr)
8 #endif
9 #ifndef RSTRING_LEN
10 #define RSTRING_LEN(s) (RSTRING(s)->len)
11 #endif
13 #ifndef SIZEOF_OFF_T
14 # define SIZEOF_OFF_T 4
15 # warning SIZEOF_OFF_T not defined, guessing 4. Did you run extconf.rb?
16 #endif
18 #if SIZEOF_OFF_T == 4
19 # define UH_OFF_T_MAX 0x7fffffff
20 #elif SIZEOF_OFF_T == 8
21 # define UH_OFF_T_MAX 0x7fffffffffffffff
22 #else
23 # error off_t size unknown for this platform!
24 #endif
26 #ifndef HAVE_RB_STR_SET_LEN
27 /* this is taken from Ruby 1.8.7, 1.8.6 may not have it */
28 static void rb_18_str_set_len(VALUE str, long len)
30 RSTRING(str)->len = len;
31 RSTRING(str)->ptr[len] = '\0';
33 # define rb_str_set_len(str,len) rb_18_str_set_len(str,len)
34 #endif
36 #endif