Windows: Remove the need for _CRT_NONSTDC_NO_DEPRECATE.

Replace some function calls with their non-deprecated equivalents so
that we can remove _CRT_NONSTDC_NO_DEPRECATE from CMakeLists.txt and
config.nmake.

Leave _CRT_SECURE_NO_DEPRECATE in place. Removing it failed with 145
warnings and 72 errors.

Note that we could probably improve startup performance by using wmem
in diam_dict.*.

Change-Id: I6e130003de838aebedbdd1aa78c50de8a339ddcb
Reviewed-on: https://code.wireshark.org/review/14883
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
Gerald Combs 2016-04-11 11:31:17 -07:00 committed by Michael Mann
parent f6b8b4dca5
commit cf6501eb45
12 changed files with 51 additions and 28 deletions

View File

@ -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

View File

@ -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));

View File

@ -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" || \

View File

@ -63,7 +63,6 @@
#endif
#ifdef _WIN32
#include <wsutil/file_util.h>
#include <wsutil/unicode-utils.h>
#include <process.h> /* getpid */
#ifdef HAVE_WINSOCK2_H
@ -77,6 +76,7 @@
#include <wsutil/crash_info.h>
#include <wsutil/filesystem.h>
#include <wsutil/file_util.h>
#include <wsutil/md5.h>
#include <wsutil/plugins.h>
#include <wsutil/privileges.h>
@ -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:
*/

View File

@ -94,6 +94,16 @@
#include <epan/to_str.h>
#include <wsutil/file_util.h>
/*
* 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_ATTRS>{xmlpi_key_attr} BEGIN XMLPI_GETKEY;
<XMLPI_GETKEY>{ndquot} { yyextra->xmlpi->key = strdup(yytext); BEGIN XMLPI_ATTRS; }
<XMLPI_GETKEY>{ndquot} { yyextra->xmlpi->key = ws_strdup(yytext); BEGIN XMLPI_ATTRS; }
<XMLPI_ATTRS>{xmlpi_value_attr} BEGIN XMLPI_GETVAL;
<XMLPI_GETVAL>{ndquot} { yyextra->xmlpi->value = strdup(yytext); BEGIN XMLPI_ATTRS; }
<XMLPI_GETVAL>{ndquot} { yyextra->xmlpi->value = ws_strdup(yytext); BEGIN XMLPI_ATTRS; }
<XMLPI_ATTRS>.
<XMLPI_ATTRS>{xmlpi_end} BEGIN LOADING;
@ -296,14 +306,14 @@ description_attr description=\042
<LOADING>{start_entity} BEGIN ENTITY;
<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;
};
<GET_SYSTEM>{system} BEGIN GET_FILE;
<GET_FILE>{ndquot} {
yyextra->ents->file = strdup(yytext);
yyextra->ents->file = ws_strdup(yytext);
BEGIN END_ENTITY;
}
<END_ENTITY>{end_entity} BEGIN LOADING;
@ -384,7 +394,7 @@ description_attr description=\042
<GET_ATTR>{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
<AVP_ATTRS>{stop_end} { BEGIN IN_APPL; }
<IN_AVP>{grouped_start} { yyextra->avp->type = strdup("Grouped"); };
<IN_AVP>{grouped_start} { yyextra->avp->type = ws_strdup("Grouped"); };
<IN_AVP>{grouped_end} ;
<IN_AVP>{type_start} { BEGIN TYPE_ATTRS; }

View File

@ -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, &current_stat))
return TRUE;

View File

@ -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;
}

View File

@ -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;

View File

@ -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);

View File

@ -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 {

View File

@ -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 */

View File

@ -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;
}