Add support for v850E2 and v850E2V3
[binutils.git] / gas / compress-debug.c
blobc2a8d3d51d08d2b6afd40ccb328ad4f4e9a54859
1 /* compress-debug.c - compress debug sections
2 Copyright 2010 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
19 02110-1301, USA. */
21 #include <stdio.h>
23 #include "ansidecl.h"
25 #include "config.h"
26 #include "compress-debug.h"
28 #ifdef HAVE_ZLIB_H
29 #include <zlib.h>
30 #endif
32 /* Initialize the compression engine. */
34 struct z_stream_s *
35 compress_init (void)
37 #ifndef HAVE_ZLIB_H
38 return NULL;
39 #else
40 static struct z_stream_s strm;
42 strm.zalloc = NULL;
43 strm.zfree = NULL;
44 strm.opaque = NULL;
45 deflateInit (&strm, Z_DEFAULT_COMPRESSION);
46 return &strm;
47 #endif /* HAVE_ZLIB_H */
50 /* Stream the contents of a frag to the compression engine. Output
51 from the engine goes into the current frag on the obstack. */
53 int
54 compress_data (struct z_stream_s *strm ATTRIBUTE_UNUSED,
55 const char **next_in ATTRIBUTE_UNUSED,
56 int *avail_in ATTRIBUTE_UNUSED,
57 char **next_out ATTRIBUTE_UNUSED,
58 int *avail_out ATTRIBUTE_UNUSED)
60 #ifndef HAVE_ZLIB_H
61 return -1;
62 #else
63 int out_size = 0;
64 int x;
66 strm->next_in = (Bytef *) (*next_in);
67 strm->avail_in = *avail_in;
68 strm->next_out = (Bytef *) (*next_out);
69 strm->avail_out = *avail_out;
71 x = deflate (strm, Z_NO_FLUSH);
72 if (x != Z_OK)
73 return -1;
75 out_size = *avail_out - strm->avail_out;
76 *next_in = (char *) (strm->next_in);
77 *avail_in = strm->avail_in;
78 *next_out = (char *) (strm->next_out);
79 *avail_out = strm->avail_out;
81 return out_size;
82 #endif /* HAVE_ZLIB_H */
85 /* Finish the compression and consume the remaining compressed output.
86 Returns -1 for error, 0 when done, 1 when more output buffer is
87 needed. */
89 int
90 compress_finish (struct z_stream_s *strm ATTRIBUTE_UNUSED,
91 char **next_out ATTRIBUTE_UNUSED,
92 int *avail_out ATTRIBUTE_UNUSED,
93 int *out_size ATTRIBUTE_UNUSED)
95 #ifndef HAVE_ZLIB_H
96 return -1;
97 #else
98 int x;
100 strm->avail_in = 0;
101 strm->next_out = (Bytef *) (*next_out);
102 strm->avail_out = *avail_out;
104 x = deflate (strm, Z_FINISH);
106 *out_size = *avail_out - strm->avail_out;
107 *next_out = (char *) (strm->next_out);
108 *avail_out = strm->avail_out;
110 if (x == Z_STREAM_END)
112 deflateEnd (strm);
113 return 0;
115 if (strm->avail_out != 0)
116 return -1;
117 return 1;
118 #endif /* HAVE_ZLIB_H */