diff options
author | doko <doko@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-07-06 21:40:08 +0000 |
---|---|---|
committer | doko <doko@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-07-06 21:40:08 +0000 |
commit | 1f445250410fd24b8185675685c85d401fb9538d (patch) | |
tree | cede115c5e69e77d0b68edda7dfceb560ccb5b15 /fastjar/compress.c | |
parent | 5e611c5f37d48ca2c450c2cbd1a28f7be2422863 (diff) | |
download | gcc-1f445250410fd24b8185675685c85d401fb9538d.tar.gz |
2004-07-06 Matthias Klose <doko@debian.org>
* Makefile.in: Regenerate.
* fastjar.texi: Update for '-u'.
2004-05-19 Casey Marshall <csm@gnu.org>
PR 7854
* Makefile.am
(jar_SOURCES): added shift.c, shift.h.
(jar_CPPFLAGS): define WITH_SHIFT_DOWN.
* compress.c
Added FSF copyright.
(write_data): new function.
(compress_file): call write_data.
* jartool.c
Updated copyright year.
(progname): new variable.
(end_of_entries): new variable.
(main): open and read file when updating.
(find_entry): new function.
(looks_like_dir): new function.
(read_entries): new function.
(make_manifest): added parameter `updating'.
Call `add_file_to_jar' with `updating'.
(add_to_jar_with_dir): added parameter `updating'.
Call `add_to_jar' with `updating'.
(add_to_jar): added parameter `updating'.
Call `add_file_to_jar' with `updating'.
Don't add directories if they already exist.
(add_file_to_jar): added parameter `updating'.
Update entries if they already exist.
* jartool.h
Added #ifndef __FASTJAR_JARTOOL_H__.
(struct zipentry): added `flags'.
* shift.c: new file.
* shift.h: new file.
* zipfile.h
(CEN_FLAGS): new constant.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@84171 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'fastjar/compress.c')
-rw-r--r-- | fastjar/compress.c | 72 |
1 files changed, 55 insertions, 17 deletions
diff --git a/fastjar/compress.c b/fastjar/compress.c index fa7bc2ed3f1..ec1d5c4b7ab 100644 --- a/fastjar/compress.c +++ b/fastjar/compress.c @@ -74,6 +74,7 @@ /* compress.c - code for handling deflation Copyright (C) 1999 Bryan Burns + Copyright (C) 2004 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 @@ -109,8 +110,12 @@ #include "jartool.h" #include "pushback.h" #include "compress.h" +#include "shift.h" + +int write_data (int, void *, size_t, struct zipentry *); extern int seekable; +extern off_t end_of_entries; static z_stream zs; @@ -133,7 +138,36 @@ void init_compression(){ } } -int compress_file(int in_fd, int out_fd, struct zipentry *ze){ +int +write_data (int fd, void *buf, size_t len, struct zipentry *ze) +{ +#ifdef WITH_SHIFT_DOWN + struct zipentry *next = NULL; + off_t here = lseek (fd, 0, SEEK_CUR); + /* + * If we are updating and there is not enough space before the next + * entry, expand the file. + */ + if (ze) + { + next = ze->next_entry; + if (next && here + len >= next->offset) + { + if (shift_down (fd, next->offset, (here + len) - next->offset, next)) + { + perror ("can't expand file"); + exit (1); + } + } + } +#endif /* WITH_SHIFT_DOWN */ + + return write (fd, buf, len); +} + +int compress_file(int in_fd, int out_fd, struct zipentry *ze, + struct zipentry *existing) +{ Bytef in_buff[RDSZ]; Bytef out_buff[RDSZ]; unsigned int rdamt, wramt; @@ -183,10 +217,11 @@ int compress_file(int in_fd, int out_fd, struct zipentry *ze){ /* If the output buffer is full, dump it to disk */ if(zs.avail_out == 0){ - if(write(out_fd, out_buff, RDSZ) != RDSZ){ - perror("write"); - exit(1); - } + if (write_data (out_fd, out_buff, RDSZ, existing) != RDSZ) + { + perror("write"); + exit(1); + } /* clear the output buffer */ zs.next_out = out_buff; @@ -201,10 +236,11 @@ int compress_file(int in_fd, int out_fd, struct zipentry *ze){ wramt = RDSZ - zs.avail_out; - if(write(out_fd, out_buff, wramt) != (int)wramt){ - perror("write"); - exit(1); - } + if (write_data (out_fd, out_buff, wramt, existing) != (int)wramt) + { + perror("write"); + exit(1); + } /* clear the output buffer */ zs.next_out = out_buff; zs.avail_out = (uInt)RDSZ; @@ -215,10 +251,11 @@ int compress_file(int in_fd, int out_fd, struct zipentry *ze){ while(deflate(&zs, Z_FINISH) == Z_OK){ wramt = RDSZ - zs.avail_out; - if(write(out_fd, out_buff, wramt) != (int)wramt){ - perror("write"); - exit(1); - } + if (write_data (out_fd, out_buff, wramt, existing) != (int)wramt) + { + perror("write"); + exit(1); + } zs.next_out = out_buff; zs.avail_out = (uInt)RDSZ; @@ -228,10 +265,11 @@ int compress_file(int in_fd, int out_fd, struct zipentry *ze){ if(zs.avail_out != RDSZ){ wramt = RDSZ - zs.avail_out; - if(write(out_fd, out_buff, wramt) != (int)wramt){ - perror("write"); - exit(1); - } + if (write_data (out_fd, out_buff, wramt, existing) != (int)wramt) + { + perror("write"); + exit(1); + } } /* update fastjar's entry information */ |