~ubuntu-branches/debian/jessie/ccache/jessie

« back to all changes in this revision

Viewing changes to debian/patches/02_ccache-compressed.diff

  • Committer: Bazaar Package Importer
  • Author(s): Loïc Minier
  • Date: 2010-10-13 17:14:13 UTC
  • mfrom: (5.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20101013171413-4ehrj1y89huf069u
Tags: 3.0.1-1ubuntu1
* Merge with Debian; remaining changes:
  - Add gcc/g++-4.4 and -4.5 symlinks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
diff --git a/Makefile.in b/Makefile.in
2
 
index 0bf3eb9..e32ebe5 100644
3
 
--- a/Makefile.in
4
 
+++ b/Makefile.in
5
 
@@ -11,6 +11,7 @@ CC=@CC@
6
 
 CFLAGS=@CFLAGS@ -I.
7
 
 EXEEXT=@EXEEXT@
8
 
 
9
 
+LIBS= @LIBS@
10
 
 OBJS= ccache.o mdfour.o hash.o execute.o util.o args.o stats.o \
11
 
        cleanup.o snprintf.o unify.o
12
 
 HEADERS = ccache.h mdfour.h
13
 
@@ -20,7 +21,7 @@ all: ccache$(EXEEXT)
14
 
 docs: ccache.1 web/ccache-man.html
15
 
 
16
 
 ccache$(EXEEXT): $(OBJS) $(HEADERS)
17
 
-       $(CC) $(CFLAGS) -o $@ $(OBJS)
18
 
+       $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS)
19
 
 
20
 
 ccache.1: ccache.yo
21
 
        -yodl2man -o ccache.1 ccache.yo
22
 
diff --git a/ccache.1 b/ccache.1
23
 
index daec8ee..9d1cbcd 100644
24
 
--- a/ccache.1
25
 
+++ b/ccache.1
26
 
@@ -210,7 +210,8 @@ If you set the environment variable
27
 
 CCACHE_HARDLINK then ccache will attempt to use hard links from the
28
 
 cache directory when creating the compiler output rather than using a
29
 
 file copy\&. Using hard links is faster, but can confuse programs like
30
 
-\&'make\&' that rely on modification times\&.
31
 
+\&'make\&' that rely on modification times\&. Hard links are never made for
32
 
+compressed cache files\&.
33
 
 .IP 
34
 
 .IP "\fBCCACHE_RECACHE\fP" 
35
 
 This forces ccache to not use any cached
36
 
@@ -257,6 +258,11 @@ systems like this you can use the CCACHE_EXTENSION option to override
37
 
 the default\&. On HP-UX set this environment variable to "i" if you use
38
 
 the aCC compiler\&.
39
 
 .IP 
40
 
+.IP "\fBCCACHE_NOCOMPRESS\fP" 
41
 
+If you set the environment variable
42
 
+CCACHE_NOCOMPRESS then there is no compression used on files that go
43
 
+into the cache\&.
44
 
+.IP 
45
 
 .PP 
46
 
 .SH "CACHE SIZE MANAGEMENT" 
47
 
 .PP 
48
 
@@ -269,6 +275,14 @@ When these limits are reached ccache will reduce the cache to 20%
49
 
 below the numbers you specified in order to avoid doing the cache
50
 
 clean operation too often\&.
51
 
 .PP 
52
 
+.SH "CACHE COMPRESSION" 
53
 
+.PP 
54
 
+By default ccache will compress all files it puts into the cache
55
 
+using the zlib compression\&. While this involves a negligible
56
 
+performance slowdown, it significantly increases the number of files
57
 
+that fit in the cache\&. You can turn off compression setting the
58
 
+CCACHE_NOCOMPRESS environment variable\&.
59
 
+.PP 
60
 
 .SH "HOW IT WORKS" 
61
 
 .PP 
62
 
 The basic idea is to detect when you are compiling exactly the same
63
 
diff --git a/ccache.c b/ccache.c
64
 
index e7272d5..f6be1bc 100644
65
 
--- a/ccache.c
66
 
+++ b/ccache.c
67
 
@@ -199,7 +199,7 @@ static void to_cache(ARGS *args)
68
 
                fd = open(tmp_stderr, O_RDONLY | O_BINARY);
