Have fileset_extract_prefix_suffix() print an error message if it fails,

so we don't just exit silently.  Don't bother checking the validity of
arguments - it shouldn't be passed NULL fprefix or fsuffix arguments in
the first place, and isn't passed them.

Exit with an exit status of 1 for command-line syntax errors and 2 for
file open/close/IO errors.

svn path=/trunk/; revision=28458
This commit is contained in:
Guy Harris 2009-05-23 20:29:12 +00:00
parent dc3b1136cc
commit 5e8e10cfa3
1 changed files with 13 additions and 12 deletions

View File

@ -186,9 +186,10 @@ fileset_extract_prefix_suffix(const char *fname, gchar **fprefix, gchar **fsuffi
gchar *save_file;
save_file = g_strdup(fname);
if (!fprefix || !fsuffix || !save_file)
return FALSE;
if (save_file == NULL) {
fprintf(stderr, "editcap: Out of memory\n");
return FALSE;
}
last_pathsep = strrchr(save_file, G_DIR_SEPARATOR);
pfx = strrchr(save_file,'.');
@ -936,7 +937,7 @@ main(int argc, char *argv[])
g_free(err_info);
break;
}
exit(1);
exit(2);
}
@ -976,7 +977,7 @@ main(int argc, char *argv[])
if (split_packet_count > 0 || secs_per_block > 0) {
if (!fileset_extract_prefix_suffix(argv[optind+1], &fprefix, &fsuffix))
exit(5);
exit(2);
filename = fileset_get_filename_by_pattern(block_cnt++, &phdr->ts, fprefix, fsuffix);
} else
@ -988,7 +989,7 @@ main(int argc, char *argv[])
if (pdh == NULL) {
fprintf(stderr, "editcap: Can't open or create %s: %s\n", filename,
wtap_strerror(err));
exit(1);
exit(2);
}
}
@ -1002,7 +1003,7 @@ main(int argc, char *argv[])
if (!wtap_dump_close(pdh, &err)) {
fprintf(stderr, "editcap: Error writing to %s: %s\n", filename,
wtap_strerror(err));
exit(1);
exit(2);
}
block_start.secs = block_start.secs + secs_per_block; /* reset for next interval */
g_free(filename);
@ -1019,7 +1020,7 @@ main(int argc, char *argv[])
if (pdh == NULL) {
fprintf(stderr, "editcap: Can't open or create %s: %s\n", filename,
wtap_strerror(err));
exit(1);
exit(2);
}
}
}
@ -1032,7 +1033,7 @@ main(int argc, char *argv[])
if (!wtap_dump_close(pdh, &err)) {
fprintf(stderr, "editcap: Error writing to %s: %s\n", filename,
wtap_strerror(err));
exit(1);
exit(2);
}
g_free(filename);
@ -1048,7 +1049,7 @@ main(int argc, char *argv[])
if (pdh == NULL) {
fprintf(stderr, "editcap: Can't open or create %s: %s\n", filename,
wtap_strerror(err));
exit(1);
exit(2);
}
}
}
@ -1222,7 +1223,7 @@ main(int argc, char *argv[])
&err)) {
fprintf(stderr, "editcap: Error writing to %s: %s\n",
filename, wtap_strerror(err));
exit(1);
exit(2);
}
written_count++;
}
@ -1253,7 +1254,7 @@ main(int argc, char *argv[])
fprintf(stderr, "editcap: Error writing to %s: %s\n", filename,
wtap_strerror(err));
exit(1);
exit(2);
}
}