pdf-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[pdf-devel] Missing stream backend error conditions.


From: gerel
Subject: [pdf-devel] Missing stream backend error conditions.
Date: Mon, 18 May 2009 16:44:15 -0300

Hi,

After modifying the Fsys API I noticed that stream backends considered an EOF
and an error as the same thing (i.e. zero-length write/read).  I attach a patch
to distinguish one from the other.

BTW, the pdf-stm.c file was DOS encoded so diff made a complete new file
although changes were only made to the 'pdf_stm_flush()' function.

-gerel

##
# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: address@hidden
# target_branch: file:///home/gerel/PROJECTS/libgnupdf/trunk/
# testament_sha1: 67f5d91d3a742545d61a5b4a11854d30aefd8d10
# timestamp: 2009-05-18 16:42:16 -0300
# base_revision_id: address@hidden
# 
# Begin patch
=== modified file 'ChangeLog'
--- ChangeLog   2009-05-18 13:36:47 +0000
+++ ChangeLog   2009-05-18 19:20:19 +0000
@@ -1,3 +1,13 @@
+2009-05-18  Gerardo E. Gidoni  <address@hidden>
+
+       * src/base/pdf-stm-be.c: added missing backend error conditions.
+
+       * src/base/pdf-stm-be.h: likewise.
+
+       * src/base/pdf-stm-filter.c: likewise.
+
+       * src/base/pdf-stm.c: likewise.
+
 2009-05-18  Jose E. Marchesi  <address@hidden>
 
        * doc/gnupdf.texi (Architectural limits): Typo fixed. Reported by

=== modified file 'src/base/pdf-stm-be.c'
--- src/base/pdf-stm-be.c       2009-05-15 17:55:40 +0000
+++ src/base/pdf-stm-be.c       2009-05-18 19:20:19 +0000
@@ -1,4 +1,4 @@
-/* -*- mode: C -*- Time-stamp: "2009-05-15 13:44:30 gerel"
+/* -*- mode: C -*- Time-stamp: "2009-05-18 14:38:39 gerel"
  *
  *       File:         pdf-stm-be.c
  *       Date:         Wed Jun 18 21:15:16 2008
@@ -9,6 +9,7 @@
 
 #include <config.h>
 #include <string.h>
+#include <errno.h>
 #include <pdf-stm-be.h>
 
 /* Forward declarations */
@@ -22,21 +23,28 @@
 static pdf_off_t pdf_stm_be_mem_seek (pdf_stm_be_t be,
                                       pdf_off_t pos);
 static pdf_off_t pdf_stm_be_mem_tell (pdf_stm_be_t be);
-static pdf_size_t pdf_stm_be_file_read (pdf_stm_be_t be,
-                                        pdf_char_t *buffer,
-                                        pdf_size_t bytes);
-static pdf_size_t pdf_stm_be_file_write (pdf_stm_be_t be,
-                                         pdf_char_t *buffer,
-                                         pdf_size_t bytes);
+
+static pdf_status_t pdf_stm_be_file_read (pdf_stm_be_t be,
+                                          pdf_char_t *buffer,
+                                          pdf_size_t bytes,
+                                          pdf_size_t *read_bytes);
+
+static pdf_status_t pdf_stm_be_file_write (pdf_stm_be_t be,
+                                           pdf_char_t *buffer,
+                                           pdf_size_t bytes,
+                                           pdf_size_t *written_bytes);
+
 static pdf_off_t pdf_stm_be_file_seek (pdf_stm_be_t be,
                                        pdf_off_t pos);
 static pdf_off_t pdf_stm_be_file_tell (pdf_stm_be_t be);
-static pdf_size_t pdf_stm_be_cfile_read (pdf_stm_be_t be,
-                                        pdf_char_t *buffer,
-                                        pdf_size_t bytes);
-static pdf_size_t pdf_stm_be_cfile_write (pdf_stm_be_t be,
-                                         pdf_char_t *buffer,
-                                         pdf_size_t bytes);
+static pdf_status_t pdf_stm_be_cfile_read (pdf_stm_be_t be,
+                                           pdf_char_t *buffer,
+                                           pdf_size_t bytes,
+                                           pdf_size_t * read_bytes);
+static pdf_status_t pdf_stm_be_cfile_write (pdf_stm_be_t be,
+                                            pdf_char_t *buffer,
+                                            pdf_size_t bytes,
+                                            pdf_size_t * written_bytes);
 static pdf_off_t pdf_stm_be_cfile_seek (pdf_stm_be_t be,
                                        pdf_off_t pos);
 static pdf_off_t pdf_stm_be_cfile_tell (pdf_stm_be_t be);
@@ -113,86 +121,91 @@
   return PDF_OK;
 }
 
-pdf_size_t
+pdf_status_t
 pdf_stm_be_read (pdf_stm_be_t be,
                  pdf_char_t *buffer,
-                 pdf_size_t bytes)
+                 pdf_size_t bytes,
+                 pdf_size_t *read_bytes)
 {
-  pdf_size_t readed_bytes;
-
+  pdf_status_t ret = PDF_OK;
   switch (be->type)
     {
     case PDF_STM_BE_MEM:
       {
-        readed_bytes = pdf_stm_be_mem_read (be,
-                                            buffer,
-                                            bytes);
+        *read_bytes = pdf_stm_be_mem_read (be,
+                                           buffer,
+                                           bytes);
         break;
       }
     case PDF_STM_BE_FILE:
       {
-        readed_bytes = pdf_stm_be_file_read (be,
-                                             buffer,
-                                             bytes);
+        ret = pdf_stm_be_file_read (be,
+                                    buffer,
+                                    bytes,
+                                    read_bytes);
         break;
       }
     case PDF_STM_BE_CFILE:
       {
-        readed_bytes = pdf_stm_be_cfile_read (be,
-                                             buffer,
-                                             bytes);
+        ret = pdf_stm_be_cfile_read (be,
+                                     buffer,
+                                     bytes,
+                                     read_bytes);
         break;
       }
     default:
       {
         /* Uh oh */
-        readed_bytes = 0;
+        *read_bytes = 0;
         break;
       }
     }
 
-  return readed_bytes;
+  return ret;
 }
 
