]> git.imager.perl.org - imager.git/blobdiff - iolayer.c
avoid a possible sign-extension for offsets/sizes in SGI
[imager.git] / iolayer.c
index c7f4f4b0d992cb38cad7b85b4e43e9525c6c1f1a..3bc9979acebc59034df880f83e83a651179531a4 100644 (file)
--- a/iolayer.c
+++ b/iolayer.c
@@ -12,8 +12,6 @@
 #include <errno.h>
 #include "imageri.h"
 
-#define dIMCTXio(io) dIMCTXctx((io)->context)
-
 #define IOL_DEB(x)
 #define IOL_DEBs stderr
 
@@ -156,13 +154,16 @@ static void bufchain_destroy(io_glue *ig);
  */
 
 /*
-=item io_new_bufchain(ctx)
+=item im_io_new_bufchain(ctx)
+X<im_io_new_bufchain API>X<i_io_new_bufchain API>
 =order 10
 =category I/O Layers
 
-returns a new io_glue object that has the 'empty' source and but can
+Returns a new io_glue object that has the 'empty' source and but can
 be written to and read from later (like a pseudo file).
 
+Also callable as C<io_new_bufchain()>.
+
 =cut
 */
 
@@ -197,16 +198,20 @@ im_io_new_bufchain(pIMCTX) {
 }
 
 /*
-=item io_new_buffer(data, length)
+=item im_io_new_buffer(ctx, data, length)
+X<im_io_new_buffer API>X<io_new_buffer API>
 =order 10
 =category I/O Layers
 
 Returns a new io_glue object that has the source defined as reading
 from specified buffer.  Note that the buffer is not copied.
 
+   ctx - an Imager context object
    data - buffer to read from
    length - length of buffer
 
+Also callable as C<io_new_buffer(data, length>.
+
 =cut
 */
 
@@ -236,15 +241,19 @@ im_io_new_buffer(pIMCTX, const char *data, size_t len, i_io_closebufp_t closecb,
 
 
 /*
-=item io_new_fd(fd)
+=item im_io_new_fd(ctx, file)
+X<io_new_fd API>X<im_io_new_fd API>
 =order 10
 =category I/O Layers
 
-returns a new io_glue object that has the source defined as reading
-from specified file descriptor.  Note that the the interface to receiving
+Returns a new io_glue object that has the source defined as reading
+from specified file descriptor.  Note that the interface to receiving
 data from the io_glue callbacks hasn't been done yet.
 
-   fd - file descriptor to read/write from
+  ctx - and Imager context object
+  file - file descriptor to read/write from
+
+Also callable as C<io_new_fd(file)>.
 
 =cut
 */
@@ -270,7 +279,8 @@ im_io_new_fd(pIMCTX, int fd) {
 }
 
 /*
-=item io_new_cb(p, read_cb, write_cb, seek_cb, close_cb, destroy_cb)
+=item im_io_new_cb(ctx, p, read_cb, write_cb, seek_cb, close_cb, destroy_cb)
+X<im_io_new_cb API>X<io_new_cb API>
 =category I/O Layers
 =order 10
 
@@ -308,6 +318,9 @@ handlers.
 
 =back
 
+Also callable as C<io_new_cb(p, readcb, writecb, seekcb, closecb,
+destroycb)>.
+
 =cut
 */
 
@@ -341,6 +354,7 @@ im_io_new_cb(pIMCTX, void *p, i_io_readl_t readcb, i_io_writel_t writecb,
 
 /*
 =item io_slurp(ig, c)
+X<io_slurp API>
 =category I/O Layers
 
 Takes the source that the io_glue is bound to and allocates space for
@@ -365,32 +379,33 @@ from io_new_bufchain().
 size_t
 io_slurp(io_glue *ig, unsigned char **c) {
   ssize_t rc;
-  off_t orgoff;
   io_ex_bchain *ieb;
   unsigned char *cc;
   io_type inn = ig->type;
   
   if ( inn != BUFCHAIN ) {
-    i_fatal(0, "io_slurp: called on a source that is not from a bufchain\n");
+    dIMCTXio(ig);
+    im_fatal(aIMCTX, 0, "io_slurp: called on a source that is not from a bufchain\n");
   }
 
   ieb = ig->exdata;
   cc = *c = mymalloc( ieb->length );
   
-  orgoff = ieb->gpos;
-  
   bufchain_seek(ig, 0, SEEK_SET);
   
   rc = bufchain_read(ig, cc, ieb->length);
 
-  if (rc != ieb->length)
-    i_fatal(1, "io_slurp: bufchain_read returned an incomplete read: rc = %d, request was %d\n", rc, ieb->length);
+  if (rc != ieb->length) {
+    dIMCTXio(ig);
+    im_fatal(aIMCTX,1, "io_slurp: bufchain_read returned an incomplete read: rc = %d, request was %d\n", rc, ieb->length);
+  }
 
   return rc;
 }
 
 /*
 =item io_glue_destroy(ig)
+X<io_glue_destroy API>
 =category I/O Layers
 =order 90
 =synopsis io_glue_destroy(ig);
@@ -1169,6 +1184,9 @@ i_io_read_fill(io_glue *ig, ssize_t needed) {
     work = ig->buffer;
   }
 
+  /* there should always be buffer space the first time around, but
+     avoid a compiler warning here */
+  rc = -1;
   while (work < buf_end && (rc = i_io_raw_read(ig, work, buf_end - work)) > 0) {
     work += rc;
     good = 1;
@@ -1354,7 +1372,8 @@ realseek_close(io_glue *igo) {
 }
 
 
-/* realseek_seek(ig, offset, whence)
+/*
+=item realseek_seek(ig, offset, whence)
 
 Implements seeking for a source that is seekable, the purpose of having this is to be able to
 have an offset into a file that is different from what the underlying library thinks.
@@ -1467,7 +1486,8 @@ buffer_close(io_glue *ig) {
 }
 
 
-/* buffer_seek(ig, offset, whence)
+/*
+=item buffer_seek(ig, offset, whence)
 
 Implements seeking for a buffer source.
 
@@ -1822,7 +1842,8 @@ bufchain_close(io_glue *ig) {
 }
 
 
-/* bufchain_seek(ig, offset, whence)
+/*
+=item bufchain_seek(ig, offset, whence)
 
 Implements seeking for a source that is seekable, the purpose of having this is to be able to
 have an offset into a file that is different from what the underlying library thinks.
@@ -1888,7 +1909,7 @@ bufchain_seek(io_glue *ig, off_t offset, int whence) {
       ssize_t rc, wl = i_min(wrlen, BBSIZ);
       im_log((aIMCTX, 1, "bufchain_seek: wrlen = %d, wl = %ld\n", wrlen, (long)wl));
       rc = bufchain_write( ig, TB, wl );
-      if (rc != wl) i_fatal(0, "bufchain_seek: Unable to extend file\n");
+      if (rc != wl) im_fatal(aIMCTX, 0, "bufchain_seek: Unable to extend file\n");
       wrlen -= rc;
     }
   }