diff --git a/CMakeLists.txt b/CMakeLists.txt index fcc3ea49ad..a473b67095 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -249,7 +249,6 @@ if( CMAKE_C_COMPILER_ID MATCHES "MSVC") /DWIN32_LEAN_AND_MEAN "/DMSC_VER_REQUIRED=${MSC_VER_REQUIRED}" /D_CRT_SECURE_NO_DEPRECATE - /D_CRT_NONSTDC_NO_DEPRECATE # NOMINMAX keeps windows.h from defining "min" and "max" via windef.h. # This avoids conflicts with the C++ standard library. /DNOMINMAX diff --git a/capchild/capture_sync.c b/capchild/capture_sync.c index 310c767f7d..edd0c5de7a 100644 --- a/capchild/capture_sync.c +++ b/capchild/capture_sync.c @@ -1617,7 +1617,7 @@ pipe_read_bytes(int pipe_fd, char *bytes, int required, char **msg) int error; while(required) { - newly = read(pipe_fd, &bytes[offset], required); + newly = ws_read(pipe_fd, &bytes[offset], required); if (newly == 0) { /* EOF */ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, @@ -1684,7 +1684,7 @@ sync_pipe_gets_nonblock(int pipe_fd, char *bytes, int max) { offset++; if (! pipe_data_available(pipe_fd)) break; - newly = read(pipe_fd, &bytes[offset], 1); + newly = ws_read(pipe_fd, &bytes[offset], 1); if (newly == 0) { /* EOF - not necessarily an error */ break; @@ -1771,7 +1771,7 @@ pipe_read_block(int pipe_fd, char *indicator, int len, char *msg, /* we have a problem here, try to read some more bytes from the pipe to debug where the problem really is */ memcpy(msg, header, sizeof(header)); - newly = read(pipe_fd, &msg[sizeof(header)], len-sizeof(header)); + newly = ws_read(pipe_fd, &msg[sizeof(header)], len-sizeof(header)); if (newly < 0) { /* error */ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_DEBUG, "read from pipe %d: error(%u): %s", pipe_fd, errno, g_strerror(errno)); @@ -2189,7 +2189,7 @@ signal_pipe_capquit_to_child(capture_session *cap_session) /* it doesn't matter *what* we send here, the first byte will stop the capture */ /* simply sending a "QUIT" string */ /*pipe_write_block(cap_session->signal_pipe_write_fd, SP_QUIT, quit_msg);*/ - ret = write(cap_session->signal_pipe_write_fd, quit_msg, sizeof quit_msg); + ret = ws_write(cap_session->signal_pipe_write_fd, quit_msg, sizeof quit_msg); if(ret == -1) { g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_WARNING, "signal_pipe_capquit_to_child: %d header: error %s", cap_session->signal_pipe_write_fd, g_strerror(errno)); diff --git a/config.nmake b/config.nmake index df21f81eee..96c2c090a3 100644 --- a/config.nmake +++ b/config.nmake @@ -1037,7 +1037,7 @@ DEBUG_CFLAGS=/O2 "$(MSVC_VARIANT)" == "MSVC2015" || \ "$(MSVC_VARIANT)" == "MSVC2015CE" LOCAL_CFLAGS=/Zi /W3 /MD $(DEBUG_CFLAGS) /DWIN32_LEAN_AND_MEAN /DMSC_VER_REQUIRED=$(MSC_VER_REQUIRED) \ - /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE -DPSAPI_VERSION=1 + /D_CRT_SECURE_NO_DEPRECATE -DPSAPI_VERSION=1 !IF "$(MSVC_VARIANT)" == "MSVC2012" || \ "$(MSVC_VARIANT)" == "MSVC2012EE" || \ diff --git a/editcap.c b/editcap.c index ea9a1656e4..4384a89fbc 100644 --- a/editcap.c +++ b/editcap.c @@ -63,7 +63,6 @@ #endif #ifdef _WIN32 -#include #include #include /* getpid */ #ifdef HAVE_WINSOCK2_H @@ -77,6 +76,7 @@ #include #include +#include #include #include #include @@ -1165,7 +1165,7 @@ main(int argc, char *argv[]) optarg); exit(1); } - srand( (unsigned int) (time(NULL) + getpid()) ); + srand( (unsigned int) (time(NULL) + ws_getpid()) ); break; case 'F': @@ -2014,4 +2014,3 @@ handle_chopping(chop_t chop, struct wtap_pkthdr *out_phdr, * vi: set shiftwidth=4 tabstop=8 expandtab: * :indentSize=4:tabSize=8:noTabs=true: */ - diff --git a/epan/diam_dict.l b/epan/diam_dict.l index 47aa11eb50..a82d81c5f2 100644 --- a/epan/diam_dict.l +++ b/epan/diam_dict.l @@ -94,6 +94,16 @@ #include #include +/* + * Deprecated CRT functions. We call malloc+free quite a bit here. We could + * probably improve startup performance by using wmem instead. + */ +#ifdef _WIN32 +#define ws_strdup _strdup +#else +#define ws_strdup strdup +#endif + typedef struct entity_t { char* name; char* file; @@ -284,10 +294,10 @@ description_attr description=\042 } {xmlpi_key_attr} BEGIN XMLPI_GETKEY; -{ndquot} { yyextra->xmlpi->key = strdup(yytext); BEGIN XMLPI_ATTRS; } +{ndquot} { yyextra->xmlpi->key = ws_strdup(yytext); BEGIN XMLPI_ATTRS; } {xmlpi_value_attr} BEGIN XMLPI_GETVAL; -{ndquot} { yyextra->xmlpi->value = strdup(yytext); BEGIN XMLPI_ATTRS; } +{ndquot} { yyextra->xmlpi->value = ws_strdup(yytext); BEGIN XMLPI_ATTRS; } . {xmlpi_end} BEGIN LOADING; @@ -296,14 +306,14 @@ description_attr description=\042 {start_entity} BEGIN ENTITY; {entityname} { entity_t* e = g_new(entity_t,1); - e->name = strdup(yytext); + e->name = ws_strdup(yytext); e->next = yyextra->ents; yyextra->ents = e; BEGIN GET_SYSTEM; }; {system} BEGIN GET_FILE; {ndquot} { - yyextra->ents->file = strdup(yytext); + yyextra->ents->file = ws_strdup(yytext); BEGIN END_ENTITY; } {end_entity} BEGIN LOADING; @@ -384,7 +394,7 @@ description_attr description=\042 {ndquot} { - *(yyextra->attr_str) = strdup(yytext); + *(yyextra->attr_str) = ws_strdup(yytext); D(("%s\n",yytext)); yyextra->attr_str = NULL; BEGIN END_ATTR; @@ -540,7 +550,7 @@ description_attr description=\042 {stop_end} { BEGIN IN_APPL; } -{grouped_start} { yyextra->avp->type = strdup("Grouped"); }; +{grouped_start} { yyextra->avp->type = ws_strdup("Grouped"); }; {grouped_end} ; {type_start} { BEGIN TYPE_ATTRS; } diff --git a/epan/dissectors/packet-ssl-utils.c b/epan/dissectors/packet-ssl-utils.c index b534144eac..29df42fc27 100644 --- a/epan/dissectors/packet-ssl-utils.c +++ b/epan/dissectors/packet-ssl-utils.c @@ -3777,7 +3777,7 @@ ssl_load_key(FILE* fp) gint ret; guint bytes; - if (ws_fstat64(fileno(fp), &statbuf) == -1) { + if (ws_fstat64(ws_fileno(fp), &statbuf) == -1) { ssl_debug_printf("ssl_load_key: can't ws_fstat64 file\n"); return NULL; } @@ -4655,7 +4655,7 @@ file_needs_reopen(FILE *fp, const char *filename) /* consider a file deleted when stat fails for either file, * or when the residing device / inode has changed. */ - if (0 != ws_fstat64(fileno(fp), &open_stat)) + if (0 != ws_fstat64(ws_fileno(fp), &open_stat)) return TRUE; if (0 != ws_stat64(filename, ¤t_stat)) return TRUE; diff --git a/sync_pipe_write.c b/sync_pipe_write.c index c7aa3eb03b..fbcadcf797 100644 --- a/sync_pipe_write.c +++ b/sync_pipe_write.c @@ -49,7 +49,7 @@ pipe_write_header(int pipe_fd, char indicator, int length) header[3] = (length >> 0) & 0xFF; /* write header */ - return write(pipe_fd, header, sizeof header); + return ws_write(pipe_fd, header, sizeof header); } @@ -80,7 +80,7 @@ pipe_write_block(int pipe_fd, char indicator, const char *msg) /* write value (if we have one) */ if(len) { /*g_warning("write %d indicator: %c value len: %u msg: %s", pipe_fd, indicator, len, msg);*/ - ret = write(pipe_fd, msg, len); + ret = ws_write(pipe_fd, msg, len); if(ret == -1) { return; } diff --git a/tshark.c b/tshark.c index 408c3be0a6..c97945f12f 100644 --- a/tshark.c +++ b/tshark.c @@ -2280,9 +2280,9 @@ main(int argc, char *argv[]) * suppress the information printed for each packet, but it'll * also suppress the packet counts. */ - if (!isatty(fileno(stderr))) + if (!ws_isatty(ws_fileno(stderr))) print_packet_counts = FALSE; - else if (print_packet_info && isatty(fileno(stdout))) + else if (print_packet_info && ws_isatty(ws_fileno(stdout))) print_packet_counts = FALSE; else if (quiet) print_packet_counts = FALSE; diff --git a/ui/qt/follow_stream_dialog.cpp b/ui/qt/follow_stream_dialog.cpp index 750627fbc4..9f04263571 100644 --- a/ui/qt/follow_stream_dialog.cpp +++ b/ui/qt/follow_stream_dialog.cpp @@ -491,7 +491,7 @@ void FollowStreamDialog::addText(QString text, gboolean is_from_server, guint32 { size_t nwritten; int FileDescriptor = file_.handle(); - FILE* fh = fdopen(dup(FileDescriptor), "wb"); + FILE* fh = ws_fdopen(ws_dup(FileDescriptor), "wb"); if (show_type_ == SHOW_RAW) { QByteArray binstream = QByteArray::fromHex(text.toUtf8()); nwritten = fwrite(binstream.constData(), binstream.length(), 1, fh); diff --git a/wiretap/file_access.c b/wiretap/file_access.c index 146715d48f..03f2e7ed52 100644 --- a/wiretap/file_access.c +++ b/wiretap/file_access.c @@ -2283,7 +2283,7 @@ wtap_dump_open_tempfile_ng(char **filenamep, const char *pfx, fh = wtap_dump_file_fdopen(wdh, fd); if (fh == NULL) { *err = errno; - close(fd); + ws_close(fd); g_free(wdh); return NULL; /* can't create file */ } @@ -2461,7 +2461,7 @@ wtap_dump_open_finish(wtap_dumper *wdh, int file_type_subtype, gboolean compress if(compressed) { cant_seek = TRUE; } else { - fd = fileno((FILE *)wdh->fh); + fd = ws_fileno((FILE *)wdh->fh); if (ws_lseek64(fd, 1, SEEK_CUR) == (off_t) -1) cant_seek = TRUE; else { diff --git a/wsutil/file_util.h b/wsutil/file_util.h index 1588ced5de..d10cc817f7 100644 --- a/wsutil/file_util.h +++ b/wsutil/file_util.h @@ -121,6 +121,15 @@ WS_DLL_PUBLIC FILE * ws_stdio_freopen (const gchar *filename, const gchar *mode, #define ws_fstat64 _fstati64 /* use _fstati64 for 64-bit size support */ #define ws_lseek64 _lseeki64 /* use _lseeki64 for 64-bit offset support */ #define ws_fdopen _fdopen +#define ws_fileno _fileno +#define ws_isatty _isatty + +/* + * Other CRT functions. getpid probably belongs in sys_util.h or proc_util.h + * but neither yet exist. + */ +#define ws_getpid _getpid +#define ws_umask _umask /* DLL loading */ @@ -189,8 +198,14 @@ WS_DLL_PUBLIC void create_app_running_mutex(); #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 */ #define ws_fdopen fdopen +#define ws_fileno fileno +#define ws_isatty isatty #define O_BINARY 0 /* Win32 needs the O_BINARY flag for open() */ +/* Other CRT functions */ +#define ws_getpid getpid +#define ws_umask umask + #endif /* _WIN32 */ /* directory handling */ diff --git a/wsutil/tempfile.c b/wsutil/tempfile.c index 4be05f8b84..2835735006 100644 --- a/wsutil/tempfile.c +++ b/wsutil/tempfile.c @@ -65,7 +65,7 @@ mkstemp (char *path_template) } if (g_snprintf (&path_template[len - 5], 6, "%.5u", - (unsigned int) getpid () % 100000) != 5) + (unsigned int) ws_getpid () % 100000) != 5) /* Inconceivable lossage. */ return -1; @@ -109,7 +109,7 @@ mkdtemp (char *path_template) } if (g_snprintf (&path_template[len - 5], 6, "%.5u", - (unsigned int) getpid () % 100000) != 5) + (unsigned int) ws_getpid () % 100000) != 5) /* Inconceivable lossage. */ return NULL; @@ -221,9 +221,9 @@ create_tempfile(char **namebuf, const char *pfx) the umask to 0077 to take away all group and other permissions, attempt to create the file, and then put the umask back. */ - old_umask = umask(0077); + old_umask = ws_umask(0077); fd = mkstemp(tf[idx].path); - umask(old_umask); + ws_umask(old_umask); return fd; }