1/* 2 struct timeval * 3 time_t 4 5 Ruby has builtin class Time. INPUT/OUTPUT typemap for timeval and 6 time_t is provided. 7 8*/ 9%{ 10#ifdef __cplusplus 11extern "C" { 12#endif 13#ifdef HAVE_SYS_TIME_H 14# include <sys/time.h> 15struct timeval rb_time_timeval(VALUE); 16#endif 17#ifdef __cplusplus 18} 19#endif 20%} 21 22%typemap(in) struct timeval *INPUT (struct timeval temp) 23{ 24 if (NIL_P($input)) 25 $1 = NULL; 26 else { 27 temp = rb_time_timeval($input); 28 $1 = &temp; 29 } 30} 31 32%typemap(in,numinputs=0) struct timeval *OUTPUT(struct timeval temp) 33{ 34 $1 = &temp; 35} 36 37%typemap(argout) struct timeval *OUTPUT 38{ 39 $result = rb_time_new($1->tv_sec, $1->tv_usec); 40} 41 42%typemap(out) struct timeval * 43{ 44 $result = rb_time_new($1->tv_sec, $1->tv_usec); 45} 46 47%typemap(out) struct timespec * 48{ 49 $result = rb_time_new($1->tv_sec, $1->tv_nsec / 1000); 50} 51 52// time_t 53%typemap(in) time_t 54{ 55 if (NIL_P($input)) 56 $1 = (time_t)-1; 57 else 58 $1 = NUM2LONG(rb_funcall($input, rb_intern("tv_sec"), 0)); 59} 60 61%typemap(out) time_t 62{ 63 $result = rb_time_new($1, 0); 64} 65