69
 
                if (fd != -1) {
70
 
                        if (strcmp(output_file, "/dev/null") == 0 ||
71
 
-                           rename(tmp_hashname, output_file) == 0 || errno == ENOENT) {
72
 
+                           move_file(tmp_hashname, output_file) == 0 || errno == ENOENT) {
73
 
                                if (cpp_stderr) {
74
 
                                        /* we might have some stderr from cpp */
75
 
                                        int fd2 = open(cpp_stderr, O_RDONLY | O_BINARY);
76
 
@@ -231,14 +231,25 @@ static void to_cache(ARGS *args)
77
 
        x_asprintf(&path_stderr, "%s.stderr", hashname);
78
 
 
79
 
        if (stat(tmp_stderr, &st1) != 0 ||
80
 
-           stat(tmp_hashname, &st2) != 0 ||
81
 
-           rename(tmp_hashname, hashname) != 0 ||
82
 
-           rename(tmp_stderr, path_stderr) != 0) {
83
 
+               stat(tmp_hashname, &st2) != 0 ||
84
 
+               move_file(tmp_hashname, hashname) != 0 ||
85
 
+               move_file(tmp_stderr, path_stderr) != 0) {
86
 
                cc_log("failed to rename tmp files - %s\n", strerror(errno));
87
 
                stats_update(STATS_ERROR);
88
 
                failed();
89
 
        }
90
 
 
91
 
+#if ENABLE_ZLIB
92
 
+       /* do an extra stat on the cache files for
93
 
+          the size statistics */
94
 
+       if (stat(path_stderr, &st1) != 0 ||
95
 
+               stat(hashname, &st2) != 0) {
96
 
+               cc_log("failed to stat cache files - %s\n", strerror(errno));
97
 
+               stats_update(STATS_ERROR);
98
 
+               failed();
99
 
+    }
100
 
+#endif
101
 
+
102
 
        cc_log("Placed %s into cache\n", output_file);
103
 
        stats_tocache(file_size(&st1) + file_size(&st2));
104
 
 
105
 
@@ -474,7 +485,13 @@ static void from_cache(int first)
106
 
        }
107
 
 
108
 
        /* the user might be disabling cache hits */
109
 
+#ifndef ENABLE_ZLIB
110
 
+       /* if the cache file is compressed we must recache */
111
 
+       if ((first && getenv("CCACHE_RECACHE")) ||
112
 
+               test_if_compressed(hashname) == 1) {
113
 
+#else
114
 
        if (first && getenv("CCACHE_RECACHE")) {
115
 
+#endif
116
 
                close(fd_stderr);
117
 
                unlink(stderr_file);
118
 
                free(stderr_file);
119
 
@@ -487,7 +504,9 @@ static void from_cache(int first)
120
 
                ret = 0;
121
 
        } else {
122
 
                unlink(output_file);
123
 
-               if (getenv("CCACHE_HARDLINK")) {
124
 
+               /* only make a hardlink if the cache file is uncompressed */
125
 
+               if (getenv("CCACHE_HARDLINK") &&
126
 
+                       test_if_compressed(hashname) == 0) {
127
 
                        ret = link(hashname, output_file);
128
 
                } else {
129
 
                        ret = copy_file(hashname, output_file);
130
 
diff --git a/ccache.h b/ccache.h
131
 
index faec597..67904cd 100644
132
 
--- a/ccache.h
133
 
+++ b/ccache.h
134
 
@@ -23,6 +23,10 @@
135
 
 #include <pwd.h>
136
 
 #endif
137
 
 
138
 
+#ifdef ENABLE_ZLIB
139
 
+#include <zlib.h>
140
 
+#endif
141
 
+
142
 
 #define STATUS_NOTFOUND 3
143
 
 #define STATUS_FATAL 4
144
 
 #define STATUS_NOCACHE 5
145
 
@@ -36,6 +40,13 @@
146
 
 #define DEFAULT_MAXSIZE (1000*1000)
147
 
 #endif
148
 
 
149
 
+/* file copy mode */
150
 
+#ifdef ENABLE_ZLIB
151
 
+#define COPY_UNCOMPRESSED 0
152
 
+#define COPY_FROM_CACHE 1
153
 
+#define COPY_TO_CACHE 2
154
 
+#endif
155
 
+
156
 
 enum stats {
157
 
        STATS_NONE=0,
158
 
        STATS_STDOUT,
159
 
@@ -79,6 +90,8 @@ void fatal(const char *msg);
160
 
 
161
 
 void copy_fd(int fd_in, int fd_out);
162
 
 int copy_file(const char *src, const char *dest);
163
 
+int move_file(const char *src, const char *dest);
164
 
+int test_if_compressed(const char *filename);
165
 
 
166
 
 int create_dir(const char *dir);
167
 
 void x_asprintf(char **ptr, const char *format, ...);
168
 
diff --git a/ccache.yo b/ccache.yo
169
 
index 12e45a6..311bead 100644
170
 
--- a/ccache.yo
171
 
+++ b/ccache.yo
172
 
@@ -169,6 +169,11 @@ will have problems with the intermediate filename extensions used in
173
 
 this optimisation, in which case this option could allow ccache to be
174
 
 used.
175
 
 
176
 
+dit(bf(CCACHE_NOCOMPRESS)) If you set the environment variable
177
 
+CCACHE_NOCOMPRESS then there is no compression used on files that go
178
 
+into the cache. However, this setting has no effect on how files are
179
 
+retrieved from the cache, compressed results will still be usable.
180
 
+
181
 
 dit(bf(CCACHE_NOSTATS)) If you set the environment variable
182
 
 CCACHE_NOSTATS then ccache will not update the statistics files on
183
 
 each compile.
184
 
@@ -181,7 +186,8 @@ dit(bf(CCACHE_HARDLINK)) If you set the environment variable
185
 
 CCACHE_HARDLINK then ccache will attempt to use hard links from the
186
 
 cache directory when creating the compiler output rather than using a
187
 
 file copy. Using hard links is faster, but can confuse programs like
188
 
-'make' that rely on modification times.
189
 
+'make' that rely on modification times. Hard links are never made for
190
 
+compressed cache files.
191
 
 
192
 
 dit(bf(CCACHE_RECACHE)) This forces ccache to not use any cached
193
 
 results, even if it finds them. New results are still cached, but
194
 
@@ -236,6 +242,14 @@ When these limits are reached ccache will reduce the cache to 20%
195
 
 below the numbers you specified in order to avoid doing the cache
196
 
 clean operation too often.
197
 
 
198
 
+manpagesection(CACHE COMPRESSION)
199
 
+
200
 
+By default ccache will compress all files it puts into the cache
201
 
+using the zlib compression. While this involves a negligible
202
 
+performance slowdown, it significantly increases the number of files
203
 
+that fit in the cache. You can turn off compression setting the
204
 
+CCACHE_NOCOMPRESS environment variable.
205
 
+
206
 
 manpagesection(HOW IT WORKS)
207
 
 
208
 
 The basic idea is to detect when you are compiling exactly the same
209
 
@@ -294,6 +308,8 @@ itemize(
210
 
   cache. This tells the filesystem to inherit group ownership for new
211
 
   directories. The command "chmod g+s `find $CCACHE_DIR -type d`" might
212
 
   be useful for this.
213
 
+  it() Set bf(CCACHE_NOCOMPRESS) for all users, if there are users with
214
 
+  versions of ccache that do not support compression.
215
 
 )
216
 
 
217
 
 manpagesection(HISTORY)
218
 
diff --git a/config.h.in b/config.h.in
219
 
index 286f038..3068845 100644
220
 
--- a/config.h.in
221
 
+++ b/config.h.in
222
 
@@ -98,3 +98,6 @@
223
 
 
224
 
 /* Define _GNU_SOURCE so that we get all necessary prototypes */
225
 
 #undef _GNU_SOURCE
226
 
+
227
 
+/* Define to 1 if you like to have zlib compression for the ccache. */
228
 
+#undef ENABLE_ZLIB
229
 
diff --git a/configure b/configure
230
 
index 2275677..c96e3ee 100755
231
 
--- a/configure
232
 
+++ b/configure
233
 
@@ -836,6 +836,11 @@ if test -n "$ac_init_help"; then
234
 
 
235
 
   cat <<\_ACEOF
236
 
 
237
 
+Optional Features:
238
 
+  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
239
 
+  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
240
 
+  --enable-zlib           enable zlib support for ccache compression
241
 
+
242
 
 Some influential environment variables:
243
 
   CC          C compiler command
244
 
   CFLAGS      C compiler flags
245
 
@@ -936,7 +941,7 @@ esac
246
 
     else
247
 
       echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
248
 
     fi
249
 
-    cd "$ac_popdir"
250
 
+    cd $ac_popdir
251
 
   done
252
 
 fi
253
 
 
254
 
@@ -1859,7 +1864,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
255
 
   cat conftest.err >&5
256
 
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
257
 
   (exit $ac_status); } &&
258
 
-        { ac_try='test -z "$ac_c_werror_flag"                   || test ! -s conftest.err'
259
 
+        { ac_try='test -z "$ac_c_werror_flag"
260
 
+                        || test ! -s conftest.err'
261
 
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
262
 
   (eval $ac_try) 2>&5
263
 
   ac_status=$?
264
 
@@ -1917,7 +1923,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
265
 
   cat conftest.err >&5
266
 
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
267
 
   (exit $ac_status); } &&
268
 
-        { ac_try='test -z "$ac_c_werror_flag"                   || test ! -s conftest.err'
269
 
+        { ac_try='test -z "$ac_c_werror_flag"
270
 
+                        || test ! -s conftest.err'
271
 
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
272
 
   (eval $ac_try) 2>&5
273
 
   ac_status=$?
274
 
@@ -2033,7 +2040,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
275
 
   cat conftest.err >&5
276
 
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
277
 
   (exit $ac_status); } &&
278
 
-        { ac_try='test -z "$ac_c_werror_flag"                   || test ! -s conftest.err'
279
 
+        { ac_try='test -z "$ac_c_werror_flag"
280
 
+                        || test ! -s conftest.err'
281
 
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
282
 
   (eval $ac_try) 2>&5
283
 
   ac_status=$?
284
 
@@ -2087,7 +2095,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
285
 
   cat conftest.err >&5
286
 
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
287
 
   (exit $ac_status); } &&
288
 
-        { ac_try='test -z "$ac_c_werror_flag"                   || test ! -s conftest.err'
289
 
+        { ac_try='test -z "$ac_c_werror_flag"
290
 
+                        || test ! -s conftest.err'
291
 
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
292
 
   (eval $ac_try) 2>&5
293
 
   ac_status=$?
294
 
@@ -2132,7 +2141,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
295
 
   cat conftest.err >&5
296
 
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
297
 
   (exit $ac_status); } &&
298
 
-        { ac_try='test -z "$ac_c_werror_flag"                   || test ! -s conftest.err'
299
 
+        { ac_try='test -z "$ac_c_werror_flag"
300
 
+                        || test ! -s conftest.err'
301
 
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
302
 
   (eval $ac_try) 2>&5
303
 
   ac_status=$?
304
 
@@ -2176,7 +2186,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
305
 
   cat conftest.err >&5
306
 
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
307
 
   (exit $ac_status); } &&
308
 
-        { ac_try='test -z "$ac_c_werror_flag"                   || test ! -s conftest.err'
309
 
+        { ac_try='test -z "$ac_c_werror_flag"
310
 
+                        || test ! -s conftest.err'
311
 
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
312
 
   (eval $ac_try) 2>&5
313
 
   ac_status=$?
314
 
@@ -2609,7 +2620,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
315
 
   cat conftest.err >&5
316
 
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
317
 
   (exit $ac_status); } &&
318
 
-        { ac_try='test -z "$ac_c_werror_flag"                   || test ! -s conftest.err'
319
 
+        { ac_try='test -z "$ac_c_werror_flag"
320
 
+                        || test ! -s conftest.err'
321
 
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
322
 
   (eval $ac_try) 2>&5
323
 
   ac_status=$?
324
 
@@ -2681,7 +2693,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
325
 
   cat conftest.err >&5
326
 
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
327
 
   (exit $ac_status); } &&
328
 
-        { ac_try='test -z "$ac_c_werror_flag"                   || test ! -s conftest.err'
329
 
+        { ac_try='test -z "$ac_c_werror_flag"
330
 
+                        || test ! -s conftest.err'
331
 
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
332
 
   (eval $ac_try) 2>&5
333
 
   ac_status=$?
334
 
@@ -2735,7 +2748,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
335
 
   cat conftest.err >&5
336
 
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
337
 
   (exit $ac_status); } &&
338
 
-        { ac_try='test -z "$ac_c_werror_flag"                   || test ! -s conftest.err'
339
 
+        { ac_try='test -z "$ac_c_werror_flag"
340
 
+                        || test ! -s conftest.err'
341
 
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
342
 
   (eval $ac_try) 2>&5
343
 
   ac_status=$?
344
 
@@ -2806,7 +2820,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
345
 
   cat conftest.err >&5
346
 
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
347
 
   (exit $ac_status); } &&
348
 
-        { ac_try='test -z "$ac_c_werror_flag"                   || test ! -s conftest.err'
349
 
+        { ac_try='test -z "$ac_c_werror_flag"
350
 
+                        || test ! -s conftest.err'
351
 
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
352
 
   (eval $ac_try) 2>&5
353
 
   ac_status=$?
354
 
@@ -2860,7 +2875,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
355
 
   cat conftest.err >&5
356
 
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
357
 
   (exit $ac_status); } &&
358
 
-        { ac_try='test -z "$ac_c_werror_flag"                   || test ! -s conftest.err'
359
 
+        { ac_try='test -z "$ac_c_werror_flag"
360
 
+                        || test ! -s conftest.err'
361
 
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
362
 
   (eval $ac_try) 2>&5
363
 
   ac_status=$?
364
 
@@ -2927,7 +2943,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
365
 
   cat conftest.err >&5
366
 
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
367
 
   (exit $ac_status); } &&
368
 
-        { ac_try='test -z "$ac_c_werror_flag"                   || test ! -s conftest.err'
369
 
+        { ac_try='test -z "$ac_c_werror_flag"
370
 
+                        || test ! -s conftest.err'
371
 
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
372
 
   (eval $ac_try) 2>&5
373
 
   ac_status=$?
374
 
@@ -2997,7 +3014,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
375
 
   cat conftest.err >&5
376
 
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
377
 
   (exit $ac_status); } &&
378
 
-        { ac_try='test -z "$ac_c_werror_flag"                   || test ! -s conftest.err'
379
 
+        { ac_try='test -z "$ac_c_werror_flag"
380
 
+                        || test ! -s conftest.err'
381
 
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
382
 
   (eval $ac_try) 2>&5
383
 
   ac_status=$?
384
 
@@ -3078,7 +3096,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
385
 
   cat conftest.err >&5
386
 
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
387
 
   (exit $ac_status); } &&
388
 
-        { ac_try='test -z "$ac_c_werror_flag"                   || test ! -s conftest.err'
389
 
+        { ac_try='test -z "$ac_c_werror_flag"
390
 
+                        || test ! -s conftest.err'
391
 
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
392
 
   (eval $ac_try) 2>&5
393
 
   ac_status=$?
394
 
@@ -3248,7 +3267,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
395
 
   cat conftest.err >&5
396
 
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
397
 
   (exit $ac_status); } &&
398
 
-        { ac_try='test -z "$ac_c_werror_flag"                   || test ! -s conftest.err'
399
 
+        { ac_try='test -z "$ac_c_werror_flag"
400
 
+                        || test ! -s conftest.err'
401
 
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
402
 
   (eval $ac_try) 2>&5
403
 
   ac_status=$?
404
 
@@ -3319,7 +3339,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
405
 
   cat conftest.err >&5
406
 
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
407
 
   (exit $ac_status); } &&
408
 
-        { ac_try='test -z "$ac_c_werror_flag"                   || test ! -s conftest.err'
409
 
+        { ac_try='test -z "$ac_c_werror_flag"
410
 
+                        || test ! -s conftest.err'
411
 
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
412
 
   (eval $ac_try) 2>&5
413
 
   ac_status=$?
414
 
@@ -3509,7 +3530,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
415
 
   cat conftest.err >&5
416
 
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
417
 
   (exit $ac_status); } &&
418
 
-        { ac_try='test -z "$ac_c_werror_flag"                   || test ! -s conftest.err'
419
 
+        { ac_try='test -z "$ac_c_werror_flag"
420
 
+                        || test ! -s conftest.err'
421
 
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
422
 
   (eval $ac_try) 2>&5
423
 
   ac_status=$?
424
 
@@ -3611,7 +3633,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
425
 
   cat conftest.err >&5
426
 
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
427
 
   (exit $ac_status); } &&
428
 
-        { ac_try='test -z "$ac_c_werror_flag"                   || test ! -s conftest.err'
429
 
+        { ac_try='test -z "$ac_c_werror_flag"
430
 
+                        || test ! -s conftest.err'
431
 
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
432
 
   (eval $ac_try) 2>&5
433
 
   ac_status=$?
434
 
@@ -3676,7 +3699,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
435
 
   cat conftest.err >&5
436
 
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
437
 
   (exit $ac_status); } &&
438
 
-        { ac_try='test -z "$ac_c_werror_flag"                   || test ! -s conftest.err'
439
 
+        { ac_try='test -z "$ac_c_werror_flag"
440
 
+                        || test ! -s conftest.err'
441
 
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
442
 
   (eval $ac_try) 2>&5
443
 
   ac_status=$?
444
 
@@ -3775,6 +3799,229 @@ _ACEOF
445
 
 
446
 
 fi
447
 
 
448
 
+# Check whether --enable-zlib or --disable-zlib was given.
449
 
+if test "${enable_zlib+set}" = set; then
450
 
+  enableval="$enable_zlib"
451
 
+
452
 
+else
453
 
+  enable_zlib=yes
454
 
+fi;
455
 
+
456
 
+if test x"$enable_zlib" = x"yes"; then
457
 
+    if test "${ac_cv_header_zlib_h+set}" = set; then
458
 
+  echo "$as_me:$LINENO: checking for zlib.h" >&5
459
 
+echo $ECHO_N "checking for zlib.h... $ECHO_C" >&6
460
 
+if test "${ac_cv_header_zlib_h+set}" = set; then
461
 
+  echo $ECHO_N "(cached) $ECHO_C" >&6
462
 
+fi
463
 
+echo "$as_me:$LINENO: result: $ac_cv_header_zlib_h" >&5
464
 
+echo "${ECHO_T}$ac_cv_header_zlib_h" >&6
465
 
+else
466
 
+  # Is the header compilable?
467
 
+echo "$as_me:$LINENO: checking zlib.h usability" >&5
468
 
+echo $ECHO_N "checking zlib.h usability... $ECHO_C" >&6
469
 
+cat >conftest.$ac_ext <<_ACEOF
470
 
+/* confdefs.h.  */
471
 
+_ACEOF
472
 
+cat confdefs.h >>conftest.$ac_ext
473
 
+cat >>conftest.$ac_ext <<_ACEOF
474
 
+/* end confdefs.h.  */
475
 
+$ac_includes_default
476
 
+#include <zlib.h>
477
 
+_ACEOF
478
 
+rm -f conftest.$ac_objext
479
 
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
480
 
+  (eval $ac_compile) 2>conftest.er1
481
 
+  ac_status=$?
482
 
+  grep -v '^ *+' conftest.er1 >conftest.err
483
 
+  rm -f conftest.er1
484
 
+  cat conftest.err >&5
485
 
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
486
 
+  (exit $ac_status); } &&
487
 
+        { ac_try='test -z "$ac_c_werror_flag"
488
 
+                        || test ! -s conftest.err'
489
 
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
490
 
+  (eval $ac_try) 2>&5
491
 
+  ac_status=$?
492
 
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
493
 
+  (exit $ac_status); }; } &&
494
 
+        { ac_try='test -s conftest.$ac_objext'
495
 
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
496
 
+  (eval $ac_try) 2>&5
497
 
+  ac_status=$?
498
 
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
499
 
+  (exit $ac_status); }; }; then
500
 
+  ac_header_compiler=yes
501
 
+else
502
 
+  echo "$as_me: failed program was:" >&5
503
 
+sed 's/^/| /' conftest.$ac_ext >&5
504
 
+
505
 
+ac_header_compiler=no
506
 
+fi
507
 
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
508
 
+echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
509
 
+echo "${ECHO_T}$ac_header_compiler" >&6
510
 
+
511
 
+# Is the header present?
512
 
+echo "$as_me:$LINENO: checking zlib.h presence" >&5
513
 
+echo $ECHO_N "checking zlib.h presence... $ECHO_C" >&6
514
 
+cat >conftest.$ac_ext <<_ACEOF
515
 
+/* confdefs.h.  */
516
 
+_ACEOF
517
 
+cat confdefs.h >>conftest.$ac_ext
518
 
+cat >>conftest.$ac_ext <<_ACEOF
519
 
+/* end confdefs.h.  */
520
 
+#include <zlib.h>
521
 
+_ACEOF
522
 
+if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
523
 
+  (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
524
 
+  ac_status=$?
525
 
+  grep -v '^ *+' conftest.er1 >conftest.err
526
 
+  rm -f conftest.er1
527
 
+  cat conftest.err >&5
528
 
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
529
 
+  (exit $ac_status); } >/dev/null; then
530
 
+  if test -s conftest.err; then
531
 
+    ac_cpp_err=$ac_c_preproc_warn_flag
532
 
+    ac_cpp_err=$ac_cpp_err$ac_c_werror_flag
533
 
+  else
534
 
+    ac_cpp_err=
535
 
+  fi
536
 
+else
537
 
+  ac_cpp_err=yes
538
 
+fi
539
 
+if test -z "$ac_cpp_err"; then
540
 
+  ac_header_preproc=yes
541
 
+else
542
 
+  echo "$as_me: failed program was:" >&5
543
 
+sed 's/^/| /' conftest.$ac_ext >&5
544
 
+
545
 
+  ac_header_preproc=no
546
 
+fi
547
 
+rm -f conftest.err conftest.$ac_ext
548
 
+echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
549
 
+echo "${ECHO_T}$ac_header_preproc" >&6
550
 
+
551
 
+# So?  What about this header?
552
 
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
553
 
+  yes:no: )
554
 
+    { echo "$as_me:$LINENO: WARNING: zlib.h: accepted by the compiler, rejected by the preprocessor!" >&5
555
 
+echo "$as_me: WARNING: zlib.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
556
 
+    { echo "$as_me:$LINENO: WARNING: zlib.h: proceeding with the compiler's result" >&5
557
 
+echo "$as_me: WARNING: zlib.h: proceeding with the compiler's result" >&2;}
558
 
+    ac_header_preproc=yes
559
 
+    ;;
560
 
+  no:yes:* )
561
 
+    { echo "$as_me:$LINENO: WARNING: zlib.h: present but cannot be compiled" >&5
562
 
+echo "$as_me: WARNING: zlib.h: present but cannot be compiled" >&2;}
563
 
+    { echo "$as_me:$LINENO: WARNING: zlib.h:     check for missing prerequisite headers?" >&5
564
 
+echo "$as_me: WARNING: zlib.h:     check for missing prerequisite headers?" >&2;}
565
 
+    { echo "$as_me:$LINENO: WARNING: zlib.h: see the Autoconf documentation" >&5
566
 
+echo "$as_me: WARNING: zlib.h: see the Autoconf documentation" >&2;}
567
 
+    { echo "$as_me:$LINENO: WARNING: zlib.h:     section \"Present But Cannot Be Compiled\"" >&5
568
 
+echo "$as_me: WARNING: zlib.h:     section \"Present But Cannot Be Compiled\"" >&2;}
569
 
+    { echo "$as_me:$LINENO: WARNING: zlib.h: proceeding with the preprocessor's result" >&5
570
 
+echo "$as_me: WARNING: zlib.h: proceeding with the preprocessor's result" >&2;}
571
 
+    { echo "$as_me:$LINENO: WARNING: zlib.h: in the future, the compiler will take precedence" >&5
572
 
+echo "$as_me: WARNING: zlib.h: in the future, the compiler will take precedence" >&2;}
573
 
+    (
574
 
+      cat <<\_ASBOX
575
 
+## ------------------------------------------ ##
576
 
+## Report this to the AC_PACKAGE_NAME lists.  ##
577
 
+## ------------------------------------------ ##
578
 
+_ASBOX
579
 
+    ) |
580
 
+      sed "s/^/$as_me: WARNING:     /" >&2
581
 
+    ;;
582
 
+esac
583
 
+echo "$as_me:$LINENO: checking for zlib.h" >&5
584
 
+echo $ECHO_N "checking for zlib.h... $ECHO_C" >&6
585
 
+if test "${ac_cv_header_zlib_h+set}" = set; then
586
 
+  echo $ECHO_N "(cached) $ECHO_C" >&6
587
 
+else
588
 
+  ac_cv_header_zlib_h=$ac_header_preproc
589
 
+fi
590
 
+echo "$as_me:$LINENO: result: $ac_cv_header_zlib_h" >&5
591
 
+echo "${ECHO_T}$ac_cv_header_zlib_h" >&6
592
 
+
593
 
+fi
594
 
+if test $ac_cv_header_zlib_h = yes; then
595
 
+  echo "$as_me:$LINENO: checking for gzdopen in -lz" >&5
596
 
+echo $ECHO_N "checking for gzdopen in -lz... $ECHO_C" >&6
597
 
+if test "${ac_cv_lib_z_gzdopen+set}" = set; then
598
 
+  echo $ECHO_N "(cached) $ECHO_C" >&6
599
 
+else
600
 
+  ac_check_lib_save_LIBS=$LIBS
601
 
+LIBS="-lz  $LIBS"
602
 
+cat >conftest.$ac_ext <<_ACEOF
603
 
+/* confdefs.h.  */
604
 
+_ACEOF
605
 
+cat confdefs.h >>conftest.$ac_ext
606
 
+cat >>conftest.$ac_ext <<_ACEOF
607
 
+/* end confdefs.h.  */
608
 
+
609
 
+/* Override any gcc2 internal prototype to avoid an error.  */
610
 
+#ifdef __cplusplus
611
 
+extern "C"
612
 
+#endif
613
 
+/* We use char because int might match the return type of a gcc2
614
 
+   builtin and then its argument prototype would still apply.  */
615
 
+char gzdopen ();
616
 
+int
617
 
+main ()
618
 
+{
619
 
+gzdopen ();
620
 
+  ;
621
 
+  return 0;
622
 
+}
623
 
+_ACEOF
624
 
+rm -f conftest.$ac_objext conftest$ac_exeext
625
 
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
626
 
+  (eval $ac_link) 2>conftest.er1
627
 
+  ac_status=$?
628
 
+  grep -v '^ *+' conftest.er1 >conftest.err
629
 
+  rm -f conftest.er1
630
 
+  cat conftest.err >&5
631
 
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
632
 
+  (exit $ac_status); } &&
633
 
+        { ac_try='test -z "$ac_c_werror_flag"
634
 
+                        || test ! -s conftest.err'
635
 
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
636
 
+  (eval $ac_try) 2>&5
637
 
+  ac_status=$?
638
 
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
639
 
+  (exit $ac_status); }; } &&
640
 
+        { ac_try='test -s conftest$ac_exeext'
641
 
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
642
 
+  (eval $ac_try) 2>&5
643
 
+  ac_status=$?
644
 
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
645
 
+  (exit $ac_status); }; }; then
646
 
+  ac_cv_lib_z_gzdopen=yes
647
 
+else
648
 
+  echo "$as_me: failed program was:" >&5
649
 
+sed 's/^/| /' conftest.$ac_ext >&5
650
 
+
651
 
+ac_cv_lib_z_gzdopen=no
652
 
+fi
653
 
+rm -f conftest.err conftest.$ac_objext \
654
 
+      conftest$ac_exeext conftest.$ac_ext
655
 
+LIBS=$ac_check_lib_save_LIBS
656
 
+fi
657
 
+echo "$as_me:$LINENO: result: $ac_cv_lib_z_gzdopen" >&5
658
 
+echo "${ECHO_T}$ac_cv_lib_z_gzdopen" >&6
659
 
+if test $ac_cv_lib_z_gzdopen = yes; then
660
 
+  LIBS="-lz $LIBS"; cat >>confdefs.h <<\_ACEOF
661
 
+#define ENABLE_ZLIB 1
662
 
+_ACEOF
663
 
+
664
 
+fi
665
 
+
666
 
+fi
667
 
+
668
 
+
669
 
+fi
670
 
+
671
 
           ac_config_files="$ac_config_files Makefile"
672
 
 
673
 
 cat >confcache <<\_ACEOF
674
 
@@ -4568,6 +4815,11 @@ esac
675
 
   *) ac_INSTALL=$ac_top_builddir$INSTALL ;;
676
 
   esac
677
 
 
678
 
+  if test x"$ac_file" != x-; then
679
 
+    { echo "$as_me:$LINENO: creating $ac_file" >&5
680
 
+echo "$as_me: creating $ac_file" >&6;}
681
 
+    rm -f "$ac_file"
682
 
+  fi
683
 
   # Let's still pretend it is `configure' which instantiates (i.e., don't
684
 
   # use $as_me), people would be surprised to read:
685
 
   #    /* config.h.  Generated by config.status.  */
686
 
@@ -4606,12 +4858,6 @@ echo "$as_me: error: cannot find input file: $f" >&2;}
687
 
         fi;;
688
 
       esac
689
 
     done` || { (exit 1); exit 1; }
690
 
-
691
 
-  if test x"$ac_file" != x-; then
692
 
-    { echo "$as_me:$LINENO: creating $ac_file" >&5
693
 
-echo "$as_me: creating $ac_file" >&6;}
694
 
-    rm -f "$ac_file"
695
 
-  fi
696
 
 _ACEOF
697
 
 cat >>$CONFIG_STATUS <<_ACEOF
698
 
   sed "$ac_vpsub
699
 
diff --git a/configure.in b/configure.in
700
 
index 3229ef0..be77bbf 100644
701
 
--- a/configure.in
702
 
+++ b/configure.in
703
 
@@ -68,5 +68,14 @@ if test x"$ccache_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
704
 
     AC_DEFINE(HAVE_C99_VSNPRINTF, 1, [ ])
705
 
 fi
706
 
 
707
 
+dnl Check for zlib.
708
 
+AC_ARG_ENABLE([zlib],
709
 
+              AS_HELP_STRING([--enable-zlib], [enable zlib support for ccache compression]),,
710
 
+              [enable_zlib=yes])
711
 
+
712
 
+if test x"$enable_zlib" = x"yes"; then
713
 
+    AC_CHECK_HEADER(zlib.h, AC_CHECK_LIB(z, gzdopen, LIBS="-lz $LIBS"; AC_DEFINE(ENABLE_ZLIB)))
714
 
+fi
715
 
+
716
 
 AC_CONFIG_FILES([Makefile])
717
 
 AC_OUTPUT
718
 
diff --git a/manage-cache.sh b/manage-cache.sh
719
 
new file mode 100644
720
 
index 0000000..7ef329d
721
 
--- /dev/null
722
 
+++ b/manage-cache.sh
723
 
@@ -0,0 +1,68 @@
724
 
+#!/bin/bash
725
 
+#
726
 
+# 2004-05-12 lars@gustaebel.de
727
 
+
728
 
+CCACHE_DIR=${CCACHE_DIR:-$HOME/.ccache}
729
 
+
730
 
+echo "Do you want to compress or decompress the ccache in $CCACHE_DIR?"
731
 
+read -p "Type c or d: " mode
732
 
+
733
 
+if [ "$mode" != "c" ] && [ "$mode" != "d" ]
734
 
+then
735
 
+    exit 1
736
 
+fi
737
 
+
738
 
+is_compressed() {
739
 
+    test "$(head -c 2 $1)" = $'\x1f\x8b'
740
 
+    return $?
741
 
+}
742
 
+
743
 
+tmpfile=$(mktemp)
744
 
+
745
 
+for dir in 0 1 2 3 4 5 6 7 8 9 a b c d e f
746
 
+do
747
 
+    # process ccache subdir
748
 
+    echo -n "$dir "
749
 
+
750
 
+    # find cache files
751
 
+    find $CCACHE_DIR/$dir -type f -name '*-*' |
752
 
+    sort > $tmpfile
753
 
+
754
 
+    oldsize=$(cat $CCACHE_DIR/$dir/stats | cut -d ' ' -f 13)
755
 
+    newsize=0
756
 
+
757
 
+    while read file
758
 
+    do
759
 
+        # empty files will be ignored since compressing
760
 
+        # them makes them bigger
761
 
+        test $(stat -c %s $file) -eq 0 && continue
762
 
+
763
 
+        if [ $mode = c ]
764
 
+        then
765
 
+            if ! is_compressed $file
766
 
+            then
767
 
+                gzip $file
768
 
+                mv $file.gz $file
769
 
+            fi
770
 
+        else
771
 
+            if is_compressed $file
772
 
+            then
773
 
+                mv $file $file.gz
774
 
+                gzip -d $file.gz
775
 
+            fi
776
 
+        fi
777
 
+
778
 
+        # calculate new size statistic for this subdir
779
 
+        let newsize=$newsize+$(stat -c "%B*%b" $file)/1024
780
 
+    done < $tmpfile
781
 
+
782
 
+    # update statistic file
783
 
+    read -a numbers < $CCACHE_DIR/$dir/stats
784
 
+    numbers[12]=$newsize
785
 
+    echo "${numbers[*]} " > $CCACHE_DIR/$dir/stats
786
 
+done
787
 
+echo
788
 
+
789
 
+# clean up
790
 
+rm $tmpfile
791
 
+
792
 
diff --git a/util.c b/util.c
793
 
index 962dd49..a6b8899 100644
794
 
--- a/util.c
795
 
+++ b/util.c
796
 
@@ -44,6 +44,7 @@ void fatal(const char *msg)
797
 
        exit(1);
798
 
 }
799
 
 
800
 
+#ifndef ENABLE_ZLIB
801
 
 /* copy all data from one file descriptor to another */
802
 
 void copy_fd(int fd_in, int fd_out)
803
 
 {
804
 
@@ -57,6 +58,11 @@ void copy_fd(int fd_in, int fd_out)
805
 
        }
806
 
 }
807
 
 
808
 
+/* move a file using rename */
809
 
+int move_file(const char *src, const char *dest) {
810
 
+       return rename(src, dest);
811
 
+}
812
 
+
813
 
 /* copy a file - used when hard links don't work 
814
 
    the copy is done via a temporary file and atomic rename
815
 
 */
816
 
@@ -120,6 +126,174 @@ int copy_file(const char *src, const char *dest)
817
 
        return 0;
818
 
 }
819
 
 
820
 
+#else /* ENABLE_ZLIB */
821
 
+
822
 
+/* copy all data from one file descriptor to another
823
 
+   possibly decompressing it
824
 
+*/
825
 
+void copy_fd(int fd_in, int fd_out) {
826
 
+       char buf[10240];
827
 
+       int n;
828
 
+       gzFile gz_in;
829
 
+
830
 
+       gz_in = gzdopen(dup(fd_in), "rb");
831
 
+
832
 
+       if (!gz_in) {
833
 
+               fatal("Failed to copy fd");
834
 
+       }
835
 
+
836
 
+       while ((n = gzread(gz_in, buf, sizeof(buf))) > 0) {
837
 
+               if (write(fd_out, buf, n) != n) {
838
 
+                       fatal("Failed to copy fd");
839
 
+               }
840
 
+       }
841
 
+}
842
 
+
843
 
+static int _copy_file(const char *src, const char *dest, int mode) {
844
 
+       int fd_in, fd_out;
845
 
+       gzFile gz_in, gz_out = NULL;
846
 
+       char buf[10240];
847
 
+       int n, ret;
848
 
+       char *tmp_name;
849
 
+       mode_t mask;
850
 
+       struct stat st;
851
 
+
852
 
+       x_asprintf(&tmp_name, "%s.XXXXXX", dest);
853
 
+
854
 
+       if (getenv("CCACHE_NOCOMPRESS")) {
855
 
+               mode = COPY_UNCOMPRESSED;
856
 
+       }
857
 
+
858
 
+       /* open source file */
859
 
+       fd_in = open(src, O_RDONLY);
860
 
+       if (fd_in == -1) {
861
 
+               return -1;
862
 
+       }
863
 
+
864
 
+       gz_in = gzdopen(fd_in, "rb");
865
 
+       if (!gz_in) {
866
 
+               close(fd_in);
867
 
+               return -1;
868
 
+       }
869
 
+
870
 
+       /* open destination file */
871
 
+       fd_out = mkstemp(tmp_name);
872
 
+       if (fd_out == -1) {
873
 
+               gzclose(gz_in);
874
 
+               free(tmp_name);
875
 
+               return -1;
876
 
+       }
877
 
+
878
 
+       if (mode == COPY_TO_CACHE) {
879
 
+               /* The gzip file format occupies at least 20 bytes. So
880
 
+                  it will always occupy an entire filesystem block,
881
 
+                  even for empty files.
882
 
+                  Since most stderr files will be empty, we turn off
883
 
+                  compression in this case to save space.
884
 
+               */
885
 
+               if (fstat(fd_in, &st) != 0) {
886
 
+                       gzclose(gz_in);
887
 
+                       close(fd_out);
888
 
+                       free(tmp_name);
889
 
+                       return -1;
890
 
+               }
891
 
+               if (file_size(&st) == 0) {
892
 
+                       mode = COPY_UNCOMPRESSED;
893
 
+               }
894
 
+       }
895
 
+
896
 
+       if (mode == COPY_TO_CACHE) {
897
 
+               gz_out = gzdopen(dup(fd_out), "wb");
898
 
+               if (!gz_out) {
899
 
+                       gzclose(gz_in);
900
 
+                       close(fd_out);
901
 
+                       free(tmp_name);
902
 
+                       return -1;
903
 
+               }
904
 
+       }
905
 
+
906
 
+       while ((n = gzread(gz_in, buf, sizeof(buf))) > 0) {
907
 
+               if (mode == COPY_TO_CACHE) {
908
 
+                       ret = gzwrite(gz_out, buf, n);
909
 
+               } else {
910
 
+                       ret = write(fd_out, buf, n);
911
 
+               }
912
 
+               if (ret != n) {
913
 
+                       gzclose(gz_in);
914
 
+                       if (gz_out) {
915
 
+                               gzclose(gz_out);
916
 
+                       }
917
 
+                       close(fd_out);
918
 
+                       unlink(tmp_name);
919
 
+                       free(tmp_name);
920
 
+                       return -1;
921
 
+               }
922
 
+       }
923
 
+
924
 
+       gzclose(gz_in);
925
 
+       if (gz_out) {
926
 
+               gzclose(gz_out);
927
 
+       }
928
 
+
929
 
+       /* get perms right on the tmp file */
930
 
+       mask = umask(0);
931
 
+       fchmod(fd_out, 0666 & ~mask);
932
 
+       umask(mask);
933
 
+
934
 
+       /* the close can fail on NFS if out of space */
935
 
+       if (close(fd_out) == -1) {
936
 
+               unlink(tmp_name);
937
 
+               free(tmp_name);
938
 
+               return -1;
939
 
+       }
940
 
+
941
 
+       unlink(dest);
942
 
+
943
 
+       if (rename(tmp_name, dest) == -1) {
944
 
+               unlink(tmp_name);
945
 
+               free(tmp_name);
946
 
+               return -1;
947
 
+       }
948
 
+
949
 
+       free(tmp_name);
950
 
+
951
 
+       return 0;
952
 
+}
953
 
+
954
 
+/* move a file to the cache, compressing it */
955
 
+int move_file(const char *src, const char *dest) {
956
 
+       int ret;
957
 
+
958
 
+       ret = _copy_file(src, dest, COPY_TO_CACHE);
959
 
+       if (ret != -1) unlink(src);
960
 
+       return ret;
961
 
+}
962
 
+
963
 
+/* copy a file from the cache, decompressing it */
964
 
+int copy_file(const char *src, const char *dest) {
965
 
+       return _copy_file(src, dest, COPY_FROM_CACHE);
966
 
+}
967
 
+#endif /* ENABLE_ZLIB */
968
 
+
969
 
+/* test if a file is zlib compressed */
970
 
+int test_if_compressed(const char *filename) {
971
 
+       FILE *f;
972
 
+
973
 
+       f = fopen(filename, "rb");
974
 
+       if (!f) {
975
 
+               return 0;
976
 
+       }
977
 
+
978
 
+       /* test if file starts with 1F8B, which is zlib's
979
 
+        * magic number */
980
 
+       if ((fgetc(f) != 0x1f) || (fgetc(f) != 0x8b)) {
981
 
+               fclose(f);
982
 
+               return 0;
983
 
+       }
984
 
+       
985
 
+       fclose(f);
986
 
+       return 1;
987
 
+}
988
 
 
989
 
 /* make sure a directory exists */
990
 
 int create_dir(const char *dir)