]> git.imager.perl.org - imager.git/blobdiff - iolayer.c
the PERL_INITIALIZE_IMAGER_PERL_CALLBACKS was checking the wrong version number
[imager.git] / iolayer.c
index 9d1b1afb4fe48b708d24e2ee62c03f306638b899..5f499762c409b4b7fcb9b80510dfd3b075d113fa 100644 (file)
--- a/iolayer.c
+++ b/iolayer.c
@@ -9,6 +9,7 @@
 #endif
 #include <string.h>
 #include <errno.h>
+#include "imageri.h"
 
 #define IOL_DEB(x)
 
@@ -57,8 +58,8 @@ typedef struct {
   off_t cpos;                  /* Offset within the current */
 } io_ex_buffer;
 
-static void io_obj_setp_buffer(io_obj *io, char *p, size_t len, closebufp closecb, void *closedata);
-static void io_obj_setp_cb2     (io_obj *io, void *p, readl readcb, writel writecb, seekl seekcb, closel closecb, destroyl destroycb);
+static void io_obj_setp_buffer(io_obj *io, char *p, size_t len, i_io_closebufp_t closecb, void *closedata);
+static void io_obj_setp_cb2     (io_obj *io, void *p, i_io_readl_t readcb, i_io_writel_t writecb, i_io_seekl_t seekcb, i_io_closel_t closecb, i_io_destroyl_t destroycb);
 
 /* turn current offset, file length, whence and offset into a new offset */
 #define calc_seek_offset(curr_off, length, offset, whence) \
@@ -113,7 +114,7 @@ Some of these functions are internal.
 static ssize_t fd_read(io_glue *ig, void *buf, size_t count);
 static ssize_t fd_write(io_glue *ig, const void *buf, size_t count);
 static off_t fd_seek(io_glue *ig, off_t offset, int whence);
-static void fd_close(io_glue *ig);
+static int fd_close(io_glue *ig);
 static ssize_t fd_size(io_glue *ig);
 static const char *my_strerror(int err);
 
