about summary refs log tree commit homepage
path: root/ext/kgio/tryopen.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-08-16 01:52:15 +0000
committerEric Wong <normalperson@yhbt.net>2013-08-16 01:57:04 +0000
commit9f30805bc4ff65ad4ca0be9dfb26b1a9bdc70c51 (patch)
treec974cbd69173710607707545817b66883c5b650f /ext/kgio/tryopen.c
parent8be51237720fd18cb45188f29c717bbac0ca1964 (diff)
downloadkgio-9f30805bc4ff65ad4ca0be9dfb26b1a9bdc70c51.tar.gz
check syscall returns against < 0 instead of == -1
This may help us avoid errors in case of C library bugs,
and also results in smaller code:

$ ~/linux/scripts/bloat-o-meter before.so after.so
add/remove: 0/0 grow/shrink: 0/9 up/down: 0/-66 (-66)
function                                     old     new   delta
s_trywrite                                   160     159      -1
kgio_write                                   160     159      -1
kgio_trywrite                                160     159      -1
my_recv                                      616     610      -6
my_peek                                      616     610      -6
stream_connect                               456     448      -8
my_socket                                    222     213      -9
my_writev                                   1703    1687     -16
write_check                                  427     409     -18
Diffstat (limited to 'ext/kgio/tryopen.c')
-rw-r--r--ext/kgio/tryopen.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/ext/kgio/tryopen.c b/ext/kgio/tryopen.c
index 0ee6a54..5fa6ada 100644
--- a/ext/kgio/tryopen.c
+++ b/ext/kgio/tryopen.c
@@ -106,7 +106,7 @@ static VALUE s_tryopen(int argc, VALUE *argv, VALUE klass)
 
 retry:
         fd = (int)rb_thread_blocking_region(nogvl_open, &o, RUBY_UBF_IO, 0);
-        if (fd == -1) {
+        if (fd < 0) {
                 if (errno == EMFILE || errno == ENFILE || errno == ENOMEM) {
                         rb_gc();
                         if (retried)
@@ -114,7 +114,7 @@ retry:
                         retried = 1;
                         goto retry;
                 }
-                if (fd == -1) {
+                if (fd < 0) {
                         int saved_errno = errno;
 
                         if (!st_lookup(errno2sym, (st_data_t)errno, &rv)) {