From dda5dc00cff334cac373096d444a0fd59e716124 Mon Sep 17 00:00:00 2001 From: ocean Date: Mon, 12 Sep 2005 10:44:21 +0000 Subject: * array.c: moved to ANSI function style from K&R function style. (used protoize on windows, so still K&R remains on #ifdef part of other platforms. And `foo _((boo))' stuff is still there) [ruby-dev:26975] * bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c, enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c, io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c, prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c, regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c, sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c, version.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- time.c | 212 ++++++++++++++++++++--------------------------------------------- 1 file changed, 64 insertions(+), 148 deletions(-) (limited to 'time.c') diff --git a/time.c b/time.c index eaf8f5acc0..140543e477 100644 --- a/time.c +++ b/time.c @@ -32,19 +32,14 @@ struct time_object { #define GetTimeval(obj, tobj) \ Data_Get_Struct(obj, struct time_object, tobj) -static void time_free _((void *)); - static void -time_free(tobj) - void *tobj; +time_free(void *tobj) { if (tobj) free(tobj); } -static VALUE time_s_alloc _((VALUE)); static VALUE -time_s_alloc(klass) - VALUE klass; +time_s_alloc(VALUE klass) { VALUE obj; struct time_object *tobj; @@ -58,8 +53,7 @@ time_s_alloc(klass) } static void -time_modify(time) - VALUE time; +time_modify(VALUE time) { rb_check_frozen(time); if (!OBJ_TAINTED(time) && rb_safe_level() >= 4) @@ -91,8 +85,7 @@ time_modify(time) */ static VALUE -time_init(time) - VALUE time; +time_init(VALUE time) { struct time_object *tobj; @@ -112,8 +105,7 @@ time_init(time) #define NMOD(x,y) ((y)-(-((x)+1)%(y))-1) void -time_overflow_p(secp, usecp) - time_t *secp, *usecp; +time_overflow_p(time_t *secp, time_t *usecp) { time_t tmp, sec = *secp, usec = *usecp; @@ -142,9 +134,7 @@ time_overflow_p(secp, usecp) } static VALUE -time_new_internal(klass, sec, usec) - VALUE klass; - time_t sec, usec; +time_new_internal(VALUE klass, time_t sec, time_t usec) { VALUE time = time_s_alloc(klass); struct time_object *tobj; @@ -158,16 +148,13 @@ time_new_internal(klass, sec, usec) } VALUE -rb_time_new(sec, usec) - time_t sec, usec; +rb_time_new(time_t sec, time_t usec) { return time_new_internal(rb_cTime, sec, usec); } static struct timeval -time_timeval(time, interval) - VALUE time; - int interval; +time_timeval(VALUE time, int interval) { struct timeval t; char *tstr = interval ? "time interval" : "time"; @@ -215,15 +202,13 @@ time_timeval(time, interval) } struct timeval -rb_time_interval(time) - VALUE time; +rb_time_interval(VALUE time) { return time_timeval(time, Qtrue); } struct timeval -rb_time_timeval(time) - VALUE time; +rb_time_timeval(VALUE time) { struct time_object *tobj; struct timeval t; @@ -252,10 +237,7 @@ rb_time_timeval(time) */ static VALUE -time_s_at(argc, argv, klass) - int argc; - VALUE *argv; - VALUE klass; +time_s_at(int argc, VALUE *argv, VALUE klass) { struct timeval tv; VALUE time, t; @@ -284,8 +266,7 @@ static char *months [12] = { }; static long -obj2long(obj) - VALUE obj; +obj2long(VALUE obj) { if (TYPE(obj) == T_STRING) { obj = rb_str_to_inum(obj, 10, Qfalse); @@ -295,11 +276,7 @@ obj2long(obj) } static void -time_arg(argc, argv, tm, usec) - int argc; - VALUE *argv; - struct tm *tm; - time_t *usec; +time_arg(int argc, VALUE *argv, struct tm *tm, time_t *usec) { VALUE v[8]; int i; @@ -401,8 +378,7 @@ static VALUE time_localtime _((VALUE)); static VALUE time_get_tm _((VALUE, int)); static int -leap_year_p(y) - long y; +leap_year_p(long y) { return ((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0); } @@ -410,8 +386,7 @@ leap_year_p(y) #define DIV(n,d) ((n)<0 ? NDIV((n),(d)) : (n)/(d)) static time_t -timegm_noleapsecond(tm) - struct tm *tm; +timegm_noleapsecond(struct tm *tm) { static int common_year_yday_offset[] = { -1, @@ -466,9 +441,7 @@ timegm_noleapsecond(tm) } static int -tmcmp(a, b) - struct tm *a; - struct tm *b; +tmcmp(struct tm *a, struct tm *b) { if (a->tm_year != b->tm_year) return a->tm_year < b->tm_year ? -1 : 1; @@ -487,9 +460,7 @@ tmcmp(a, b) } static time_t -search_time_t(tptr, utc_p) - struct tm *tptr; - int utc_p; +search_time_t(struct tm *tptr, int utc_p) { time_t guess, guess_lo, guess_hi; struct tm *tm, tm_lo, tm_hi; @@ -743,9 +714,7 @@ search_time_t(tptr, utc_p) } static time_t -make_time_t(tptr, utc_p) - struct tm *tptr; - int utc_p; +make_time_t(struct tm *tptr, int utc_p) { time_t t; struct tm *tmp, buf; @@ -789,11 +758,7 @@ make_time_t(tptr, utc_p) } static VALUE -time_utc_or_local(argc, argv, utc_p, klass) - int argc; - VALUE *argv; - int utc_p; - VALUE klass; +time_utc_or_local(int argc, VALUE *argv, int utc_p, VALUE klass) { struct tm tm; VALUE time; @@ -827,10 +792,7 @@ time_utc_or_local(argc, argv, utc_p, klass) * Time.gm(2000,"jan",1,20,15,1) #=> Sat Jan 01 20:15:01 UTC 2000 */ static VALUE -time_s_mkutc(argc, argv, klass) - int argc; - VALUE *argv; - VALUE klass; +time_s_mkutc(int argc, VALUE *argv, VALUE klass) { return time_utc_or_local(argc, argv, Qtrue, klass); } @@ -849,10 +811,7 @@ time_s_mkutc(argc, argv, klass) */ static VALUE -time_s_mktime(argc, argv, klass) - int argc; - VALUE *argv; - VALUE klass; +time_s_mktime(int argc, VALUE *argv, VALUE klass) { return time_utc_or_local(argc, argv, Qfalse, klass); } @@ -871,8 +830,7 @@ time_s_mktime(argc, argv, klass) */ static VALUE -time_to_i(time) - VALUE time; +time_to_i(VALUE time) { struct time_object *tobj; @@ -893,8 +851,7 @@ time_to_i(time) */ static VALUE -time_to_f(time) - VALUE time; +time_to_f(VALUE time) { struct time_object *tobj; @@ -915,8 +872,7 @@ time_to_f(time) */ static VALUE -time_usec(time) - VALUE time; +time_usec(VALUE time) { struct time_object *tobj; @@ -941,8 +897,7 @@ time_usec(time) */ static VALUE -time_cmp(time1, time2) - VALUE time1, time2; +time_cmp(VALUE time1, VALUE time2) { struct time_object *tobj1, *tobj2; @@ -971,8 +926,7 @@ time_cmp(time1, time2) */ static VALUE -time_eql(time1, time2) - VALUE time1, time2; +time_eql(VALUE time1, VALUE time2) { struct time_object *tobj1, *tobj2; @@ -1006,8 +960,7 @@ time_eql(time1, time2) */ static VALUE -time_utc_p(time) - VALUE time; +time_utc_p(VALUE time) { struct time_object *tobj; @@ -1024,8 +977,7 @@ time_utc_p(time) */ static VALUE -time_hash(time) - VALUE time; +time_hash(VALUE time) { struct time_object *tobj; long hash; @@ -1037,8 +989,7 @@ time_hash(time) /* :nodoc: */ static VALUE -time_init_copy(copy, time) - VALUE copy, time; +time_init_copy(VALUE copy, VALUE time) { struct time_object *tobj, *tcopy; @@ -1055,8 +1006,7 @@ time_init_copy(copy, time) } static VALUE -time_dup(time) - VALUE time; +time_dup(VALUE time) { VALUE dup = time_s_alloc(rb_cTime); time_init_copy(dup, time); @@ -1077,8 +1027,7 @@ time_dup(time) */ static VALUE -time_localtime(time) - VALUE time; +time_localtime(VALUE time) { struct time_object *tobj; struct tm *tm_tmp; @@ -1121,8 +1070,7 @@ time_localtime(time) */ static VALUE -time_gmtime(time) - VALUE time; +time_gmtime(VALUE time) { struct time_object *tobj; struct tm *tm_tmp; @@ -1161,8 +1109,7 @@ time_gmtime(time) */ static VALUE -time_getlocaltime(time) - VALUE time; +time_getlocaltime(VALUE time) { return time_localtime(time_dup(time)); } @@ -1183,16 +1130,13 @@ time_getlocaltime(time) */ static VALUE -time_getgmtime(time) - VALUE time; +time_getgmtime(VALUE time) { return time_gmtime(time_dup(time)); } static VALUE -time_get_tm(time, gmt) - VALUE time; - int gmt; +time_get_tm(VALUE time, int gmt) { if (gmt) return time_gmtime(time); return time_localtime(time); @@ -1209,8 +1153,7 @@ time_get_tm(time, gmt) */ static VALUE -time_asctime(time) - VALUE time; +time_asctime(VALUE time) { struct time_object *tobj; char *s; @@ -1239,8 +1182,7 @@ time_asctime(time) */ static VALUE -time_to_s(time) - VALUE time; +time_to_s(VALUE time) { struct time_object *tobj; char buf[128]; @@ -1270,10 +1212,7 @@ typedef unsigned long long unsigned_time_t; #endif static VALUE -time_add(tobj, offset, sign) - struct time_object *tobj; - VALUE offset; - int sign; +time_add(struct time_object *tobj, VALUE offset, int sign) { double v = NUM2DBL(offset); double f, d; @@ -1324,8 +1263,7 @@ time_add(tobj, offset, sign) */ static VALUE -time_plus(time1, time2) - VALUE time1, time2; +time_plus(VALUE time1, VALUE time2) { struct time_object *tobj; GetTimeval(time1, tobj); @@ -1352,8 +1290,7 @@ time_plus(time1, time2) */ static VALUE -time_minus(time1, time2) - VALUE time1, time2; +time_minus(VALUE time1, VALUE time2) { struct time_object *tobj; @@ -1380,8 +1317,7 @@ time_minus(time1, time2) */ static VALUE -time_succ(time) - VALUE time; +time_succ(VALUE time) { struct time_object *tobj; @@ -1403,8 +1339,7 @@ time_succ(time) */ static VALUE -time_sec(time) - VALUE time; +time_sec(VALUE time) { struct time_object *tobj; @@ -1426,8 +1361,7 @@ time_sec(time) */ static VALUE -time_min(time) - VALUE time; +time_min(VALUE time) { struct time_object *tobj; @@ -1449,8 +1383,7 @@ time_min(time) */ static VALUE -time_hour(time) - VALUE time; +time_hour(VALUE time) { struct time_object *tobj; @@ -1474,8 +1407,7 @@ time_hour(time) */ static VALUE -time_mday(time) - VALUE time; +time_mday(VALUE time) { struct time_object *tobj; @@ -1499,8 +1431,7 @@ time_mday(time) */ static VALUE -time_mon(time) - VALUE time; +time_mon(VALUE time) { struct time_object *tobj; @@ -1522,8 +1453,7 @@ time_mon(time) */ static VALUE -time_year(time) - VALUE time; +time_year(VALUE time) { struct time_object *tobj; @@ -1546,8 +1476,7 @@ time_year(time) */ static VALUE -time_wday(time) - VALUE time; +time_wday(VALUE time) { struct time_object *tobj; @@ -1569,8 +1498,7 @@ time_wday(time) */ static VALUE -time_yday(time) - VALUE time; +time_yday(VALUE time) { struct time_object *tobj; @@ -1596,8 +1524,7 @@ time_yday(time) */ static VALUE -time_isdst(time) - VALUE time; +time_isdst(VALUE time) { struct time_object *tobj; @@ -1622,8 +1549,7 @@ time_isdst(time) */ static VALUE -time_zone(time) - VALUE time; +time_zone(VALUE time) { struct time_object *tobj; #if !defined(HAVE_TM_ZONE) && (!defined(HAVE_TZNAME) || !defined(HAVE_DAYLIGHT)) @@ -1665,8 +1591,7 @@ time_zone(time) */ static VALUE -time_utc_offset(time) - VALUE time; +time_utc_offset(VALUE time) { struct time_object *tobj; @@ -1722,8 +1647,7 @@ time_utc_offset(time) */ static VALUE -time_to_a(time) - VALUE time; +time_to_a(VALUE time) { struct time_object *tobj; @@ -1746,10 +1670,10 @@ time_to_a(time) #define SMALLBUF 100 static int -rb_strftime(buf, format, time) - char ** volatile buf; - char * volatile format; - struct tm * volatile time; +rb_strftime( + char ** volatile buf, + char * volatile format, + struct tm * volatile time) { volatile int size; int len, flen; @@ -1820,8 +1744,7 @@ rb_strftime(buf, format, time) */ static VALUE -time_strftime(time, format) - VALUE time, format; +time_strftime(VALUE time, VALUE format) { struct time_object *tobj; char buffer[SMALLBUF]; @@ -1874,8 +1797,7 @@ time_strftime(time, format) */ static VALUE -time_s_times(obj) - VALUE obj; +time_s_times(VALUE obj) { rb_warn("obsolete method Time::times; use Process::times"); return rb_proc_times(obj); @@ -1886,8 +1808,7 @@ time_s_times(obj) */ static VALUE -time_mdump(time) - VALUE time; +time_mdump(VALUE time) { struct time_object *tobj; struct tm *tm; @@ -1934,10 +1855,7 @@ time_mdump(time) */ static VALUE -time_dump(argc, argv, time) - int argc; - VALUE *argv; - VALUE time; +time_dump(int argc, VALUE *argv, VALUE time) { VALUE str; @@ -1953,8 +1871,7 @@ time_dump(argc, argv, time) */ static VALUE -time_mload(time, str) - VALUE time, str; +time_mload(VALUE time, VALUE str) { struct time_object *tobj; unsigned long p, s; @@ -2014,8 +1931,7 @@ time_mload(time, str) */ static VALUE -time_load(klass, str) - VALUE klass, str; +time_load(VALUE klass, VALUE str) { VALUE time = time_s_alloc(klass); @@ -2043,7 +1959,7 @@ time_load(klass, str) */ void -Init_Time() +Init_Time(void) { rb_cTime = rb_define_class("Time", rb_cObject); rb_include_module(rb_cTime, rb_mComparable); -- cgit v1.2.3