b5653dc25435f394e7b0608b2b75c537c68b6cdb
[clogger.git] / ext / clogger_ext / ruby_1_9_compat.h
blobb5653dc25435f394e7b0608b2b75c537c68b6cdb
1 /* Ruby 1.8.6+ macros (for compatibility with Ruby 1.9) */
2 #ifndef RSTRING_PTR
3 # define RSTRING_PTR(s) (RSTRING(s)->ptr)
4 #endif
5 #ifndef RSTRING_LEN
6 # define RSTRING_LEN(s) (RSTRING(s)->len)
7 #endif
8 #ifndef RARRAY_LEN
9 # define RARRAY_LEN(s) (RARRAY(s)->len)
10 #endif
12 #ifndef HAVE_RB_STR_SET_LEN
13 /* this is taken from Ruby 1.8.7, 1.8.6 may not have it */
14 static void rb_18_str_set_len(VALUE str, long len)
16 RSTRING(str)->len = len;
17 RSTRING(str)->ptr[len] = '\0';
19 #define rb_str_set_len(str,len) rb_18_str_set_len(str,len)
20 #endif
22 #if ! HAVE_RB_IO_T
23 # define rb_io_t OpenFile
24 #endif
26 #ifdef GetReadFile
27 # define FPTR_TO_FD(fptr) (fileno(GetReadFile(fptr)))
28 #else
29 # if !HAVE_RB_IO_T || (RUBY_VERSION_MAJOR == 1 && RUBY_VERSION_MINOR == 8)
30 # define FPTR_TO_FD(fptr) fileno(fptr->f)
31 # else
32 # define FPTR_TO_FD(fptr) fptr->fd
33 # endif
34 #endif
36 static int my_fileno(VALUE io)
38 rb_io_t *fptr;
40 for (;;) {
41 switch (TYPE(io)) {
42 case T_FILE: {
43 GetOpenFile(io, fptr);
44 return FPTR_TO_FD(fptr);
46 default:
47 io = rb_convert_type(io, T_FILE, "IO", "to_io");
48 /* retry */