From f0f4af42871aa8004747ce3df025e4cfef4d2d07 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 6 Jan 2013 21:02:57 +0100 Subject: [PATCH] Fixed warnings on VC++. --- examples/CMakeLists.txt | 4 ++++ examples/heightmap.c | 2 -- src/monitor.c | 2 +- support/getopt.c | 6 ++++++ support/tinycthread.c | 13 +++++++++---- tests/CMakeLists.txt | 4 ++++ tests/events.c | 2 -- tests/joysticks.c | 4 ++++ 8 files changed, 28 insertions(+), 9 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 723244d3..42aede9e 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -11,6 +11,10 @@ endif() include_directories(${GLFW_SOURCE_DIR}/include ${GLFW_SOURCE_DIR}/support) +if (MSVC) + add_definitions(-D_CRT_SECURE_NO_WARNINGS) +endif() + if (NOT APPLE) # HACK: This is NOTFOUND on OS X 10.8 include_directories(${OPENGL_INCLUDE_DIR}) diff --git a/examples/heightmap.c b/examples/heightmap.c index 34838640..352d0e3a 100644 --- a/examples/heightmap.c +++ b/examples/heightmap.c @@ -23,8 +23,6 @@ // //======================================================================== -#define _CRT_SECURE_NO_WARNINGS - #include #include #include diff --git a/src/monitor.c b/src/monitor.c index 0fae07a3..6a6e8b91 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -228,7 +228,7 @@ void _glfwDestroyMonitors(void) const GLFWvidmode* _glfwChooseVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* desired) { - unsigned int i; + int i; unsigned int sizeDiff, leastSizeDiff = UINT_MAX; unsigned int colorDiff, leastColorDiff = UINT_MAX; const GLFWvidmode* current; diff --git a/support/getopt.c b/support/getopt.c index 6ff6ef99..7b3decd2 100644 --- a/support/getopt.c +++ b/support/getopt.c @@ -34,13 +34,19 @@ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. */ +#ifndef _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS +#endif #include #include #include #include "getopt.h" +/* 2013-01-06 Camilla Berglund + * + * Only define _CRT_SECURE_NO_WARNINGS if not already defined. + */ /* 2012-08-12 Lambert Clara * * Constify third argument of getopt. diff --git a/support/tinycthread.c b/support/tinycthread.c index ced7cf3f..670857eb 100644 --- a/support/tinycthread.c +++ b/support/tinycthread.c @@ -21,6 +21,11 @@ freely, subject to the following restrictions: distribution. */ +/* 2013-01-06 Camilla Berglund + * + * Added casts from time_t to DWORD to avoid warnings on VC++. + */ + #include "tinycthread.h" #include @@ -291,8 +296,8 @@ int cnd_timedwait(cnd_t *cond, mtx_t *mtx, const struct timespec *ts) struct timespec now; if (clock_gettime(TIME_UTC, &now) == 0) { - DWORD delta = (ts->tv_sec - now.tv_sec) * 1000 + - (ts->tv_nsec - now.tv_nsec + 500000) / 1000000; + DWORD delta = (DWORD) ((ts->tv_sec - now.tv_sec) * 1000 + + (ts->tv_nsec - now.tv_nsec + 500000) / 1000000); return _cnd_timedwait_win32(cond, mtx, delta); } else @@ -471,8 +476,8 @@ int thrd_sleep(const struct timespec *time_point, struct timespec *remaining) #if defined(_TTHREAD_WIN32_) /* Delta in milliseconds */ - delta = (time_point->tv_sec - now.tv_sec) * 1000 + - (time_point->tv_nsec - now.tv_nsec + 500000) / 1000000; + delta = (DWORD) ((time_point->tv_sec - now.tv_sec) * 1000 + + (time_point->tv_nsec - now.tv_nsec + 500000) / 1000000); if (delta > 0) { Sleep(delta); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d6629933..49cc1dc6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -16,6 +16,10 @@ endif() include_directories(${GLFW_SOURCE_DIR}/include ${GLFW_SOURCE_DIR}/support) +if (MSVC) + add_definitions(-D_CRT_SECURE_NO_WARNINGS) +endif() + if (NOT APPLE) # HACK: This is NOTFOUND on OS X 10.8 include_directories(${OPENGL_INCLUDE_DIR}) diff --git a/tests/events.c b/tests/events.c index 1b99f037..596eab0f 100644 --- a/tests/events.c +++ b/tests/events.c @@ -31,8 +31,6 @@ // //======================================================================== -#define _CRT_SECURE_NO_WARNINGS - #include #include diff --git a/tests/joysticks.c b/tests/joysticks.c index 0be3e3df..90dbe588 100644 --- a/tests/joysticks.c +++ b/tests/joysticks.c @@ -34,6 +34,10 @@ #include #include +#ifdef _MSC_VER +#define strdup(x) _strdup(x) +#endif + typedef struct Joystick { GLboolean present;