2 * Common routines for tracking & saving objects found in streams of data
3 * Copyright 2007, Stephen Fisher (see AUTHORS file)
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
33 #include <epan/packet_info.h>
36 #include <wiretap/wtap.h>
38 #include <wsutil/file_util.h>
40 #include <ui/alert_box.h>
42 #include "export_object_ui.h"
45 eo_save_entry(const gchar *save_as_filename, export_object_entry_t *entry, gboolean show_err)
50 ssize_t bytes_written;
54 to_fd = ws_open(save_as_filename, O_WRONLY | O_CREAT | O_EXCL |
56 if(to_fd == -1) { /* An error occurred */
58 open_failure_alert_box(save_as_filename, errno, TRUE);
63 * The third argument to _write() on Windows is an unsigned int,
64 * so, on Windows, that's the size of the third argument to
67 * The third argument to write() on UN*X is a size_t, although
68 * the return value is an ssize_t, so one probably shouldn't
69 * write more than the max value of an ssize_t.
71 * In either case, there's no guarantee that a gint64 such as
72 * payload_len can be passed to ws_write(), so we write in
73 * chunks of, at most 2^31 bytes.
75 ptr = entry->payload_data;
76 bytes_left = entry->payload_len;
77 while (bytes_left != 0) {
78 if (bytes_left > 0x40000000)
79 bytes_to_write = 0x40000000;
81 bytes_to_write = (int)bytes_left;
82 bytes_written = ws_write(to_fd, ptr, bytes_to_write);
83 if(bytes_written <= 0) {
84 if (bytes_written < 0)
87 err = WTAP_ERR_SHORT_WRITE;
89 write_failure_alert_box(save_as_filename, err);
93 bytes_left -= bytes_written;
96 if (ws_close(to_fd) < 0) {
98 write_failure_alert_box(save_as_filename, errno);
111 * indent-tabs-mode: nil
114 * ex: set shiftwidth=4 tabstop=8 expandtab:
115 * :indentSize=4:tabSize=8:noTabs=true: