In Tethereal:

When capturing, report errors trying to create the output file
	with "file_open_error_message()".

	Make the "for_writing" argument to "file_open_error_message()" a
	"gboolean", as it's either TRUE (if the file is being opened for
	writing) or FALSE (if it's being opened for reading).

	Report EISDIR as "XXX is a directory (folder), not a file.".

When checking whether an "open()" of a capture file succeeded, check
whether "open()" returns a negative number, not whether it returns 0.

In "wtap_open_offline()", if the file to be opened is a directory,
return EISDIR, not WTAP_ERR_NOT_REGULAR_FILE, so that the error message
can say "that's a directory, not a file".

If "wtap_open_offline()" returns WTAP_ERR_NOT_REGULAR_FILE, don't just
say the file is "invalid", say it's a "special file" or socket or some
other weird type of file.

svn path=/trunk/; revision=2144
This commit is contained in:
Guy Harris 2000-07-20 09:39:43 +00:00
parent 024c2d72fe
commit e068b7dbe7
3 changed files with 18 additions and 42 deletions

4
file.c
View File

@ -1,7 +1,7 @@
/* file.c
* File I/O routines
*
* $Id: file.c,v 1.199 2000/07/20 05:09:45 guy Exp $
* $Id: file.c,v 1.200 2000/07/20 09:39:19 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -1819,7 +1819,7 @@ file_open_error_message(int err, gboolean for_writing)
switch (err) {
case WTAP_ERR_NOT_REGULAR_FILE:
errmsg = "The file \"%s\" is invalid.";
errmsg = "The file \"%s\" is a \"special file\" or socket or other non-regular file.";
break;
case WTAP_ERR_FILE_UNKNOWN_FORMAT:

View File

@ -1,6 +1,6 @@
/* tethereal.c
*
* $Id: tethereal.c,v 1.35 2000/07/09 03:29:29 guy Exp $
* $Id: tethereal.c,v 1.36 2000/07/20 09:39:23 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -567,40 +567,8 @@ capture(int packet_count, int out_file_type)
ld.linktype, pcap_snapshot(ld.pch), &err);
if (ld.pdh == NULL) {
/* We couldn't set up to write to the capture file. */
switch (err) {
case WTAP_ERR_UNSUPPORTED_FILE_TYPE:
strcpy(errmsg, "Tethereal does not support writing capture files in that format.");
break;
case WTAP_ERR_UNSUPPORTED_ENCAP:
case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED:
strcpy(errmsg, "Tethereal cannot save this capture in that format.");
break;
case WTAP_ERR_CANT_OPEN:
strcpy(errmsg, "The file to which the capture would be written"
" couldn't be created for some unknown reason.");
break;
case WTAP_ERR_SHORT_WRITE:
strcpy(errmsg, "A full header couldn't be written to the file"
" to which the capture would be written.");
break;
default:
if (err < 0) {
sprintf(errmsg, "The file to which the capture would be"
" written (\"%s\") could not be opened: Error %d.",
cfile.save_file, err);
} else {
sprintf(errmsg, "The file to which the capture would be"
" written (\"%s\") could not be opened: %s.",
cfile.save_file, strerror(err));
}
break;
}
snprintf(errmsg, sizeof errmsg, file_open_error_message(errno, TRUE),
cfile.save_file);
goto error;
}
}
@ -956,7 +924,7 @@ wtap_dispatch_cb_print(u_char *user, const struct wtap_pkthdr *phdr, int offset,
}
char *
file_open_error_message(int err, int for_writing)
file_open_error_message(int err, gboolean for_writing)
{
char *errmsg;
static char errmsg_errno[1024+1];
@ -964,7 +932,7 @@ file_open_error_message(int err, int for_writing)
switch (err) {
case WTAP_ERR_NOT_REGULAR_FILE:
errmsg = "The file \"%s\" is invalid.";
errmsg = "The file \"%s\" is a \"special file\" or socket or other non-regular file.";
break;
case WTAP_ERR_FILE_UNKNOWN_FORMAT:
@ -1020,6 +988,10 @@ file_open_error_message(int err, int for_writing)
errmsg = "You do not have permission to read the file \"%s\".";
break;
case EISDIR:
errmsg = "\"%s\" is a directory (folder), not a file.";
break;
default:
sprintf(errmsg_errno, "The file \"%%s\" could not be opened: %s.",
wtap_strerror(err));

View File

@ -1,6 +1,6 @@
/* file.c
*
* $Id: file.c,v 1.54 2000/06/24 05:32:46 guy Exp $
* $Id: file.c,v 1.55 2000/07/20 09:39:43 guy Exp $
*
* Wiretap Library
* Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
@ -126,7 +126,10 @@ wtap* wtap_open_offline(const char *filename, int *err, gboolean do_random)
}
#ifndef WIN32
if (! S_ISREG(statb.st_mode) && ! S_ISFIFO(statb.st_mode)) {
*err = WTAP_ERR_NOT_REGULAR_FILE;
if (S_ISDIR(statb.st_mode))
*err = EISDIR;
else
*err = WTAP_ERR_NOT_REGULAR_FILE;
return NULL;
}
#endif
@ -145,7 +148,8 @@ wtap* wtap_open_offline(const char *filename, int *err, gboolean do_random)
/* Open the file */
errno = WTAP_ERR_CANT_OPEN;
if (!(wth->fd = open(filename, O_RDONLY|O_BINARY))) {
wth->fd = open(filename, O_RDONLY|O_BINARY);
if (wth->fd < 0) {
*err = errno;
g_free(wth);
return NULL;