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 * SPDX-License-Identifier: GPL-2.0-or-later
20 #include <epan/packet_info.h>
23 #include <wiretap/wtap.h>
25 #include <wsutil/file_util.h>
27 #include <ui/alert_box.h>
29 #include "export_object_ui.h"
32 eo_save_entry(const gchar *save_as_filename, export_object_entry_t *entry, gboolean show_err)
37 ssize_t bytes_written;
41 to_fd = ws_open(save_as_filename, O_WRONLY | O_CREAT | O_EXCL |
43 if(to_fd == -1) { /* An error occurred */
45 open_failure_alert_box(save_as_filename, errno, TRUE);
50 * The third argument to _write() on Windows is an unsigned int,
51 * so, on Windows, that's the size of the third argument to
54 * The third argument to write() on UN*X is a size_t, although
55 * the return value is an ssize_t, so one probably shouldn't
56 * write more than the max value of an ssize_t.
58 * In either case, there's no guarantee that a gint64 such as
59 * payload_len can be passed to ws_write(), so we write in
60 * chunks of, at most 2^31 bytes.
62 ptr = entry->payload_data;
63 bytes_left = entry->payload_len;
64 while (bytes_left != 0) {
65 if (bytes_left > 0x40000000)
66 bytes_to_write = 0x40000000;
68 bytes_to_write = (int)bytes_left;
69 bytes_written = ws_write(to_fd, ptr, bytes_to_write);
70 if(bytes_written <= 0) {
71 if (bytes_written < 0)
74 err = WTAP_ERR_SHORT_WRITE;
76 write_failure_alert_box(save_as_filename, err);
80 bytes_left -= bytes_written;
83 if (ws_close(to_fd) < 0) {
85 write_failure_alert_box(save_as_filename, errno);
98 * indent-tabs-mode: nil
101 * ex: set shiftwidth=4 tabstop=8 expandtab:
102 * :indentSize=4:tabSize=8:noTabs=true: