This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Patch: fix fastjar -C
- From: Per Bothner <per at bothner dot com>
- To: Anthony Green <green at cygnus dot com>
- Cc: gcc-patches at gcc dot gnu dot org, tromey at redhat dot com
- Date: Sat, 23 Feb 2002 13:18:06 -0800
- Subject: Re: Patch: fix fastjar -C
- References: <200202232104.NAA16405@makita.cygnus.com>
Anthony Green wrote:
> jar was complaining that -C is an unrecognized option. This appears
> to fix.
I just ran into the same bug, and a similar patch (attached - but
including some other stuff).
The difference is that my patch handles '-C DIR' as a unit, rather
than just handling '-C'. Either should work, as long as DIR doesn't
start with a '-'. I think the way I did it is probably cleaner, though.
--
--Per Bothner
per@bothner.com http://www.bothner.com/per/
Index: jartool.c
===================================================================
RCS file: /cvs/gcc/gcc/fastjar/jartool.c,v
retrieving revision 1.12
diff -u -p -r1.12 jartool.c
--- jartool.c 2002/01/31 00:52:16 1.12
+++ jartool.c 2002/02/23 21:13:10
@@ -274,6 +274,7 @@ int make_manifest(int, const char*);
static void init_args(char **, int);
static char *get_next_arg (void);
static char *jt_strdup (char*);
+static void *xmalloc (size_t);
static void expand_options (int *argcp, char ***argvp);
/* global variables */
@@ -304,7 +305,7 @@ int number_of_entries; /* number of entr
#define OPT_HELP LONG_OPT (0)
/* This holds all options except `-C', which is handled specially. */
-#define OPTION_STRING "-ctxuvVf:m:0ME@"
+#define OPTION_STRING "-ctxuvVf:m:C:0ME@"
static const struct option options[] =
{
@@ -348,6 +349,9 @@ int main(int argc, char **argv){
while ((opt = getopt_long (argc, argv, OPTION_STRING,
options, NULL)) != -1) {
switch(opt){
+ case 'C':
+ new_argv[new_argc++] = "-C";
+ /* ... fall through ... */
case 1:
/* File name or unparsed option, due to RETURN_IN_ORDER. In
particular `-C' is handled here and not elsewhere. */
@@ -362,9 +366,12 @@ int main(int argc, char **argv){
case 'x':
action = ACTION_EXTRACT;
break;
- case 'u':
+ case 'U':
action = ACTION_UPDATE;
break;
+ case 'u':
+ fprintf(stderr, "update action does not work - use 'U' to force\n");
+ exit(1);
case 'v':
verbose = TRUE;
break;
@@ -700,11 +707,7 @@ int make_manifest(int jfd, const char *m
if(verbose)
printf("adding: META-INF/ (in=0) (out=0) (stored 0%%)\n");
- ze = (zipentry*)malloc(sizeof(zipentry));
- if(ze == NULL){
- perror("malloc");
- exit(1);
- }
+ ze = (zipentry*)xmalloc(sizeof(zipentry));
memset(ze, 0, sizeof(zipentry)); /* clear all the fields*/
ze->filename = (char*)malloc((nlen + 1) * sizeof(char) + 1);
@@ -749,11 +752,7 @@ int make_manifest(int jfd, const char *m
if(verbose)
printf("adding: META-INF/MANIFEST.MF (in=56) (out=56) (stored 0%%)\n");
- ze = (zipentry*)malloc(sizeof(zipentry));
- if(ze == NULL){
- perror("malloc");
- exit(1);
- }
+ ze = (zipentry*)xmalloc(sizeof(zipentry));
memset(ze, 0, sizeof(zipentry)); /* clear all the fields*/
ze->filename = (char*)malloc((nlen + 1) * sizeof(char) + 1);
@@ -893,11 +892,7 @@ int add_to_jar(int fd, const char *new_d
if(verbose)
printf("adding: %s (in=%d) (out=%d) (stored 0%%)\n", fullname, 0, 0);
- ze = (zipentry*)malloc(sizeof(zipentry));
- if(ze == NULL){
- perror("malloc");
- exit(1);
- }
+ ze = (zipentry*)xmalloc(sizeof(zipentry));
memset(ze, 0, sizeof(zipentry)); /* clear all the fields*/
ze->filename = (char*)malloc((nlen + 1) * sizeof(char) + 1);
@@ -1007,11 +1002,7 @@ int add_file_to_jar(int jfd, int ffd, co
} else
memset((file_header + LOC_CRC), '\0', 12); /* clear crc/usize/csize */
- ze = (zipentry*)malloc(sizeof(zipentry));
- if(ze == NULL){
- perror("malloc");
- exit(1);
- }
+ ze = (zipentry*)xmalloc(sizeof(zipentry));
memset(ze, 0, sizeof(zipentry)); /* clear all the fields*/
ze->filename = (char*)malloc((file_name_length + 1) * sizeof(char));
@@ -1663,6 +1654,18 @@ int list_jar(int fd, char **files, int f
filename_len = fnlen + 1;
}
+#if 0
+ ze = (zipentry*)xmalloc(sizeof(zipentry));
+ ze->mod_time = UNPACK_UB2(file_header, LOC_COMP);
+ ze->crc = UNPACK_UB4(cen_header, CEN_CRC);
+ ze->mod_time = UNPACK_UB2(cen_header, CEN_MODTIME);
+ ze->mod_date = UNPACK_UB2(cen_header, CEN_MODDATE);
+ ze->csize = UNPACK_UB4(cen_header, CEN_CSIZE);
+ ze->usize = UNPACK_UB4(cen_header, CEN_USIZE);
+ ze->offset = UNPACK_UB4(cen_header, CEN_OFFSET);
+ ze->compressed = UNPACK_UB2(cen_header, CEN_COMP) != 0;
+#endif
+
if(read(fd, filename, fnlen) != fnlen){
perror("read");
exit(1);
@@ -1925,6 +1928,18 @@ jt_strdup(s)
return (char*)0;
strcpy(result, s);
return result;
+}
+
+static void *
+xmalloc (size_t nbytes)
+{
+ void *ptr = malloc (nbytes);
+ if (ptr == NULL)
+ {
+ perror("malloc");
+ exit(1);
+ }
+ return ptr;
}
/* Convert "tar-style" first argument to a form expected by getopt.