-pdf_size_t
+pdf_status_t
 pdf_stm_be_write (pdf_stm_be_t be,
                   pdf_char_t *buffer,
-                  pdf_size_t bytes)
+                  pdf_size_t bytes,
+                  pdf_size_t *written_bytes)
 {
-  pdf_size_t written_bytes;
+  pdf_status_t ret = PDF_OK;
 
   switch (be->type)
     {
     case PDF_STM_BE_MEM:
       {
-        written_bytes = pdf_stm_be_mem_write (be,
-                                              buffer,
-                                              bytes);
-        break;
-      }
-    case PDF_STM_BE_FILE:
-      {
-        written_bytes = pdf_stm_be_file_write (be,
+        *written_bytes = pdf_stm_be_mem_write (be,
                                                buffer,
                                                bytes);
         break;
       }
+    case PDF_STM_BE_FILE:
+      {
+        ret = pdf_stm_be_file_write (be,
+                                     buffer,
+                                     bytes,
+                                     written_bytes);
+        break;
+      }
     case PDF_STM_BE_CFILE:
       {
-        written_bytes = pdf_stm_be_cfile_write (be,
-                                               buffer,
-                                               bytes);
+        ret = pdf_stm_be_cfile_write (be,
+                                      buffer,
+                                      bytes,
+                                      written_bytes);
         break;
       }
     default:
       {
         /* Uh oh */
-        written_bytes = 0;
+        *written_bytes = 0;
         break;
       }
     }
 
-  return written_bytes;
+  return ret;
 }
 
 pdf_off_t
@@ -341,12 +354,12 @@
   return written_bytes;
 }
 
-static pdf_size_t
+static pdf_status_t
 pdf_stm_be_file_read (pdf_stm_be_t be,
                       pdf_char_t *buffer,
-                      pdf_size_t bytes)
+                      pdf_size_t bytes,
+                      pdf_size_t *read_bytes)
 {
-  pdf_size_t readed_bytes;
   pdf_size_t current_pos;
   pdf_status_t ret;
 
@@ -357,34 +370,34 @@
                              be->data.file.pos) == PDF_ERROR)
     {
       /* Bad position */
-      return 0;
+      return PDF_ERROR;
     }
 
   /* Read the requested number of bytes */
   ret = pdf_fsys_file_read (be->data.file.file,
                             buffer,
                             bytes,
-                            &readed_bytes);
+                            read_bytes);
 
   /* Restore the file position and update the position of the
      stream */
-  be->data.file.pos = be->data.file.pos + readed_bytes;
+  be->data.file.pos = be->data.file.pos + (*read_bytes);
   if (pdf_fsys_file_set_pos (be->data.file.file,
                              current_pos) == PDF_ERROR)
     {
       /* This should not happen, but just in case */
-      return 0;
+      return PDF_ERROR;
     }
 
-  return readed_bytes;
+  return ret;
 }
 
-static pdf_size_t
+static pdf_status_t
 pdf_stm_be_file_write (pdf_stm_be_t be,
                        pdf_char_t *buffer,
-                       pdf_size_t bytes)
+                       pdf_size_t bytes,
+                       pdf_size_t *written_bytes)
 {
-  pdf_size_t written_bytes;
   pdf_size_t current_pos;
   pdf_status_t ret;
 
@@ -395,26 +408,26 @@
                              be->data.file.pos) == PDF_ERROR)
     {
       /* Bad position */
-      return 0;
+      return PDF_ERROR;
     }
   
   /* Write the requested number of bytes */
   ret = pdf_fsys_file_write (be->data.file.file,
                              buffer,
                              bytes,
-                             &written_bytes);
+                             written_bytes);
   
   /* Restore the file position and update the position of the
      stream */
-  be->data.file.pos = be->data.file.pos + written_bytes;
+  be->data.file.pos = be->data.file.pos + (*written_bytes);
   if (pdf_fsys_file_set_pos (be->data.file.file,
                              current_pos) == PDF_ERROR)
     {
       /* This should not happen, but just in case */
-      return 0;
+      return PDF_ERROR;
     }
                                        
-  return written_bytes;
+  return ret;
 }
 
 static pdf_off_t
@@ -507,34 +520,56 @@
   return be->data.cfile.pos;
 }
 
-static pdf_size_t
+static pdf_status_t
 pdf_stm_be_cfile_read (pdf_stm_be_t be,
-                      pdf_char_t *buffer,
-                      pdf_size_t bytes)
+                       pdf_char_t *buffer,
+                       pdf_size_t bytes,
+                       pdf_size_t * read_bytes)
 {
-  pdf_size_t readed_bytes;
+  pdf_status_t ret = PDF_OK;
 
   /* Read the requested number of bytes */
-  readed_bytes = fread (buffer, 
-                       1, bytes,
-                       be->data.cfile.file);
+  *read_bytes = fread (buffer, 
+                       1, bytes,
+                       be->data.cfile.file);
 
-  return readed_bytes;
+  if (feof(be->data.cfile.file))
+    {
+      ret = PDF_EEOF;
+    }
+  else if (ferror(be->data.cfile.file))
+    {
+      ret = PDF_ERROR;
+    }
+  return ret;
 }
 
-static pdf_size_t
+static pdf_status_t
 pdf_stm_be_cfile_write (pdf_stm_be_t be,
                        pdf_char_t *buffer,
-                       pdf_size_t bytes)
+                       pdf_size_t bytes,
+                        pdf_size_t *written_bytes)
 {
-  pdf_size_t written_bytes;
+  pdf_status_t ret = PDF_OK;
 
   /* Write the requested number of bytes */
-  written_bytes = fwrite (buffer,
-                         1, bytes,
-                         be->data.cfile.file);
+  *written_bytes = fwrite (buffer,
+                           1, bytes,
+                           be->data.cfile.file);
   
-  return written_bytes;
+  if (ferror(be->data.cfile.file))
+    {
+      if (errno == ENOSPC)
+        {
+          ret = PDF_ENOMEM;
+        }
+      else
+        {
+          ret = PDF_ERROR;
+        }
+    }
+
+  return ret;
 }
 
 /* End of pdf-stm-be.c */

