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 */
19 #include <epan/packet_info.h>
22 #include <wiretap/wtap.h>
24 #include <wsutil/file_util.h>
26 #include <ui/alert_box.h>
28 #include "export_object_ui.h"
31 eo_save_entry(const gchar *save_as_filename, export_object_entry_t *entry, gboolean show_err)
36 ssize_t bytes_written;
40 to_fd = ws_open(save_as_filename, O_WRONLY | O_CREAT | O_EXCL |
42 if(to_fd == -1) { /* An error occurred */
44 open_failure_alert_box(save_as_filename, errno, TRUE);
49 * The third argument to _write() on Windows is an unsigned int,
50 * so, on Windows, that's the size of the third argument to
53 * The third argument to write() on UN*X is a size_t, although
54 * the return value is an ssize_t, so one probably shouldn't
55 * write more than the max value of an ssize_t.
57 * In either case, there's no guarantee that a gint64 such as
58 * payload_len can be passed to ws_write(), so we write in
59 * chunks of, at most 2^31 bytes.
61 ptr = entry->payload_data;
62 bytes_left = entry->payload_len;
63 while (bytes_left != 0) {
64 if (bytes_left > 0x40000000)
65 bytes_to_write = 0x40000000;
67 bytes_to_write = (int)bytes_left;
68 bytes_written = ws_write(to_fd, ptr, bytes_to_write);
69 if(bytes_written <= 0) {
70 if (bytes_written < 0)
73 err = WTAP_ERR_SHORT_WRITE;
75 write_failure_alert_box(save_as_filename, err);
79 bytes_left -= bytes_written;
82 if (ws_close(to_fd) < 0) {
84 write_failure_alert_box(save_as_filename, errno);
97 * indent-tabs-mode: nil
100 * ex: set shiftwidth=4 tabstop=8 expandtab:
101 * :indentSize=4:tabSize=8:noTabs=true: