summaryrefslogtreecommitdiff
path: root/time.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-12-04 04:53:31 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-12-04 04:53:31 +0000
commitdc6de95cf2f61f3c2dd11b85d67894dbb208b2ec (patch)
tree4755b13166d7e50d7c4f01d0b44a79f8dce4dc8c /time.c
parent2db0bdd9c0bf9e63708400d4bb8c5e8890e21bb3 (diff)
* io.c (io_fread): EAGAIN/EWOULDBLOCK should not terminate and
throw away the input. * time.c (time_new_internal): underflow adjustment must not use negative div/mod. * time.c (time_cmp): should consider tv_usec on non Fixnum number comparison. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@1884 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r--time.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/time.c b/time.c
index 5464499eca..e6809e16f0 100644
--- a/time.c
+++ b/time.c
@@ -91,9 +91,9 @@ time_new_internal(klass, sec, usec)
sec += usec / 1000000;
usec %= 1000000;
}
- if (usec < 0) { /* usec underflow */
- sec -= (-usec) / 1000000;
- usec %= 1000000;
+ while (usec < 0) { /* usec underflow */
+ sec--;
+ usec += 1000000;
}
if (sec < 0 || (sec == 0 && usec < 0))
rb_raise(rb_eArgError, "time must be positive");
@@ -501,7 +501,13 @@ time_cmp(time1, time2)
return INT2FIX(-1);
}
i = NUM2LONG(time2);
- if (tobj1->tv.tv_sec == i) return INT2FIX(0);
+ if (tobj1->tv.tv_sec == i) {
+ if (tobj1->tv.tv_usec == 0)
+ return INT2FIX(0);
+ if (tobj1->tv.tv_usec > 0)
+ return INT2FIX(1);
+ return INT2FIX(-1);
+ }
if (tobj1->tv.tv_sec > i) return INT2FIX(1);
return INT2FIX(-1);
}
@@ -914,7 +920,7 @@ rb_strftime(buf, format, time)
* if the buffer is 1024 times bigger than the length of the
* format string, it's not failing for lack of room.
*/
- if (len > 0 || len >= 1024 * flen) return len;
+ if (len > 0 || size >= 1024 * flen) return len;
free(*buf);
}
/* not reached */
@@ -950,7 +956,10 @@ time_strftime(time, format)
p += strlen(p) + 1;
if (p <= pe)
rb_str_cat(str, "\0", 1);
- if (len > SMALLBUF) free(buf);
+ if (buf != buffer) {
+ free(buf);
+ buf = buffer;
+ }
}
return str;
}