=== modified file 'src/base/pdf-stm-be.h'
--- src/base/pdf-stm-be.h       2008-11-29 16:21:37 +0000
+++ src/base/pdf-stm-be.h       2009-05-18 19:20:19 +0000
@@ -1,4 +1,4 @@
-/* -*- mode: C -*- Time-stamp: "08/11/29 15:11:39 jemarch"
+/* -*- mode: C -*- Time-stamp: "2009-05-18 13:40:59 gerel"
  *
  *       File:         pdf-stm-be.h
  *       Date:         Wed Jun 18 20:53:27 2008
@@ -70,12 +70,14 @@
                                  pdf_size_t pos);
 pdf_status_t pdf_stm_be_destroy (pdf_stm_be_t be);
 
-pdf_size_t pdf_stm_be_read (pdf_stm_be_t be,
-                            pdf_char_t *buffer,
-                            pdf_size_t bytes);
-pdf_size_t pdf_stm_be_write (pdf_stm_be_t be,
-                             pdf_char_t *buffer,
-                             pdf_size_t bytes);
+pdf_status_t pdf_stm_be_read (pdf_stm_be_t be,
+                              pdf_char_t *buffer,
+                              pdf_size_t bytes,
+                              pdf_size_t *read_bytes);
+pdf_status_t pdf_stm_be_write (pdf_stm_be_t be,
+                               pdf_char_t *buffer,
+                               pdf_size_t bytes,
+                               pdf_size_t *written_bytes);
 
 pdf_off_t pdf_stm_be_seek (pdf_stm_be_t be,
                            pdf_off_t pos);

=== modified file 'src/base/pdf-stm-filter.c'
--- src/base/pdf-stm-filter.c   2009-01-12 13:30:36 +0000
+++ src/base/pdf-stm-filter.c   2009-05-18 19:20:19 +0000
@@ -1,4 +1,4 @@
-/* -*- mode: C -*- Time-stamp: "09/01/11 22:03:18 jemarch"
+/* -*- mode: C -*- Time-stamp: "2009-05-18 14:25:30 gerel"
  *
  *       File:         pdf-stm-filter.c
  *       Date:         Thu Jun 12 22:13:31 2008
@@ -367,13 +367,18 @@
     }
   else if (filter->backend != NULL)
     {
-      read_bytes = pdf_stm_be_read (filter->backend,
-                                    filter->in->data,
-                                    filter->in->size);
-      filter->in->wp = read_bytes;
-      if (read_bytes < filter->in->size)
-        {
-          ret = PDF_EEOF;
+      ret = pdf_stm_be_read (filter->backend,
+                             filter->in->data,
+                             filter->in->size,
+                             &read_bytes);
+
+      if (ret != PDF_ERROR)
+        {        
+          filter->in->wp = read_bytes;
+          if (read_bytes < filter->in->size)
+            {
+              ret = PDF_EEOF;
+            }
         }
     }
   else

=== modified file 'src/base/pdf-stm.c'
--- src/base/pdf-stm.c  2009-02-06 00:33:22 +0000
+++ src/base/pdf-stm.c  2009-05-18 19:42:11 +0000
@@ -1,607 +1,614 @@
-/* -*- mode: C -*- Time-stamp: "09/02/06 01:31:12 jemarch"
- *
- *       File:         pdf-stm.c
- *       Date:         Fri Jul  6 18:43:15 2007
- *
- *       GNU PDF Library - Streams
- *
- */
-
-/* Copyright (C) 2007, 2008 Free Software Foundation, Inc. */
-
-/* This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <config.h>
-#include <unistd.h>
-#include <string.h>
-
-#include <pdf-alloc.h>
-#include <pdf-stm.h>
-
-/* Forward declarations */
-
-static pdf_status_t pdf_stm_init (pdf_size_t buffer_size,
-                                  enum pdf_stm_mode_e mode,
-                                  pdf_stm_t stm);
-static inline pdf_stm_t pdf_stm_alloc (void);
-static inline void pdf_stm_dealloc (pdf_stm_t stm);
-static pdf_status_t pdf_stm_read_peek_char (pdf_stm_t stm, pdf_char_t *c, 
pdf_bool_t peek_p);
-
-/*
- * Public functions
- */
-
-pdf_status_t
-pdf_stm_cfile_new (FILE* file,
-                  pdf_off_t offset,
-                  pdf_size_t cache_size,
-                  enum pdf_stm_mode_e mode,
-                  pdf_stm_t *stm)
-{
-  /* Allocate memory for the new stream */
-  *stm = pdf_stm_alloc ();
-
-  /* Initialize a file stream */
-  (*stm)->type = PDF_STM_FILE;
-  (*stm)->backend = pdf_stm_be_new_cfile (file,
-                                         offset);
-
-  /* Initialize the common parts */
-  return pdf_stm_init (cache_size,
-                       mode,
-                       *stm);
-}
-
-
-pdf_status_t
-pdf_stm_file_new (pdf_fsys_file_t file,
-                  pdf_off_t offset,
-                  pdf_size_t cache_size,
-                  enum pdf_stm_mode_e mode,
-                  pdf_stm_t *stm)
-{
-  /* Allocate memory for the new stream */
-  *stm = pdf_stm_alloc ();
-
-  /* Initialize a file stream */
-  (*stm)->type = PDF_STM_FILE;
-  (*stm)->backend = pdf_stm_be_new_file (file,
-                                         offset);
-
-  /* Initialize the common parts */
-  return pdf_stm_init (cache_size,
-                       mode,
-                       *stm);
-}
-
-pdf_status_t
-pdf_stm_mem_new (pdf_char_t *buffer,
-                 pdf_size_t size,
-                 pdf_size_t cache_size,
-                 enum pdf_stm_mode_e mode,
-                 pdf_stm_t *stm)
-{
-  /* Allocate memory for the new stream */
-  *stm = pdf_stm_alloc ();
-
-  /* Initialize a memory stream */
-  (*stm)->type = PDF_STM_MEM;
-  (*stm)->backend = pdf_stm_be_new_mem (buffer,
-                                        size,
-                                        0);
-  
-  /* Initialize the common parts */
-  return pdf_stm_init (cache_size,
-                       mode,
-                       *stm);
-}
-
-pdf_status_t
-pdf_stm_destroy (pdf_stm_t stm)
-{
-  pdf_stm_filter_t filter;
-  pdf_stm_filter_t filter_to_delete;
-  pdf_size_t flushed_bytes;
-  pdf_status_t ret;
-
-  ret = PDF_OK;
-  if (stm->mode == PDF_STM_WRITE)
-    {
-      /* Flush the cache, finishing the filters */
-      ret = pdf_stm_flush (stm, PDF_TRUE, &flushed_bytes);
-    }
-
-  /* Destroy the backend */
-  pdf_stm_be_destroy (stm->backend);
-
-  /* Destroy the cache */
-  pdf_buffer_destroy (stm->cache);
-
-  /* Destroy the filter chain */
-  filter = stm->filter;
-  while (filter != NULL)
-    {
-      filter_to_delete = filter;
-      filter = filter->next;
-      pdf_stm_filter_destroy (filter_to_delete);
-    }
-
-  /* Deallocate the stm structure */
-  pdf_stm_dealloc (stm);
-
-  return ret;
-}
-
-pdf_status_t
-pdf_stm_read (pdf_stm_t stm,
-              pdf_char_t *buf,
-              pdf_size_t bytes,
-              pdf_size_t *read_bytes)
-{
-  pdf_size_t pending_bytes;
-  pdf_size_t cache_size;
-  pdf_size_t to_copy_bytes;
-  pdf_status_t ret;
-
-  if (stm->mode != PDF_STM_READ)
-    {
-      /* Invalid operation */
-      return PDF_EINVOP;
-    }
-
-  ret = PDF_OK;
-  *read_bytes = 0;
-  while ((*read_bytes < bytes) &&
-         (ret == PDF_OK))
-    {
-      pending_bytes = bytes - *read_bytes;
-
-      /* If the cache is empty, refill it with filtered data */
-      if (pdf_buffer_eob_p (stm->cache))
-        {
-         pdf_buffer_rewind (stm->cache);
-          ret = pdf_stm_filter_apply (stm->filter, PDF_FALSE);
-        }
-
-      if (ret != PDF_ERROR)
-        {
-          /* Read data from the cache */
-          pending_bytes = bytes - *read_bytes;
-          cache_size = stm->cache->wp - stm->cache->rp;
-          to_copy_bytes = PDF_MIN(pending_bytes, cache_size);
-
-          memcpy ((char *) (buf + *read_bytes),
-                  (char *) stm->cache->data + stm->cache->rp,
-                  to_copy_bytes);
-          
-          *read_bytes += to_copy_bytes;
-          stm->cache->rp += to_copy_bytes;
-        }
-    }
-
-  if ((*read_bytes == bytes) &&
-      (ret == PDF_EEOF))
-    {
-      /* Avoid a false PDF_EEOF in the current operation */
-      ret = PDF_OK;
-    }
-
-  return ret;
-}
-
-
-pdf_status_t
-pdf_stm_write (pdf_stm_t stm,
-               pdf_char_t *buf,
-               pdf_size_t bytes,
-               pdf_size_t *written_bytes)
-{
-  pdf_status_t ret;
-  pdf_size_t pending_bytes;
-  pdf_size_t to_write_bytes;
-  pdf_stm_filter_t tail_filter;
-  pdf_buffer_t tail_buffer;
-  pdf_size_t tail_buffer_size;
-  pdf_size_t flushed_bytes;
-
-  if (stm->mode != PDF_STM_WRITE)
-    {
-      /* Invalid operation */
-      return PDF_EINVOP;
-    }
-
-  tail_filter = pdf_stm_filter_get_tail (stm->filter);
-  tail_buffer = pdf_stm_filter_get_in (tail_filter);
-
-  ret = PDF_OK;
-  *written_bytes = 0;
-  while ((*written_bytes < bytes) &&
-         (ret == PDF_OK))
-    {
-      if ((pdf_buffer_full_p (tail_buffer)) &&
-          (!pdf_buffer_eob_p (tail_buffer)))
-        {
-          /* Flush the cache */
-          tail_buffer_size = tail_buffer->wp - tail_buffer->rp;
-
-          if (pdf_stm_flush (stm, PDF_FALSE, &flushed_bytes)
-              == PDF_ERROR)
-            {
-              ret = PDF_ERROR;
-            }
-          else if (flushed_bytes < tail_buffer_size)
-            {
-              ret = PDF_EEOF;
-            }
-        }
-
-      if (ret == PDF_OK)
-        {
-          /* Write the data into the tail buffer. Note that at this
-             point the tail buffer should be empty */
-          tail_buffer_size = tail_buffer->size - tail_buffer->wp;
-          pending_bytes = bytes - *written_bytes;
-
-          to_write_bytes = PDF_MIN(pending_bytes, tail_buffer_size);
-
-          if (to_write_bytes != 0)
-            {
-              memcpy ((char *) tail_buffer->data + tail_buffer->wp,
-                      (char *) buf + *written_bytes,
-                      to_write_bytes);
-
-              *written_bytes += to_write_bytes;
-              tail_buffer->wp += to_write_bytes;
-            }
-        }
-    }
-
-  if ((*written_bytes == bytes) &&
-      (ret == PDF_EEOF))
-    {
-      /* Avoid a false PDF_EEOF in the current operation */
-      ret = PDF_OK;
-    }
-
-  
-  return ret;
-}
-
-pdf_status_t
-pdf_stm_flush (pdf_stm_t stm,
-               pdf_bool_t finish_p,
-               pdf_size_t *flushed_bytes)
-{
-  pdf_stm_filter_t tail_filter;
-  pdf_buffer_t tail_buffer;
-  pdf_status_t ret;
-  pdf_size_t cache_size;
-  pdf_size_t written_bytes;
-  pdf_size_t tail_size;
-
-  if (stm->mode != PDF_STM_WRITE)
-    {
-      /* Invalid operation */
-      return 0;
-    }
-
-  /* Apply the head filter until the filter chain gets empty */
-  tail_filter = pdf_stm_filter_get_tail (stm->filter);
-  tail_buffer = pdf_stm_filter_get_in (tail_filter);
-  *flushed_bytes = 0;
-  while (1)
-    {
-      tail_size = tail_buffer->wp - tail_buffer->rp;
-      ret = pdf_stm_filter_apply (stm->filter, finish_p);
-
-      if (ret == PDF_ERROR)
-        {
-          /* The filter chain is in error */
-          break;
-        }
-
-      /* Update the number of flushed bytes */
-      *flushed_bytes += tail_size
-        - (tail_buffer->wp - tail_buffer->rp);
-      
-      if ((ret == PDF_EEOF)
-          && (pdf_buffer_eob_p (stm->cache)))
-        {
-          pdf_buffer_rewind (tail_buffer);
-          ret = PDF_OK;
-          break;
-        }
-
-      /* Write the data from the buffer cache into the backend */
-      cache_size = stm->cache->wp - stm->cache->rp;
-      written_bytes = pdf_stm_be_write (stm->backend,
-                                        stm->cache->data + stm->cache->rp,
-                                        cache_size);
-
-      if (written_bytes != cache_size)
-        {
-          /* Could not write all the contents of the cache buffer into
-             the backend */
-          stm->cache->rp += written_bytes;
-          ret = PDF_EEOF;
-          break;
-        }
-
-      /* Rewind the cache */
-      pdf_buffer_rewind (stm->cache);
-    }
-
-  return ret;
-}
-
-pdf_status_t
-pdf_stm_install_filter (pdf_stm_t stm,
-                        enum pdf_stm_filter_type_e filter_type,
-                        pdf_hash_t filter_params)
-{
-  pdf_status_t ret;
-  pdf_stm_filter_t filter;
-  enum pdf_stm_filter_mode_e filter_mode;
-
-  if (stm->mode == PDF_STM_READ)
-    {
-      filter_mode = PDF_STM_FILTER_MODE_READ;
-    }
-  else
-    {
-      filter_mode = PDF_STM_FILTER_MODE_WRITE;
-    }
-
-  /* Create the new filter */
-  ret = pdf_stm_filter_new (filter_type,
-                            filter_params,
-                            stm->cache->size,
-                            filter_mode,
-                            &filter);
-
-  if (filter != NULL)
-    {
-      /* Set the new filter as the new head of the filter chain */
-      pdf_stm_filter_set_next (filter, stm->filter);
-      pdf_stm_filter_set_out (filter, stm->cache);
-      pdf_stm_filter_set_out (stm->filter, pdf_stm_filter_get_in (filter));
-      stm->filter = filter;
-    }
-
-  return ret;
-}
-
-pdf_status_t
-pdf_stm_read_char (pdf_stm_t stm, pdf_char_t *c)
-{
-  return pdf_stm_read_peek_char (stm, c, PDF_FALSE);
-}
-
-pdf_status_t
-pdf_stm_peek_char (pdf_stm_t stm, pdf_char_t *c)
-{
-  return pdf_stm_read_peek_char (stm, c, PDF_TRUE);
-}
-
-pdf_off_t
-pdf_stm_seek (pdf_stm_t stm,
-              pdf_off_t pos)
-{
-  pdf_off_t cur_pos;
-  pdf_off_t new_pos;
-  pdf_stm_filter_t tail_filter;
-  pdf_buffer_t tail_buffer;
-  pdf_size_t flushed_bytes;
-
-  cur_pos = pdf_stm_tell (stm);
-
-  if (stm->mode == PDF_STM_READ)
-    {
-      /* Discard the cache contents */
-      pdf_buffer_rewind (stm->cache);
-
-      /* Seek the backend */
-      new_pos = pdf_stm_be_seek (stm->backend, pos);
-    }
-  else
-    {
-      /* Writing stream */
-
-      tail_filter = pdf_stm_filter_get_tail (stm->filter);
-      tail_buffer = pdf_stm_filter_get_in (tail_filter);
-      if (!pdf_buffer_eob_p (tail_buffer))
-        {
-          /* Flush the stream */
-          if (pdf_stm_flush (stm, PDF_FALSE, &flushed_bytes)
-              == PDF_ERROR)
-            {
-              /* Error flushing the stream: return the current
-                 position */
-              return cur_pos;
-            }
-        }
-
-      /* Note that if there is an EOF condition in the backend we are
-         going to loose data */
-      pdf_buffer_rewind (tail_buffer);
-
-      /* Seek the backend */
-      new_pos = pdf_stm_be_seek (stm->backend, pos);
-    }
-
-  return new_pos;
-}
-
-pdf_off_t
-pdf_stm_tell (pdf_stm_t stm)
-{
-  pdf_off_t pos;
-  pdf_size_t cache_size;
-  pdf_stm_filter_t tail_filter;
-  pdf_buffer_t tail_buffer;
-
-  if (stm->mode == PDF_STM_READ)
-    {
-      cache_size = stm->cache->wp - stm->cache->rp;
-      pos = pdf_stm_be_tell (stm->backend) + cache_size;
-    }
-  else
-    {
-      /* Writing stream */
-
-      tail_filter = pdf_stm_filter_get_tail (stm->filter);
-      tail_buffer = pdf_stm_filter_get_in (tail_filter);
-
-      cache_size = tail_buffer->wp - tail_buffer->rp;
-      pos = pdf_stm_be_tell (stm->backend) + cache_size;
-    }
-
-  return pos;
-}
-
-/*
- * Private functions
- */
-
-static pdf_status_t
-pdf_stm_init (pdf_size_t cache_size,
-              enum pdf_stm_mode_e mode,
-              pdf_stm_t stm)
-{
-  pdf_hash_t null_filter_params;
-  enum pdf_stm_filter_mode_e filter_mode;
-  pdf_status_t ret;
-
-  if (cache_size == 0)
-    {
-      /* Use the default cache size */
-      cache_size = PDF_STM_DEFAULT_CACHE_SIZE;
-    } 
-
-  /* Initialize the null filter */
-  pdf_hash_new (NULL, &null_filter_params);
-
-  if (stm->mode == PDF_STM_READ)
-    {
-      filter_mode = PDF_STM_FILTER_MODE_READ;
-    }
-  else
-    {
-      filter_mode = PDF_STM_FILTER_MODE_WRITE;
-    }
-
-  ret = pdf_stm_filter_new (PDF_STM_FILTER_NULL,
-                            null_filter_params,
-                            cache_size,
-                            filter_mode,
-                            &(stm->filter));
-
-  if (ret == PDF_OK)
-    {
-      /* Initialize the filter cache */
-      stm->cache = pdf_buffer_new (cache_size);
-      
-      /* Configure the filter */
-      stm->mode = mode;
-      if (stm->mode == PDF_STM_READ)
-        {
-          /* Configuration for a reading stream
-           *
-           *  <cache> <--- <null-filter> <--- <backend>
-           */
-          
-          pdf_stm_filter_set_out (stm->filter, 
-                                  stm->cache);
-          pdf_stm_filter_set_be (stm->filter,
-                                 stm->backend);
-        } 
-      else
-        {
-          /* Configuration for a writing stream
-           *
-           * <null-filter> --> <cache> --> <backend>
-           */
-          
-          pdf_stm_filter_set_out (stm->filter,
-                                  stm->cache);
-        }
-    }
-
-  return ret;
-}
-
-
-static pdf_status_t
-pdf_stm_read_peek_char (pdf_stm_t stm,
-                        pdf_char_t *c,
-                        pdf_bool_t peek_p)
-{
-  pdf_status_t ret;
-
-  /* Is this a read stream? */
-  if (stm->mode != PDF_STM_READ)
-    {
-      /* Invalid operation */
-      return PDF_EINVOP;
-    }
-
-  /* Is the cache empty? */
-  ret = PDF_OK;
-  if (pdf_buffer_eob_p (stm->cache))
-    {
-      ret = pdf_stm_filter_apply (stm->filter, PDF_FALSE);
-    }
-
-  if (pdf_buffer_eob_p (stm->cache))
-    {
-      ret = PDF_EEOF;
-    }
-  else
-    {
-      /* Read a character from the cache */
-      *c = 
-        (pdf_u32_t) stm->cache->data[stm->cache->rp];
-
-      if (!peek_p)
-        {
-          stm->cache->rp++;
-        }
-
-      if (ret == PDF_EEOF)
-        {
-          /* Avoid a false PDF_EEOF */
-          ret = PDF_OK;
-        }
-    }
-  
-  return ret;
-}
-
-static inline pdf_stm_t
-pdf_stm_alloc (void)
-{
-  pdf_stm_t new;
-
-  new =  pdf_alloc (sizeof(struct pdf_stm_s));
-  return new;
-}
-
-static inline void
-pdf_stm_dealloc (pdf_stm_t stm)
-{
-  pdf_dealloc (stm);
-}
-
-/* End of pdf_stm.c */
+/* -*- mode: C -*- Time-stamp: "2009-05-18 16:42:07 gerel"
+ *
+ *       File:         pdf-stm.c
+ *       Date:         Fri Jul  6 18:43:15 2007
+ *
+ *       GNU PDF Library - Streams
+ *
+ */
+
+/* Copyright (C) 2007, 2008 Free Software Foundation, Inc. */
+
+/* This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <pdf-alloc.h>
+#include <pdf-stm.h>
+
+/* Forward declarations */
+
+static pdf_status_t pdf_stm_init (pdf_size_t buffer_size,
+                                  enum pdf_stm_mode_e mode,
+                                  pdf_stm_t stm);
+static inline pdf_stm_t pdf_stm_alloc (void);
+static inline void pdf_stm_dealloc (pdf_stm_t stm);
+static pdf_status_t pdf_stm_read_peek_char (pdf_stm_t stm, pdf_char_t *c, 
pdf_bool_t peek_p);
+
+/*
+ * Public functions
+ */
+
+pdf_status_t
+pdf_stm_cfile_new (FILE* file,
+                  pdf_off_t offset,
+                  pdf_size_t cache_size,
+                  enum pdf_stm_mode_e mode,
+                  pdf_stm_t *stm)
+{
+  /* Allocate memory for the new stream */
+  *stm = pdf_stm_alloc ();
+
+  /* Initialize a file stream */
+  (*stm)->type = PDF_STM_FILE;
+  (*stm)->backend = pdf_stm_be_new_cfile (file,
+                                         offset);
+
+  /* Initialize the common parts */
+  return pdf_stm_init (cache_size,
+                       mode,
+                       *stm);
+}
+
+
+pdf_status_t
+pdf_stm_file_new (pdf_fsys_file_t file,
+                  pdf_off_t offset,
+                  pdf_size_t cache_size,
+                  enum pdf_stm_mode_e mode,
+                  pdf_stm_t *stm)
+{
+  /* Allocate memory for the new stream */
+  *stm = pdf_stm_alloc ();
+
+  /* Initialize a file stream */
+  (*stm)->type = PDF_STM_FILE;
+  (*stm)->backend = pdf_stm_be_new_file (file,
+                                         offset);
+
+  /* Initialize the common parts */
+  return pdf_stm_init (cache_size,
+                       mode,
+                       *stm);
+}
+
+pdf_status_t
+pdf_stm_mem_new (pdf_char_t *buffer,
+                 pdf_size_t size,
+                 pdf_size_t cache_size,
+                 enum pdf_stm_mode_e mode,
+                 pdf_stm_t *stm)
+{
+  /* Allocate memory for the new stream */
+  *stm = pdf_stm_alloc ();
+
+  /* Initialize a memory stream */
+  (*stm)->type = PDF_STM_MEM;
+  (*stm)->backend = pdf_stm_be_new_mem (buffer,
+                                        size,
+                                        0);
+  
+  /* Initialize the common parts */
+  return pdf_stm_init (cache_size,
+                       mode,
+                       *stm);
+}
+
+pdf_status_t
+pdf_stm_destroy (pdf_stm_t stm)
+{
+  pdf_stm_filter_t filter;
+  pdf_stm_filter_t filter_to_delete;
+  pdf_size_t flushed_bytes;
+  pdf_status_t ret;
+
+  ret = PDF_OK;
+  if (stm->mode == PDF_STM_WRITE)
+    {
+      /* Flush the cache, finishing the filters */
+      ret = pdf_stm_flush (stm, PDF_TRUE, &flushed_bytes);
+    }
+
+  /* Destroy the backend */
+  pdf_stm_be_destroy (stm->backend);
+
+  /* Destroy the cache */
+  pdf_buffer_destroy (stm->cache);
+
+  /* Destroy the filter chain */
+  filter = stm->filter;
+  while (filter != NULL)
+    {
+      filter_to_delete = filter;
+      filter = filter->next;
+      pdf_stm_filter_destroy (filter_to_delete);
+    }
+
+  /* Deallocate the stm structure */
+  pdf_stm_dealloc (stm);
+
+  return ret;
+}
+
+pdf_status_t
+pdf_stm_read (pdf_stm_t stm,
+              pdf_char_t *buf,
+              pdf_size_t bytes,
+              pdf_size_t *read_bytes)
+{
+  pdf_size_t pending_bytes;
+  pdf_size_t cache_size;
+  pdf_size_t to_copy_bytes;
+  pdf_status_t ret;
+
+  if (stm->mode != PDF_STM_READ)
+    {
+      /* Invalid operation */
+      return PDF_EINVOP;
+    }
+
+  ret = PDF_OK;
+  *read_bytes = 0;
+  while ((*read_bytes < bytes) &&
+         (ret == PDF_OK))
+    {
+      pending_bytes = bytes - *read_bytes;
+
+      /* If the cache is empty, refill it with filtered data */
+      if (pdf_buffer_eob_p (stm->cache))
+        {
+         pdf_buffer_rewind (stm->cache);
+          ret = pdf_stm_filter_apply (stm->filter, PDF_FALSE);
+        }
+
+      if (ret != PDF_ERROR)
+        {
+          /* Read data from the cache */
+          pending_bytes = bytes - *read_bytes;
+          cache_size = stm->cache->wp - stm->cache->rp;
+          to_copy_bytes = PDF_MIN(pending_bytes, cache_size);
+
+          memcpy ((char *) (buf + *read_bytes),
+                  (char *) stm->cache->data + stm->cache->rp,
+                  to_copy_bytes);
+          
+          *read_bytes += to_copy_bytes;
+          stm->cache->rp += to_copy_bytes;
+        }
+    }
+
+  if ((*read_bytes == bytes) &&
+      (ret == PDF_EEOF))
+    {
+      /* Avoid a false PDF_EEOF in the current operation */
+      ret = PDF_OK;
+    }
+
+  return ret;
+}
+
+
+pdf_status_t
+pdf_stm_write (pdf_stm_t stm,
+               pdf_char_t *buf,
+               pdf_size_t bytes,
+               pdf_size_t *written_bytes)
+{
+  pdf_status_t ret;
+  pdf_size_t pending_bytes;
+  pdf_size_t to_write_bytes;
+  pdf_stm_filter_t tail_filter;
+  pdf_buffer_t tail_buffer;
+  pdf_size_t tail_buffer_size;
+  pdf_size_t flushed_bytes;
+
+  if (stm->mode != PDF_STM_WRITE)
+    {
+      /* Invalid operation */
+      return PDF_EINVOP;
+    }
+
+  tail_filter = pdf_stm_filter_get_tail (stm->filter);
+  tail_buffer = pdf_stm_filter_get_in (tail_filter);
+
+  ret = PDF_OK;
+  *written_bytes = 0;
+  while ((*written_bytes < bytes) &&
+         (ret == PDF_OK))
+    {
+      if ((pdf_buffer_full_p (tail_buffer)) &&
+          (!pdf_buffer_eob_p (tail_buffer)))
+        {
+          /* Flush the cache */
+          tail_buffer_size = tail_buffer->wp - tail_buffer->rp;
+
+          if (pdf_stm_flush (stm, PDF_FALSE, &flushed_bytes)
+              == PDF_ERROR)
+            {
+              ret = PDF_ERROR;
+            }
+          else if (flushed_bytes < tail_buffer_size)
+            {
+              ret = PDF_EEOF;
+            }
+        }
+
+      if (ret == PDF_OK)
+        {
+          /* Write the data into the tail buffer. Note that at this
+             point the tail buffer should be empty */
+          tail_buffer_size = tail_buffer->size - tail_buffer->wp;
+          pending_bytes = bytes - *written_bytes;
+
+          to_write_bytes = PDF_MIN(pending_bytes, tail_buffer_size);
+
+          if (to_write_bytes != 0)
+            {
+              memcpy ((char *) tail_buffer->data + tail_buffer->wp,
+                      (char *) buf + *written_bytes,
+                      to_write_bytes);
+
+              *written_bytes += to_write_bytes;
+              tail_buffer->wp += to_write_bytes;
+            }
+        }
+    }
+
+  if ((*written_bytes == bytes) &&
+      (ret == PDF_EEOF))
+    {
+      /* Avoid a false PDF_EEOF in the current operation */
+      ret = PDF_OK;
+    }
+
+  
+  return ret;
+}
+
+pdf_status_t
+pdf_stm_flush (pdf_stm_t stm,
+               pdf_bool_t finish_p,
+               pdf_size_t *flushed_bytes)
+{
+  pdf_stm_filter_t tail_filter;
+  pdf_buffer_t tail_buffer;
+  pdf_status_t ret;
+  pdf_size_t cache_size;
+  pdf_size_t written_bytes;
+  pdf_size_t tail_size;
+
+  if (stm->mode != PDF_STM_WRITE)
+    {
+      /* Invalid operation */
+      return 0;
+    }
+
+  /* Apply the head filter until the filter chain gets empty */
+  tail_filter = pdf_stm_filter_get_tail (stm->filter);
+  tail_buffer = pdf_stm_filter_get_in (tail_filter);
+  *flushed_bytes = 0;
+  while (1)
+    {
+      tail_size = tail_buffer->wp - tail_buffer->rp;
+      ret = pdf_stm_filter_apply (stm->filter, finish_p);
+
+      if (ret == PDF_ERROR)
+        {
+          /* The filter chain is in error */
+          break;
+        }
+
+      /* Update the number of flushed bytes */
+      *flushed_bytes += tail_size
+        - (tail_buffer->wp - tail_buffer->rp);
+      
+      if ((ret == PDF_EEOF)
+          && (pdf_buffer_eob_p (stm->cache)))
+        {
+          pdf_buffer_rewind (tail_buffer);
+          ret = PDF_OK;
+          break;
+        }
+
+      /* Write the data from the buffer cache into the backend */
+      cache_size = stm->cache->wp - stm->cache->rp;
+      ret = pdf_stm_be_write (stm->backend,
+                              stm->cache->data + stm->cache->rp,
+                              cache_size,
+                              &written_bytes);
+
+      if (ret == PDF_ERROR)
+        {
+          /* Error prevented us from writing */
+          break;
+        }
+
+      if (written_bytes != cache_size)
+        {
+          /* Could not write all the contents of the cache buffer into
+             the backend */
+          stm->cache->rp += written_bytes;
+          ret = PDF_EEOF;
+          break;
+        }
+
+      /* Rewind the cache */
+      pdf_buffer_rewind (stm->cache);
+    }
+
+  return ret;
+}
+
+pdf_status_t
+pdf_stm_install_filter (pdf_stm_t stm,
+                        enum pdf_stm_filter_type_e filter_type,
+                        pdf_hash_t filter_params)
+{
+  pdf_status_t ret;
+  pdf_stm_filter_t filter;
+  enum pdf_stm_filter_mode_e filter_mode;
+
+  if (stm->mode == PDF_STM_READ)
+    {
+      filter_mode = PDF_STM_FILTER_MODE_READ;
+    }
+  else
+    {
+      filter_mode = PDF_STM_FILTER_MODE_WRITE;
+    }
+
+  /* Create the new filter */
+  ret = pdf_stm_filter_new (filter_type,
+                            filter_params,
+                            stm->cache->size,
+                            filter_mode,
+                            &filter);
+
+  if (filter != NULL)
+    {
+      /* Set the new filter as the new head of the filter chain */
+      pdf_stm_filter_set_next (filter, stm->filter);
+      pdf_stm_filter_set_out (filter, stm->cache);
+      pdf_stm_filter_set_out (stm->filter, pdf_stm_filter_get_in (filter));
+      stm->filter = filter;
+    }
+
+  return ret;
+}
+
+pdf_status_t
+pdf_stm_read_char (pdf_stm_t stm, pdf_char_t *c)
+{
+  return pdf_stm_read_peek_char (stm, c, PDF_FALSE);
+}
+
+pdf_status_t
+pdf_stm_peek_char (pdf_stm_t stm, pdf_char_t *c)
+{
+  return pdf_stm_read_peek_char (stm, c, PDF_TRUE);
+}
+
+pdf_off_t
+pdf_stm_seek (pdf_stm_t stm,
+              pdf_off_t pos)
+{
+  pdf_off_t cur_pos;
+  pdf_off_t new_pos;
+  pdf_stm_filter_t tail_filter;
+  pdf_buffer_t tail_buffer;
+  pdf_size_t flushed_bytes;
+
+  cur_pos = pdf_stm_tell (stm);
+
+  if (stm->mode == PDF_STM_READ)
+    {
+      /* Discard the cache contents */
+      pdf_buffer_rewind (stm->cache);
+
+      /* Seek the backend */
+      new_pos = pdf_stm_be_seek (stm->backend, pos);
+    }
+  else
+    {
+      /* Writing stream */
+
+      tail_filter = pdf_stm_filter_get_tail (stm->filter);
+      tail_buffer = pdf_stm_filter_get_in (tail_filter);
+      if (!pdf_buffer_eob_p (tail_buffer))
+        {
+          /* Flush the stream */
+          if (pdf_stm_flush (stm, PDF_FALSE, &flushed_bytes)
+              == PDF_ERROR)
+            {
+              /* Error flushing the stream: return the current
+                 position */
+              return cur_pos;
+            }
+        }
+
+      /* Note that if there is an EOF condition in the backend we are
+         going to loose data */
+      pdf_buffer_rewind (tail_buffer);
+
+      /* Seek the backend */
+      new_pos = pdf_stm_be_seek (stm->backend, pos);
+    }
+
+  return new_pos;
+}
+
+pdf_off_t
+pdf_stm_tell (pdf_stm_t stm)
+{
+  pdf_off_t pos;
+  pdf_size_t cache_size;
+  pdf_stm_filter_t tail_filter;
+  pdf_buffer_t tail_buffer;
+
+  if (stm->mode == PDF_STM_READ)
+    {
+      cache_size = stm->cache->wp - stm->cache->rp;
+      pos = pdf_stm_be_tell (stm->backend) + cache_size;
+    }
+  else
+    {
+      /* Writing stream */
+
+      tail_filter = pdf_stm_filter_get_tail (stm->filter);
+      tail_buffer = pdf_stm_filter_get_in (tail_filter);
+
+      cache_size = tail_buffer->wp - tail_buffer->rp;
+      pos = pdf_stm_be_tell (stm->backend) + cache_size;
+    }
+
+  return pos;
+}
+
+/*
+ * Private functions
+ */
+
+static pdf_status_t
+pdf_stm_init (pdf_size_t cache_size,
+              enum pdf_stm_mode_e mode,
+              pdf_stm_t stm)
+{
+  pdf_hash_t null_filter_params;
+  enum pdf_stm_filter_mode_e filter_mode;
+  pdf_status_t ret;
+
+  if (cache_size == 0)
+    {
+      /* Use the default cache size */
+      cache_size = PDF_STM_DEFAULT_CACHE_SIZE;
+    } 
+
+  /* Initialize the null filter */
+  pdf_hash_new (NULL, &null_filter_params);
+
+  if (stm->mode == PDF_STM_READ)
+    {
+      filter_mode = PDF_STM_FILTER_MODE_READ;
+    }
+  else
+    {
+      filter_mode = PDF_STM_FILTER_MODE_WRITE;
+    }
+
+  ret = pdf_stm_filter_new (PDF_STM_FILTER_NULL,
+                            null_filter_params,
+                            cache_size,
+                            filter_mode,
+                            &(stm->filter));
+
+  if (ret == PDF_OK)
+    {
+      /* Initialize the filter cache */
+      stm->cache = pdf_buffer_new (cache_size);
+      
+      /* Configure the filter */
+      stm->mode = mode;
+      if (stm->mode == PDF_STM_READ)
+        {
+          /* Configuration for a reading stream
+           *
+           *  <cache> <--- <null-filter> <--- <backend>
+           */
+          
+          pdf_stm_filter_set_out (stm->filter, 
+                                  stm->cache);
+          pdf_stm_filter_set_be (stm->filter,
+                                 stm->backend);
+        } 
+      else
+        {
+          /* Configuration for a writing stream
+           *
+           * <null-filter> --> <cache> --> <backend>
+           */
+          
+          pdf_stm_filter_set_out (stm->filter,
+                                  stm->cache);
+        }
+    }
+
+  return ret;
+}
+
+
+static pdf_status_t
+pdf_stm_read_peek_char (pdf_stm_t stm,
+                        pdf_char_t *c,
+                        pdf_bool_t peek_p)
+{
+  pdf_status_t ret;
+
+  /* Is this a read stream? */
+  if (stm->mode != PDF_STM_READ)
+    {
+      /* Invalid operation */
+      return PDF_EINVOP;
+    }
+
+  /* Is the cache empty? */
+  ret = PDF_OK;
+  if (pdf_buffer_eob_p (stm->cache))
+    {
+      ret = pdf_stm_filter_apply (stm->filter, PDF_FALSE);
+    }
+
+  if (pdf_buffer_eob_p (stm->cache))
+    {
+      ret = PDF_EEOF;
+    }
+  else
+    {
+      /* Read a character from the cache */
+      *c = 
+        (pdf_u32_t) stm->cache->data[stm->cache->rp];
+
+      if (!peek_p)
+        {
+          stm->cache->rp++;
+        }
+
+      if (ret == PDF_EEOF)
+        {
+          /* Avoid a false PDF_EEOF */
+          ret = PDF_OK;
+        }
+    }
+  
+  return ret;
+}
+
+static inline pdf_stm_t
+pdf_stm_alloc (void)
+{
+  pdf_stm_t new;
+
+  new =  pdf_alloc (sizeof(struct pdf_stm_s));
+  return new;
+}
+
+static inline void
+pdf_stm_dealloc (pdf_stm_t stm)
+{
+  pdf_dealloc (stm);
+}
+
+/* End of pdf_stm.c */

# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWdhHLQUAFXN/gF/7HPt/////
///fur////pgHf7zbCm+y43lu3Tccee6velnvMTyo1vFFsVdgNUO21hrmus2pylXJ2Mnrvb1YYwF
RltMUFVWWG297e97t20x7d22tJVezcJTSJKfqelPaanqT9TKbUPKB6g9QeTU9TyjR6mgADQGh6g0
AAAkkaNE0Apq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