@@ -157,8 +158,8 @@ realseek_read(io_glue *ig, void *buf, size_t count) {
   size_t        bc = 0;
   char       *cbuf = buf;
 
-  IOL_DEB( printf("realseek_read: fd = %d, ier->cpos = %ld, buf = %p, "
-                  "count = %d\n", fd, (long) ier->cpos, buf, count) );
+  IOL_DEB( printf("realseek_read:  buf = %p, count = %d\n", 
+                 buf, count) );
   /* Is this a good idea? Would it be better to handle differently?
      skip handling? */
   while( count!=bc && (rc = ig->source.cb.readcb(p,cbuf+bc,count-bc))>0 ) {
@@ -167,7 +168,7 @@ realseek_read(io_glue *ig, void *buf, size_t count) {
   
   ier->cpos += bc;
   IOL_DEB( printf("realseek_read: rc = %d, bc = %d\n", rc, bc) );
-  return bc;
+  return rc < 0 ? rc : bc;
 }
 
 
@@ -203,7 +204,7 @@ realseek_write(io_glue *ig, const void *buf, size_t count) {
 
   ier->cpos += bc;
   IOL_DEB( printf("realseek_write: rc = %d, bc = %d\n", rc, bc) );
-  return bc;
+  return rc < 0 ? rc : bc;
 }
 
 
@@ -218,11 +219,13 @@ actual close or not.  Does nothing for now.  Should be fixed.
 =cut */
 
 static
-void
+int
 realseek_close(io_glue *ig) {
   mm_log((1, "realseek_close(ig %p)\n", ig));
   if (ig->source.cb.closecb)
-    ig->source.cb.closecb(ig->source.cb.p);
+    return ig->source.cb.closecb(ig->source.cb.p);
+  else
+    return 0;
 }
 
 
@@ -284,7 +287,7 @@ ssize_t
 buffer_read(io_glue *ig, void *buf, size_t count) {
   io_ex_buffer *ieb = ig->exdata;
 
-  IOL_DEB( printf("buffer_read: fd = %d, ier->cpos = %ld, buf = %p, count = %d\n", fd, (long) ier->cpos, buf, count) );
+  IOL_DEB( printf("buffer_read: ieb->cpos = %ld, buf = %p, count = %d\n", (long) ieb->cpos, buf, count) );
 
   if ( ieb->cpos+count > ig->source.buffer.len ) {
     mm_log((1,"buffer_read: short read: cpos=%d, len=%d, count=%d\n", ieb->cpos, ig->source.buffer.len));
@@ -293,7 +296,7 @@ buffer_read(io_glue *ig, void *buf, size_t count) {
   
   memcpy(buf, ig->source.buffer.data+ieb->cpos, count);
   ieb->cpos += count;
-  IOL_DEB( printf("buffer_read: rc = %d, count = %d\n", rc, count) );
+  IOL_DEB( printf("buffer_read: count = %d\n", count) );
   return count;
 }
 
@@ -330,10 +333,11 @@ or not.  Does nothing for now.  Should be fixed.
 */
 
 static
-void
+int
 buffer_close(io_glue *ig) {
   mm_log((1, "buffer_close(ig %p)\n", ig));
-  /* FIXME: Do stuff here */
+
+  return 0;
 }
 
 
@@ -684,12 +688,12 @@ or not.  Does nothing for now.  Should be fixed.
 */
 
 static
-void
+int
 bufchain_close(io_glue *ig) {
   mm_log((1, "bufchain_close(ig %p)\n",ig));
   IOL_DEB( printf("bufchain_close(ig %p)\n", ig) );
-  /* FIXME: Commit a seek point here */
-  
+
+  return 0;  
 }
 
 
@@ -758,7 +762,7 @@ bufchain_seek(io_glue *ig, off_t offset, int whence) {
       ssize_t rc, wl = i_min(wrlen, BBSIZ);
       mm_log((1, "bufchain_seek: wrlen = %d, wl = %d\n", wrlen, wl));
       rc = bufchain_write( ig, TB, wl );
-      if (rc != wl) m_fatal(0, "bufchain_seek: Unable to extend file\n");
+      if (rc != wl) i_fatal(0, "bufchain_seek: Unable to extend file\n");
       wrlen -= rc;
     }
   }
@@ -794,7 +798,7 @@ Sets an io_object for reading from a buffer source
 */
 
 static void
-io_obj_setp_buffer(io_obj *io, char *p, size_t len, closebufp closecb, 
+io_obj_setp_buffer(io_obj *io, char *p, size_t len, i_io_closebufp_t closecb, 
                   void *closedata) {
   io->buffer.type      = BUFFER;
   io->buffer.data      = p;
@@ -822,7 +826,7 @@ Sets an io_object for reading from a source that uses callbacks
 */
 
 static void
-io_obj_setp_cb2(io_obj *io, void *p, readl readcb, writel writecb, seekl seekcb, closel closecb, destroyl destroycb) {
+io_obj_setp_cb2(io_obj *io, void *p, i_io_readl_t readcb, i_io_writel_t writecb, i_io_seekl_t seekcb, i_io_closel_t closecb, i_io_destroyl_t destroycb) {
   io->cb.type      = CBSEEK;
   io->cb.p         = p;
   io->cb.readcb    = readcb;
@@ -936,7 +940,7 @@ from specified buffer.  Note that the buffer is not copied.
 */
 
 io_glue *
-io_new_buffer(char *data, size_t len, closebufp closecb, void *closedata) {
+io_new_buffer(char *data, size_t len, i_io_closebufp_t closecb, void *closedata) {
   io_glue *ig;
   io_ex_buffer *ieb = mymalloc(sizeof(io_ex_buffer));
   
@@ -997,8 +1001,9 @@ io_new_fd(int fd) {
   return ig;
 }
 
-io_glue *io_new_cb(void *p, readl readcb, writel writecb, seekl seekcb, 
-                   closel closecb, destroyl destroycb) {
+io_glue *io_new_cb(void *p, i_io_readl_t readcb, i_io_writel_t writecb, 
+                  i_io_seekl_t seekcb, i_io_closel_t closecb, 
+                  i_io_destroyl_t destroycb) {
   io_glue *ig;
   io_ex_rseek *ier = mymalloc(sizeof(io_ex_rseek));
 
@@ -1045,7 +1050,7 @@ io_slurp(io_glue *ig, unsigned char **c) {
   io_type inn = ig->source.type;
   
   if ( inn != BUFCHAIN ) {
-    m_fatal(0, "io_slurp: called on a source that is not from a bufchain\n");
+    i_fatal(0, "io_slurp: called on a source that is not from a bufchain\n");
   }
 
   ieb = ig->exdata;
@@ -1058,7 +1063,7 @@ io_slurp(io_glue *ig, unsigned char **c) {
   rc = bufchain_read(ig, cc, ieb->length);
 
   if (rc != ieb->length)
-    m_fatal(1, "io_slurp: bufchain_read returned an incomplete read: rc = %d, request was %d\n", rc, ieb->length);
+    i_fatal(1, "io_slurp: bufchain_read returned an incomplete read: rc = %d, request was %d\n", rc, ieb->length);
 
   return rc;
 }
@@ -1114,8 +1119,9 @@ static off_t fd_seek(io_glue *ig, off_t offset, int whence) {
   return result;
 }
 
-static void fd_close(io_glue *ig) {
+static int fd_close(io_glue *ig) {
   /* no, we don't close it */
+  return 0;
 }
 
 static ssize_t fd_size(io_glue *ig) {