about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-05-09 13:45:28 -0700
committerEric Wong <normalperson@yhbt.net>2011-05-09 13:46:48 -0700
commit7a7ea76be30e212c35132829959c0b57e5acb621 (patch)
tree921a887ec47119b07798452075d1d65d0b21e676
parentc797cea2cdddbbc5534be54ac37d95d0c8af6e61 (diff)
downloadruby_io_splice-7a7ea76be30e212c35132829959c0b57e5acb621.tar.gz
Easier to read this way since it matches upstream
functions.
-rw-r--r--ext/io_splice/io_splice_ext.c61
1 files changed, 37 insertions, 24 deletions
diff --git a/ext/io_splice/io_splice_ext.c b/ext/io_splice/io_splice_ext.c
index 1181797..a1f511c 100644
--- a/ext/io_splice/io_splice_ext.c
+++ b/ext/io_splice/io_splice_ext.c
@@ -37,6 +37,19 @@ static VALUE sym_EAGAIN;
 #  endif
 #endif
 
+#ifndef SSIZET2NUM
+#  define SSIZET2NUM(x) LONG2NUM(x)
+#endif
+#ifndef NUM2SSIZET
+#  define NUM2SSIZET(x) NUM2LONG(x)
+#endif
+#ifndef SIZET2NUM
+#  define SIZET2NUM(x) ULONG2NUM(x)
+#endif
+#ifndef NUM2SIZET
+#  define NUM2SIZET(x) NUM2ULONG(x)
+#endif
+
 static int my_fileno(VALUE io)
 {
         rb_io_t *fptr;
@@ -120,25 +133,25 @@ static VALUE nogvl_splice(void *ptr)
                              a->len, a->flags);
 }
 
