clogger 1.2.0 - small bug and compatibility fixes
[clogger.git] / ext / clogger_ext / ruby_1_9_compat.h
blob30a38d6623649ca5199c8b507b7ea8117c47db31
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_PTR
9 # define RARRAY_PTR(s) (RARRAY(s)->ptr)
10 #endif
11 #ifndef RARRAY_LEN
12 # define RARRAY_LEN(s) (RARRAY(s)->len)
13 #endif
15 #ifndef HAVE_RB_STR_SET_LEN
16 /* this is taken from Ruby 1.8.7, 1.8.6 may not have it */
17 static void rb_18_str_set_len(VALUE str, long len)
19 RSTRING(str)->len = len;
20 RSTRING(str)->ptr[len] = '\0';
22 #define rb_str_set_len(str,len) rb_18_str_set_len(str,len)
23 #endif
25 #if ! HAVE_RB_IO_T
26 # define rb_io_t OpenFile
27 #endif
29 #ifdef GetReadFile
30 # define FPTR_TO_FD(fptr) (fileno(GetReadFile(fptr)))
31 #else
32 # if !HAVE_RB_IO_T || (RUBY_VERSION_MAJOR == 1 && RUBY_VERSION_MINOR == 8)
33 # define FPTR_TO_FD(fptr) fileno(fptr->f)
34 # else
35 # define FPTR_TO_FD(fptr) fptr->fd
36 # endif
37 #endif
39 static int my_fileno(VALUE io)
41 rb_io_t *fptr;
43 for (;;) {
44 switch (TYPE(io)) {
45 case T_FILE: {
46 GetOpenFile(io, fptr);
47 return FPTR_TO_FD(fptr);
49 default:
50 io = rb_convert_type(io, T_FILE, "IO", "to_io");
51 /* retry */