From: Steve Hay Date: Thu, 23 Nov 2006 11:06:47 +0000 (+0000) Subject: Silence VC8's warnings about "unsafe" CRT functions and POSIX CRT X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c5b31784e02aac7c0b7f5bd436ee6d2fd57bbcf0;p=p5sagit%2Fp5-mst-13.2.git Silence VC8's warnings about "unsafe" CRT functions and POSIX CRT function names being deprecated, and add a note to perltodo to revisit this one day. p4raw-id: //depot/perl@29358 --- diff --git a/pod/perltodo.pod b/pod/perltodo.pod index c084177..026f2f6 100644 --- a/pod/perltodo.pod +++ b/pod/perltodo.pod @@ -376,6 +376,29 @@ Currently, numerous functions look virtually, if not completely, identical in both C and C files, which can't be good. +=head2 Use secure CRT functions when building with VC8 on Win32 + +Visual C++ 2005 (VC++ 8.x) deprecated a number of CRT functions on the basis +that they were "unsafe" and introduced differently named secure versions of +them as replacements, e.g. instead of writing + + FILE* f = fopen(__FILE__, "r"); + +one should now write + + FILE* f; + errno_t err = fopen_s(&f, __FILE__, "r"); + +Currently, the warnings about these deprecations have been disabled by adding +-D_CRT_SECURE_NO_DEPRECATE to the CFLAGS. It would be nice to remove that +warning suppressant and actually make use of the new secure CRT functions. + +There is also a similar issue with POSIX CRT function names like fileno having +been deprecated in favour of ISO C++ conformant names like _fileno. These +warnings are also currently suppressed with the compiler option /wd4996. It +might be nice to do as Microsoft suggest here too, although, unlike the secure +functions issue, there is presumably little or no benefit in this case. + =head1 Tasks that need a knowledge of XS These tasks would need C knowledge, and roughly the level of knowledge of diff --git a/win32/Makefile b/win32/Makefile index bf0a1bb..e4573b5 100644 --- a/win32/Makefile +++ b/win32/Makefile @@ -454,6 +454,12 @@ DEFINES = $(DEFINES) -DWIN64 -DCONSERVATIVE OPTIMIZE = $(OPTIMIZE) -Wp64 -fp:precise !ENDIF +# For now, silence VC++ 8.x's warnings about "unsafe" CRT functions and POSIX +# CRT function names being deprecated. +!IF "$(CCTYPE)" == "MSVC80" || "$(CCTYPE)" == "MSVC80FREE" +DEFINES = $(DEFINES) -D_CRT_SECURE_NO_DEPRECATE -wd4996 +!ENDIF + # Use the MSVCRT read() fix if the PerlCRT was not chosen, but only when using # VC++ 6.x or earlier. Later versions use MSVCR70.dll, MSVCR71.dll, etc, which # do not require the fix. diff --git a/win32/makefile.mk b/win32/makefile.mk index 764e3d3..09f4b57 100644 --- a/win32/makefile.mk +++ b/win32/makefile.mk @@ -565,6 +565,12 @@ DEFINES += -DWIN64 -DCONSERVATIVE OPTIMIZE += -Wp64 -fp:precise .ENDIF +# For now, silence VC++ 8.x's warnings about "unsafe" CRT functions and POSIX +# CRT function names being deprecated. +.IF "$(CCTYPE)" == "MSVC80" || "$(CCTYPE)" == "MSVC80FREE" +DEFINES += -D_CRT_SECURE_NO_DEPRECATE -wd4996 +.ENDIF + # Use the MSVCRT read() fix if the PerlCRT was not chosen, but only when using # VC++ 6.x or earlier. Later versions use MSVCR70.dll, MSVCR71.dll, etc, which # do not require the fix.