-static long do_splice(int argc, VALUE *argv, unsigned dflags)
+static ssize_t do_splice(int argc, VALUE *argv, unsigned dflags)
 {
         off_t i, o;
         VALUE fd_in, off_in, fd_out, off_out, len, flags;
         struct splice_args a;
-        long bytes;
+        ssize_t bytes;
 
         rb_scan_args(argc, argv, "51",
                      &fd_in, &off_in, &fd_out, &off_out, &len, &flags);
 
         a.off_in = NIL_P(off_in) ? NULL : (i = NUM2OFFT(off_in), &i);
         a.off_out = NIL_P(off_out) ? NULL : (o = NUM2OFFT(off_out), &o);
-        a.len = (size_t)NUM2ULONG(len);
+        a.len = NUM2SIZET(len);
         a.flags = NIL_P(flags) ? dflags : NUM2UINT(flags) | dflags;
 
         do {
                 a.fd_in = check_fileno(fd_in);
                 a.fd_out = check_fileno(fd_out);
-                bytes = (long)io_run(nogvl_splice, &a);
+                bytes = (ssize_t)io_run(nogvl_splice, &a);
         } while (bytes == -1 && errno == EINTR);
 
         return bytes;
@@ -188,13 +201,13 @@ static long do_splice(int argc, VALUE *argv, unsigned dflags)
  */
 static VALUE my_splice(int argc, VALUE *argv, VALUE self)
 {
-        long n = do_splice(argc, argv, 0);
+        ssize_t n = do_splice(argc, argv, 0);
 
         if (n == 0)
                 rb_eof_error();
-        if (n < 0)
+        if (n == -1)
                 rb_sys_fail("splice");
-        return LONG2NUM(n);
+        return SSIZET2NUM(n);
 }
 
 /*
@@ -212,16 +225,16 @@ static VALUE my_splice(int argc, VALUE *argv, VALUE self)
  */
 static VALUE trysplice(int argc, VALUE *argv, VALUE self)
 {
-        long n = do_splice(argc, argv, SPLICE_F_NONBLOCK);
+        ssize_t n = do_splice(argc, argv, SPLICE_F_NONBLOCK);
 
         if (n == 0)
                 return Qnil;
-        if (n < 0) {
+        if (n == -1) {
                 if (errno == EAGAIN)
                         return sym_EAGAIN;
                 rb_sys_fail("splice");
         }
-        return LONG2NUM(n);
+        return SSIZET2NUM(n);
 }
 
 struct tee_args {
@@ -239,20 +252,20 @@ static VALUE nogvl_tee(void *ptr)
         return (VALUE)tee(a->fd_in, a->fd_out, a->len, a->flags);
 }
 
-static long do_tee(int argc, VALUE *argv, unsigned dflags)
+static ssize_t do_tee(int argc, VALUE *argv, unsigned dflags)
 {
         VALUE fd_in, fd_out, len, flags;
         struct tee_args a;
-        long bytes;
+        ssize_t bytes;
 
         rb_scan_args(argc, argv, "31", &fd_in, &fd_out, &len, &flags);
-        a.len = (size_t)NUM2ULONG(len);
+        a.len = (size_t)NUM2SIZET(len);
         a.flags = NIL_P(flags) ? dflags : NUM2UINT(flags) | dflags;
 
         do {
                 a.fd_in = check_fileno(fd_in);
                 a.fd_out = check_fileno(fd_out);
-                bytes = (long)io_run(nogvl_tee, &a);
+                bytes = (ssize_t)io_run(nogvl_tee, &a);
         } while (bytes == -1 && errno == EINTR);
 
         return bytes;
@@ -283,14 +296,14 @@ static long do_tee(int argc, VALUE *argv, unsigned dflags)
  */
 static VALUE my_tee(int argc, VALUE *argv, VALUE self)
 {
-        long n = do_tee(argc, argv, 0);
+        ssize_t n = do_tee(argc, argv, 0);
 
         if (n == 0)
                 rb_eof_error();
-        if (n < 0)
+        if (n == -1)
                 rb_sys_fail("tee");
 
-        return LONG2NUM(n);
+        return SSIZET2NUM(n);
 }
 
 /*
@@ -308,17 +321,17 @@ static VALUE my_tee(int argc, VALUE *argv, VALUE self)
  */
 static VALUE trytee(int argc, VALUE *argv, VALUE self)
 {
-        long n = do_tee(argc, argv, SPLICE_F_NONBLOCK);
+        ssize_t n = do_tee(argc, argv, SPLICE_F_NONBLOCK);
 
         if (n == 0)
                 return Qnil;
-        if (n < 0) {
+        if (n == -1) {
                 if (errno == EAGAIN)
                         return sym_EAGAIN;
                 rb_sys_fail("tee");
         }
 
-        return LONG2NUM(n);
+        return SSIZET2NUM(n);
 }
 
 struct vmsplice_args {
@@ -411,7 +424,7 @@ static void advance_vmsplice_args(struct vmsplice_args *a, long n)
  */
 static VALUE my_vmsplice(int argc, VALUE * argv, VALUE self)
 {
-        long rv = 0;
+        ssize_t rv = 0;
         ssize_t left;
         struct vmsplice_args a;
         VALUE fd, data, flags;
@@ -440,9 +453,9 @@ static VALUE my_vmsplice(int argc, VALUE * argv, VALUE self)
         a.flags = NIL_P(flags) ? 0 : NUM2UINT(flags);
 
         for (;;) {
-                long n = (long)io_run(nogvl_vmsplice, &a);
+                ssize_t n = (ssize_t)io_run(nogvl_vmsplice, &a);
 
-                if (n < 0) {
+                if (n == -1) {
                         if (errno == EAGAIN) {
                                 if (a.flags & SPLICE_F_NONBLOCK) {
                                         rb_sys_fail("vmsplice");
@@ -474,7 +487,7 @@ static VALUE my_vmsplice(int argc, VALUE * argv, VALUE self)
                 advance_vmsplice_args(&a, n);
         }
 
-        return LONG2NUM(rv);
+        return SSIZET2NUM(rv);
 }
 
 /*