Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a "windows.h" helper include file
As we use Win Socket 2 library is a good idea to always include
winsock2.h before windows.h to avoid some potential issues calling
functions with wrong parameters.

Note that samples and public headers won't include this new header.

This was also suggested by some patches by
Aaron M. Ucko <ucko@ncbi.nlm.nih.gov>.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
  • Loading branch information
freddy77 committed Oct 29, 2018
1 parent 29266e2 commit 0085e91
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 21 deletions.
1 change: 1 addition & 0 deletions include/freetds/Makefile.am
Expand Up @@ -22,6 +22,7 @@ noinst_HEADERS = \
checks.h \
alloca.h \
macros.h \
windows.h \
utils.h \
utils/string.h \
utils/dlist.h \
Expand Down
4 changes: 1 addition & 3 deletions include/freetds/sysdep_private.h
Expand Up @@ -56,9 +56,7 @@ typedef int pid_t;
#endif /* defined(DOS32X) */

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64)
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
#include <freetds/windows.h>
#define READSOCKET(a,b,c) recv((a), (char *) (b), (c), TDS_NOSIGNAL)
#define WRITESOCKET(a,b,c) send((a), (const char *) (b), (c), TDS_NOSIGNAL)
#define CLOSESOCKET(a) closesocket((a))
Expand Down
2 changes: 1 addition & 1 deletion include/freetds/thread.h
Expand Up @@ -119,7 +119,7 @@ static inline int tds_thread_is_current(tds_thread_id th)

#elif defined(_WIN32)

#include <windows.h>
#include <freetds/windows.h>
#include <errno.h>

/* old version of Windows do not define this constant */
Expand Down
29 changes: 29 additions & 0 deletions include/freetds/windows.h
@@ -0,0 +1,29 @@
/* FreeTDS - Library of routines accessing Sybase and Microsoft databases
* Copyright (C) 2018 Frediano Ziglio
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/

#ifndef freetds_windows_h_
#define freetds_windows_h_

#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
#endif

#endif /* freetds_windows_h_ */
5 changes: 1 addition & 4 deletions src/apps/bsqlodbc.c
Expand Up @@ -47,10 +47,7 @@
#include <locale.h>
#endif

#ifdef HAVE_WINDOWS_H
#include <winsock2.h>
#include <windows.h>
#endif
#include <freetds/windows.h>

#include "tds_sysdep_public.h"
#include <sql.h>
Expand Down
3 changes: 1 addition & 2 deletions src/apps/defncopy.c
Expand Up @@ -36,8 +36,7 @@ int getopt(int argc, const char *argv[], char *optstring);
# define WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN_DEFINED_HERE
# endif
# include <windows.h>
# include <winsock2.h>
# include <freetds/windows.h>
# ifdef WIN32_LEAN_AND_MEAN_DEFINED_HERE
# undef WIN32_LEAN_AND_MEAN_DEFINED_HERE
# undef WIN32_LEAN_AND_MEAN
Expand Down
2 changes: 1 addition & 1 deletion src/dblib/unittests/common.h
Expand Up @@ -23,7 +23,7 @@
#endif /* HAVE_STRING_H */

#ifdef DBNTWIN32
#include <windows.h>
#include <freetds/windows.h>
/* fix MingW missing declare */
#ifndef _WINDOWS_
#define _WINDOWS_ 1
Expand Down
3 changes: 1 addition & 2 deletions src/odbc/unittests/common.h
@@ -1,7 +1,6 @@
#ifdef _WIN32
#define _CRT_SECURE_NO_WARNINGS 1
#include <winsock2.h>
#include <windows.h>
#include <freetds/windows.h>
#include <direct.h>
#endif

Expand Down
5 changes: 1 addition & 4 deletions src/replacements/socketpair.c
Expand Up @@ -21,10 +21,7 @@

#if !defined(HAVE_SOCKETPAIR)

#if defined(_WIN32)
#include <winsock2.h>
#include <windows.h>
#endif
#include <freetds/windows.h>

#if HAVE_UNISTD_H
#include <unistd.h>
Expand Down
3 changes: 1 addition & 2 deletions src/tds/sspi.c
Expand Up @@ -36,8 +36,7 @@
#if HAVE_SSPI
#define SECURITY_WIN32

#include <winsock2.h>
#include <windows.h>
#include <freetds/windows.h>
#include <security.h>
#include <sspi.h>
#include <rpc.h>
Expand Down
2 changes: 1 addition & 1 deletion src/utils/win_mutex.c
Expand Up @@ -29,7 +29,7 @@
#include <string.h>
#endif /* HAVE_STRING_H */

#include <windows.h>
#include <freetds/windows.h>
#include <freetds/thread.h>

#include "ptw32_MCS_lock.c"
Expand Down
2 changes: 1 addition & 1 deletion win32/initnet.c
Expand Up @@ -4,7 +4,7 @@
#include <crtdbg.h>
#endif

#include <windows.h>
#include <freetds/windows.h>

#ifdef DLL_EXPORT

Expand Down

0 comments on commit 0085e91

Please sign in to comment.