1 : /* -*- mode: C -*-
2 : *
3 : * File: pdf-stm-f-null.c
4 : * Date: Mon Jul 9 22:01:41 2007
5 : *
6 : * GNU PDF Library - NULL stream filter
7 : *
8 : */
9 :
10 : /* Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc. */
11 :
12 : /* This program is free software: you can redistribute it and/or modify
13 : * it under the terms of the GNU General Public License as published by
14 : * the Free Software Foundation, either version 3 of the License, or
15 : * (at your option) any later version.
16 : *
17 : * This program is distributed in the hope that it will be useful,
18 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 : * GNU General Public License for more details.
21 : *
22 : * You should have received a copy of the GNU General Public License
23 : * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 : */
25 :
26 : #include <config.h>
27 :
28 : #include <string.h>
29 :
30 : #include <pdf-types.h>
31 : #include <pdf-stm-f-null.h>
32 :
33 : /*
34 : * Public functions
35 : */
36 :
37 : pdf_status_t
38 : pdf_stm_f_null_init (pdf_hash_t params,
39 : void **state)
40 806 : {
41 : /* This filter does not use any parameters and does not hold any
42 : internal state */
43 :
44 806 : return PDF_OK;
45 : }
46 :
47 : pdf_status_t
48 : pdf_stm_f_null_apply (pdf_hash_t params,
49 : void *state,
50 : pdf_buffer_t in,
51 : pdf_buffer_t out,
52 : pdf_bool_t finish_p)
53 4973 : {
54 : pdf_size_t in_size;
55 : pdf_size_t out_size;
56 : pdf_size_t bytes_to_copy;
57 : pdf_status_t ret;
58 :
59 : /* Fill the output buffer with the contents of the input buffer, but
60 : note that the second may be bigger than the former */
61 4973 : in_size = in->wp - in->rp;
62 4973 : out_size = out->size - out->wp;
63 :
64 4973 : bytes_to_copy = PDF_MIN(out_size, in_size);
65 :
66 4973 : if (bytes_to_copy != 0)
67 : {
68 2005 : memcpy ((char *) out->data,
69 : (char *) in->data,
70 : bytes_to_copy);
71 :
72 2005 : in->rp = in->rp + bytes_to_copy;
73 2005 : out->wp = out->wp + bytes_to_copy;
74 : }
75 :
76 4973 : if (in_size > out_size)
77 : {
78 : /* We need more room in the output buffer */
79 0 : ret = PDF_ENOUTPUT;
80 : }
81 : else
82 : {
83 : /* We can process more input */
84 4973 : ret = PDF_ENINPUT;
85 : }
86 :
87 4973 : return ret;
88 : }
89 :
90 : pdf_status_t
91 : pdf_stm_f_null_dealloc_state (void *state)
92 621 : {
93 621 : return PDF_OK;
94 : }
95 :
96 : /* End of pdf_stm_f_null.c */
|