diff options
author | Guy Harris <guy@alum.mit.edu> | 2015-11-08 02:31:01 -0800 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2015-11-08 10:32:09 +0000 |
commit | caa1e87410fb74606f2ec91b5fd1b897053149bf (patch) | |
tree | 7d46afa570a24957716f5b74add64760bfeb5079 | |
parent | 11bdadacc27d3781c3fd0d759068fddd3da9107c (diff) |
Use ws_{read,write,fdopen,close}.
Be more consistent about using the ws_ routines, as we suggest in
README.developer.
In C++ on UN*X, define ws_close as ::close rather than close, so that it
works even in classes with methods or members named "close".
Change-Id: Ide2652229e6b6b4624cbddae0e909a4ea1efa591
Reviewed-on: https://code.wireshark.org/review/11637
Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r-- | dumpcap.c | 4 | ||||
-rw-r--r-- | rawshark.c | 6 | ||||
-rw-r--r-- | ui/cli/tap-follow.c | 2 | ||||
-rw-r--r-- | ui/gtk/follow_tcp.c | 2 | ||||
-rw-r--r-- | ui/gtk/iax2_analysis.c | 14 | ||||
-rw-r--r-- | ui/qt/main_window_slots.cpp | 10 | ||||
-rw-r--r-- | ui/win32/file_dlg_win32.c | 6 | ||||
-rw-r--r-- | wiretap/file_access.c | 4 | ||||
-rw-r--r-- | wiretap/file_wrappers.c | 8 | ||||
-rw-r--r-- | wsutil/file_util.h | 7 |
10 files changed, 35 insertions, 28 deletions
@@ -220,9 +220,9 @@ enable_kernel_bpf_jit_compiler(void) if (fd < 0) return; - written = write(fd, "1", strlen("1")); + written = ws_write(fd, "1", strlen("1")); - close(fd); + ws_close(fd); } #endif diff --git a/rawshark.c b/rawshark.c index 78e3e83448..1becd58a04 100644 --- a/rawshark.c +++ b/rawshark.c @@ -830,7 +830,7 @@ DIAG_ON(cast-qual) size_t bytes_left = sizeof(struct pcap_hdr) + sizeof(guint32); gchar buf[sizeof(struct pcap_hdr) + sizeof(guint32)]; while (bytes_left != 0) { - ssize_t bytes = read(fd, buf, (int)bytes_left); + ssize_t bytes = ws_read(fd, buf, (int)bytes_left); if (bytes <= 0) { cmdarg_err("Not enough bytes for pcap header."); exit(2); @@ -883,7 +883,7 @@ raw_pipe_read(struct wtap_pkthdr *phdr, guchar * pd, int *err, gchar **err_info, /* Copied from capture_loop.c */ while (bytes_needed > 0) { - bytes_read = read(fd, ptr, (int)bytes_needed); + bytes_read = ws_read(fd, ptr, (int)bytes_needed); if (bytes_read == 0) { *err = 0; *err_info = NULL; @@ -929,7 +929,7 @@ raw_pipe_read(struct wtap_pkthdr *phdr, guchar * pd, int *err, gchar **err_info, ptr = pd; while (bytes_needed > 0) { - bytes_read = read(fd, ptr, (int)bytes_needed); + bytes_read = ws_read(fd, ptr, (int)bytes_needed); if (bytes_read == 0) { *err = WTAP_ERR_SHORT_READ; *err_info = NULL; diff --git a/ui/cli/tap-follow.c b/ui/cli/tap-follow.c index a436f502f1..12239dade3 100644 --- a/ui/cli/tap-follow.c +++ b/ui/cli/tap-follow.c @@ -272,7 +272,7 @@ followFileOpen( followExit("Error duping temp file name."); } - fp->filep = fdopen(fd, "w+b"); + fp->filep = ws_fdopen(fd, "w+b"); if (fp->filep == NULL) { ws_close(fd); diff --git a/ui/gtk/follow_tcp.c b/ui/gtk/follow_tcp.c index aece6aabd6..369a756b3e 100644 --- a/ui/gtk/follow_tcp.c +++ b/ui/gtk/follow_tcp.c @@ -142,7 +142,7 @@ follow_tcp_stream_cb(GtkWidget * w _U_, gpointer data _U_) return; } - data_out_file = fdopen(tmp_fd, "w+b"); + data_out_file = ws_fdopen(tmp_fd, "w+b"); if (data_out_file == NULL) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Could not create temporary file %s: %s", diff --git a/ui/gtk/iax2_analysis.c b/ui/gtk/iax2_analysis.c index 56a10f9770..66eaa00ee5 100644 --- a/ui/gtk/iax2_analysis.c +++ b/ui/gtk/iax2_analysis.c @@ -2364,7 +2364,7 @@ static gboolean copy_file(gchar *dest, gint channels, gint format, user_data_t * case SAVE_FORWARD_DIRECTION_MASK: { progbar_count = user_data->forward.saveinfo.count; progbar_quantum = user_data->forward.saveinfo.count/100; - while ((fread_cnt = read(forw_fd, f_pd, 1)) > 0) { + while ((fread_cnt = ws_read(forw_fd, f_pd, 1)) > 0) { if (stop_flag) break; if ((count > progbar_nextstep) && (count <= progbar_count)) { @@ -2405,7 +2405,7 @@ static gboolean copy_file(gchar *dest, gint channels, gint format, user_data_t * case SAVE_REVERSE_DIRECTION_MASK: { progbar_count = user_data->reversed.saveinfo.count; progbar_quantum = user_data->reversed.saveinfo.count/100; - while ((rread = read(rev_fd, r_pd, 1)) > 0) { + while ((rread = ws_read(rev_fd, r_pd, 1)) > 0) { if (stop_flag) break; if ((count > progbar_nextstep) && (count <= progbar_count)) { @@ -2468,7 +2468,7 @@ static gboolean copy_file(gchar *dest, gint channels, gint format, user_data_t * } count++; if (f_write_silence > 0) { - rread = read(rev_fd, r_pd, 1); + rread = ws_read(rev_fd, r_pd, 1); switch (user_data->forward.statinfo.reg_pt) { case AST_FORMAT_ULAW: *f_pd = SILENCE_PCMU; @@ -2481,7 +2481,7 @@ static gboolean copy_file(gchar *dest, gint channels, gint format, user_data_t * f_write_silence--; } else if (r_write_silence > 0) { - fread_cnt = read(forw_fd, f_pd, 1); + fread_cnt = ws_read(forw_fd, f_pd, 1); switch (user_data->reversed.statinfo.reg_pt) { case AST_FORMAT_ULAW: *r_pd = SILENCE_PCMU; @@ -2494,8 +2494,8 @@ static gboolean copy_file(gchar *dest, gint channels, gint format, user_data_t * r_write_silence--; } else { - fread_cnt = read(forw_fd, f_pd, 1); - rread = read(rev_fd, r_pd, 1); + fread_cnt = ws_read(forw_fd, f_pd, 1); + rread = ws_read(rev_fd, r_pd, 1); } if ((rread == 0) && (fread_cnt == 0)) break; @@ -2561,7 +2561,7 @@ static gboolean copy_file(gchar *dest, gint channels, gint format, user_data_t * /* XXX how do you just copy the file? */ - while ((rread = read(fd, pd, 1)) > 0) { + while ((rread = ws_read(fd, pd, 1)) > 0) { if (stop_flag) break; if ((count > progbar_nextstep) && (count <= progbar_count)) { diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index e4eab4e43a..d4867b8050 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -1652,12 +1652,12 @@ void MainWindow::on_actionFileExportPacketBytes_triggered() open_failure_alert_box(file_name.toUtf8().constData(), errno, TRUE); return; } - if (write(fd, data_p, capture_file_.capFile()->finfo_selected->length) < 0) { + if (ws_write(fd, data_p, capture_file_.capFile()->finfo_selected->length) < 0) { write_failure_alert_box(file_name.toUtf8().constData(), errno); - ::close(fd); + ws_close(fd); return; } - if (::close(fd) < 0) { + if (ws_close(fd) < 0) { write_failure_alert_box(file_name.toUtf8().constData(), errno); return; } @@ -1726,11 +1726,11 @@ void MainWindow::on_actionFileExportSSLSessionKeys_triggered() */ if (ws_write(fd, keylist, (unsigned int)strlen(keylist)) < 0) { write_failure_alert_box(file_name.toUtf8().constData(), errno); - ::close(fd); + ws_close(fd); g_free(keylist); return; } - if (::close(fd) < 0) { + if (ws_close(fd) < 0) { write_failure_alert_box(file_name.toUtf8().constData(), errno); g_free(keylist); return; diff --git a/ui/win32/file_dlg_win32.c b/ui/win32/file_dlg_win32.c index d9b5d026c1..9e9c32d6c5 100644 --- a/ui/win32/file_dlg_win32.c +++ b/ui/win32/file_dlg_win32.c @@ -797,12 +797,12 @@ win32_export_raw_file(HWND h_wnd, capture_file *cf) { open_failure_alert_box(file_name8, errno, TRUE); return; } - if (write(fd, data_p, cf->finfo_selected->length) < 0) { + if (ws_write(fd, data_p, cf->finfo_selected->length) < 0) { write_failure_alert_box(file_name8, errno); - close(fd); + ws_close(fd); return; } - if (close(fd) < 0) { + if (ws_close(fd) < 0) { write_failure_alert_box(file_name8, errno); return; } diff --git a/wiretap/file_access.c b/wiretap/file_access.c index fad807bd2f..9d59f1274c 100644 --- a/wiretap/file_access.c +++ b/wiretap/file_access.c @@ -2513,14 +2513,14 @@ wtap_dump_file_fdopen(wtap_dumper *wdh, int fd) if(wdh->compressed) { return gzwfile_fdopen(fd); } else { - return fdopen(fd, "wb"); + return ws_fdopen(fd, "wb"); } } #else static WFILE_T wtap_dump_file_fdopen(wtap_dumper *wdh _U_, int fd) { - return fdopen(fd, "wb"); + return ws_fdopen(fd, "wb"); } #endif diff --git a/wiretap/file_wrappers.c b/wiretap/file_wrappers.c index ea3ee3f0b4..5b4cbd27da 100644 --- a/wiretap/file_wrappers.c +++ b/wiretap/file_wrappers.c @@ -146,7 +146,7 @@ raw_read(FILE_T state, unsigned char *buf, unsigned int count, guint *have) *have = 0; do { - ret = read(state->fd, buf + *have, count - *have); + ret = ws_read(state->fd, buf + *have, count - *have); if (ret <= 0) break; *have += (unsigned)ret; @@ -1498,7 +1498,7 @@ gzwfile_open(const char *path) state = gzwfile_fdopen(fd); if (state == NULL) { save_errno = errno; - close(fd); + ws_close(fd); errno = save_errno; } return state; @@ -1603,7 +1603,7 @@ gz_comp(GZWFILE_T state, int flush) (flush != Z_FINISH || ret == Z_STREAM_END))) { have = strm->next_out - state->next; if (have) { - got = write(state->fd, state->next, (unsigned int)have); + got = ws_write(state->fd, state->next, (unsigned int)have); if (got < 0) { state->err = errno; return -1; @@ -1732,7 +1732,7 @@ gzwfile_close(GZWFILE_T state) g_free(state->out); g_free(state->in); state->err = Z_OK; - if (close(state->fd) == -1 && ret == 0) + if (ws_close(state->fd) == -1 && ret == 0) ret = errno; g_free(state); return ret; diff --git a/wsutil/file_util.h b/wsutil/file_util.h index dff51bbe83..813c349cfc 100644 --- a/wsutil/file_util.h +++ b/wsutil/file_util.h @@ -182,7 +182,14 @@ WS_DLL_PUBLIC void create_app_running_mutex(); #define ws_read read #define ws_write write +#ifdef __cplusplus +/* + * Just in case this is used in a class with a close method or member. + */ +#define ws_close ::close +#else #define ws_close close +#endif #define ws_dup dup #define ws_fstat64 fstat /* AC_SYS_LARGEFILE should make off_t 64-bit */ #define ws_lseek64 lseek /* AC_SYS_LARGEFILE should make off_t 64-bit */ |