Commit a55a78d1 by Nathanael Nerode

re PR fastjar/9532 (jar -C flag is incompatible with Sun's (fastjar uses…

re PR fastjar/9532 (jar -C flag is incompatible with Sun's (fastjar uses nonportable feature of getcwd))

	PR java/9532
	* jartool.c (main) Give proper error messages with -C, and
	check for missing arguments properly.  Send error messages
	to stderr.
	* jartool.c (add_to_jar): Make getcwd() call portable,
	and check for error return.

From-SVN: r67985
parent 3d57a5cc
2003-06-15 Nathanael Nerode <neroden@gcc.gnu.org>
PR java/9532
* jartool.c (main) Give proper error messages with -C, and
check for missing arguments properly. Send error messages
to stderr.
* jartool.c (add_to_jar): Make getcwd() call portable,
and check for error return.
2003-03-30 Joseph S. Myers <jsm@polyomino.org.uk> 2003-03-30 Joseph S. Myers <jsm@polyomino.org.uk>
* fastjar.texi: Remove @ at start of file. * fastjar.texi: Remove @ at start of file.
......
...@@ -507,15 +507,19 @@ int main(int argc, char **argv){ ...@@ -507,15 +507,19 @@ int main(int argc, char **argv){
if(!strcmp(arg, "-C")){ if(!strcmp(arg, "-C")){
const char *dir_to_change = get_next_arg (); const char *dir_to_change = get_next_arg ();
const char *file_to_add = get_next_arg (); const char *file_to_add = get_next_arg ();
if(!dir_to_change if (!dir_to_change || !file_to_add) {
|| !file_to_add fprintf(stderr, "Error: missing argument for -C.\n");
|| add_to_jar(jarfd, dir_to_change, file_to_add)){ exit(1);
printf("Error adding %s to jar archive!\n", arg); }
if (add_to_jar(jarfd, dir_to_change, file_to_add)) {
fprintf(stderr,
"Error adding %s (in directory %s) to jar archive!\n",
file_to_add, dir_to_change);
exit(1); exit(1);
} }
} else { } else {
if(add_to_jar(jarfd, NULL, arg)){ if(add_to_jar(jarfd, NULL, arg)){
printf("Error adding %s to jar archive!\n", arg); fprintf(stderr, "Error adding %s to jar archive!\n", arg);
exit(1); exit(1);
} }
} }
...@@ -817,8 +821,8 @@ int add_to_jar(int fd, const char *new_dir, const char *file){ ...@@ -817,8 +821,8 @@ int add_to_jar(int fd, const char *new_dir, const char *file){
struct dirent *de; struct dirent *de;
zipentry *ze; zipentry *ze;
int stat_return; int stat_return;
char *old_dir = NULL; char old_dir[MAXPATHLEN];
/* This is a quick compatibility fix -- Simon Weijgers <simon@weijgers.com> /* This is a quick compatibility fix -- Simon Weijgers <simon@weijgers.com>
* It fixes this: * It fixes this:
* "normal" jar : org/apache/java/io/LogRecord.class * "normal" jar : org/apache/java/io/LogRecord.class
...@@ -830,10 +834,12 @@ int add_to_jar(int fd, const char *new_dir, const char *file){ ...@@ -830,10 +834,12 @@ int add_to_jar(int fd, const char *new_dir, const char *file){
file+=2; file+=2;
/* If new_dir isn't null, we need to change to that directory. However, /* If new_dir isn't null, we need to change to that directory. However,
we also need to return to the old directory when we're done */ we also need to return to the old directory when we're done. See below.*/
if(new_dir != NULL){ if(new_dir != NULL){
old_dir = getcwd(NULL, 0); if (getcwd(old_dir, MAXPATHLEN) == NULL) {
perror("getcwd");
return 1;
}
if(chdir(new_dir) == -1){ if(chdir(new_dir) == -1){
perror(new_dir); perror(new_dir);
return 1; return 1;
...@@ -957,11 +963,13 @@ int add_to_jar(int fd, const char *new_dir, const char *file){ ...@@ -957,11 +963,13 @@ int add_to_jar(int fd, const char *new_dir, const char *file){
fprintf(stderr, "Illegal file specified: %s\n", file); fprintf(stderr, "Illegal file specified: %s\n", file);
} }
if(old_dir != NULL){ /* If (and only if!) new_dir != NULL, we switched directories, so
if(chdir(old_dir)) we have to switch back to the old directory. */
if (new_dir != NULL) {
if (chdir(old_dir) == -1) {
perror(old_dir); perror(old_dir);
return 1;
free(old_dir); }
} }
return 0; return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment