Ethereal-dev: Re: [Ethereal-dev] save silently fails on Win XP

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Guy Harris <guy@xxxxxxxxxxxx>
Date: Fri, 23 Jan 2004 16:30:24 -0800

On Jan 23, 2004, at 1:40 PM, Ulf Lamping wrote:

Well, if you press the ok button in the file save (as) dialog, this starts the function "file_open_ok_cb" in file gtk/file_dlg.c.

I would hope that it wouldn't, given that "file_open_ok_cb()" is the function called for the "OK" button in the "File->Open" dialog.

It should be calling "file_save_as_ok_cb()" - and, in fact, it is.

The actual file access is in one of the calls named cf_xy(), probably the cf_open() call.

No, "cf_save()", in the case of "file_save_as_ok_cb()".

Hint: Have a call to simple_dialog() to make a message to the user.

"cf_save()" will, if you're saving a temporary capture file, in its entirety, in standard libpcap format, first try to call "rename()" to move the file to its target location.

If "rename()" returns 0, it is presumed to have succeeded, and no message is displayed. Perhaps "rename()" returns 0 even when it fails on Windows; if that were the case, it would at best be an extreme bogosity on Windows, and at worst an actual bug. However, Microsoft's documentation suggests that it does *not* return 0 when it fails, but behaves sufficiently similarly to UNIX's "rename()" as to be usable in Ethereal:

http://msdn.microsoft.com/library/en-us/vclib/html/ _crt_rename.2c_._wrename.asp?frame=true

If "rename()" doesn't return 0, then, if it returns EXDEV, that's assumed to mean "you can't just move the file because the target is on a different file system", and Ethereal copies the file and removes the old file instead. Otherwise, it uses "simple_dialog()" to put up an error message alert box.

If the "rename()" got EXDEV, or you're doing a "Save As" of a permanent file in the same format that it's currently in, a raw binary copy of the file will be done. If the routine that copies it, "copy_binary_file()", fails, it will pop up an error message alert box using "simple_dialog()".

If you're saving the file in a format other than the one it's already in, or saving only some of the packets in the file, "cf_save()" will call "wtap_dump_open()" to create the output file. If that fails, it'll call "simple_dialog()" to put up an error message alert box.