From 4c293169146d5727082884e9547948978c87ffc9 Mon Sep 17 00:00:00 2001 From: Frederik Carlier Date: Sun, 19 Apr 2015 14:00:16 +0200 Subject: [PATCH 1/6] Visual C++ Compatibility: Configuration and Compatibility headers Add msc_config.h file which contains definitions for inline, __func__ and various definitions that make the Visual C++ compiler be compatible with the libusbmuxd codebase collection.c, socket.c, libusbmuxd.c: Include msc_config.h --- common/collection.c | 4 ++++ common/socket.c | 4 ++++ src/libusbmuxd.c | 4 ++++ src/msc_config.h | 29 +++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 src/msc_config.h diff --git a/common/collection.c b/common/collection.c index ccc4016..15006b1 100644 --- a/common/collection.c +++ b/common/collection.c @@ -23,6 +23,10 @@ #include #endif +#ifdef _MSC_VER +#include "..\src\msc_config.h" +#endif + #include #include #include diff --git a/common/socket.c b/common/socket.c index 27b93ba..eb1f083 100644 --- a/common/socket.c +++ b/common/socket.c @@ -19,6 +19,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifdef _MSC_VER +#include "..\src\msc_config.h" +#endif + #include #include #include diff --git a/src/libusbmuxd.c b/src/libusbmuxd.c index af8636b..15e476b 100644 --- a/src/libusbmuxd.c +++ b/src/libusbmuxd.c @@ -30,6 +30,10 @@ #include #endif +#ifdef _MSC_VER +#include "msc_config.h" +#endif + #ifdef WIN32 #define USBMUXD_API __declspec( dllexport ) #else diff --git a/src/msc_config.h b/src/msc_config.h new file mode 100644 index 0000000..7b16e11 --- /dev/null +++ b/src/msc_config.h @@ -0,0 +1,29 @@ +/* +* msc_config.h +* Contains definitions that will help the Visual C++ compiler compile +* the libimobiledevice code base. +* +* Copyright (c) 2015 Frederik Carlier, Quamotion bvba. All Rights Reserved. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifdef _MSC_VER +#define inline __inline +#define WIN32_LEAN_AND_MEAN +#define _CRT_SECURE_NO_WARNINGS +#define _WINSOCK_DEPRECATED_NO_WARNINGS +#define __func__ __FUNCTION__ +#endif From fe2722e7d7e771667be40498860be09f05bee997 Mon Sep 17 00:00:00 2001 From: Frederik Carlier Date: Sun, 19 Apr 2015 14:06:50 +0200 Subject: [PATCH 2/6] Visual C++ compatibility Move config.h, msc_config.h to the top o --- src/libusbmuxd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libusbmuxd.c b/src/libusbmuxd.c index 15e476b..6a53adb 100644 --- a/src/libusbmuxd.c +++ b/src/libusbmuxd.c @@ -20,12 +20,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include -#include -#include -#include -#include - #ifdef HAVE_CONFIG_H #include #endif @@ -34,6 +28,12 @@ #include "msc_config.h" #endif +#include +#include +#include +#include +#include + #ifdef WIN32 #define USBMUXD_API __declspec( dllexport ) #else From 8f1b2d74a656e18a43d5c241e7867903243b8665 Mon Sep 17 00:00:00 2001 From: Frederik Carlier Date: Sun, 19 Apr 2015 14:42:46 +0200 Subject: [PATCH 3/6] Visual C++ Compatibility: Define PACK macro Packing structs is done differently on MSVC and GCC --- include/usbmuxd-proto.h | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/include/usbmuxd-proto.h b/include/usbmuxd-proto.h index 9ad5f71..793fc08 100644 --- a/include/usbmuxd-proto.h +++ b/include/usbmuxd-proto.h @@ -32,6 +32,12 @@ #define USBMUXD_SOCKET_FILE "/var/run/usbmuxd" #endif +#ifndef _MSC_VER +#define PACK( __Declaration__ ) __Declaration__ __attribute__((__packed__)) +#else +#define PACK( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop) ) +#endif + #ifdef __cplusplus extern "C" { #endif @@ -57,36 +63,36 @@ enum usbmuxd_msgtype { MESSAGE_PLIST = 8, }; -struct usbmuxd_header { +PACK(struct usbmuxd_header { uint32_t length; // length of message, including header uint32_t version; // protocol version uint32_t message; // message type uint32_t tag; // responses to this query will echo back this tag -} __attribute__((__packed__)); +}); -struct usbmuxd_result_msg { +PACK(struct usbmuxd_result_msg { struct usbmuxd_header header; uint32_t result; -} __attribute__((__packed__)); +}); -struct usbmuxd_connect_request { +PACK(struct usbmuxd_connect_request { struct usbmuxd_header header; uint32_t device_id; uint16_t port; // TCP port number uint16_t reserved; // set to zero -} __attribute__((__packed__)); +}); -struct usbmuxd_listen_request { +PACK(struct usbmuxd_listen_request { struct usbmuxd_header header; -} __attribute__((__packed__)); +}); -struct usbmuxd_device_record { +PACK(struct usbmuxd_device_record { uint32_t device_id; uint16_t product_id; char serial_number[256]; uint16_t padding; uint32_t location; -} __attribute__((__packed__)); +}); #ifdef __cplusplus } From 58bd755dbf05d25b10b8a8c4802061fda4acccd2 Mon Sep 17 00:00:00 2001 From: Frederik Carlier Date: Sun, 19 Apr 2015 14:48:28 +0200 Subject: [PATCH 4/6] Visual C++ compatibility: fix C2375 Visual C++ requires the declaration of methods to be exactly the same in the .h and .c files; otherwise it throws C2375. This is fixed by: - Defining USBMUXD_API_MSC in the public headers (via usbmuxd.h) which will add __declspec( dllexport ) to all method definitions in the public headers when compiling with Visual C++ - Ensuring USBMUXD_API_MSC is always set to __declspec( dllexport ) in the private source files when compiling with Visual C++. Using USBMUXD_API in the public headers does not work, becuase its value depends on HAVE_FVISIBILITY, which may be defined in config.h, which is not a public header. --- common/socket.c | 3 +-- include/usbmuxd.h | 38 ++++++++++++++++++++++---------------- src/libusbmuxd.c | 5 ++++- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/common/socket.c b/common/socket.c index eb1f083..4835b64 100644 --- a/common/socket.c +++ b/common/socket.c @@ -27,15 +27,14 @@ #include #include #include -#include #include -#include #include #ifdef WIN32 #include #include static int wsa_init = 0; #else +#include #include #include #include diff --git a/include/usbmuxd.h b/include/usbmuxd.h index d413eab..ca12f47 100644 --- a/include/usbmuxd.h +++ b/include/usbmuxd.h @@ -24,6 +24,12 @@ #define USBMUXD_H #include +#ifdef _MSC_VER +#define USBMUXD_API_MSC __declspec( dllexport ) +#else +#define USBMUXD_API_MSC +#endif + #ifdef __cplusplus extern "C" { #endif @@ -71,14 +77,14 @@ typedef void (*usbmuxd_event_cb_t) (const usbmuxd_event_t *event, void *user_dat * * @return 0 on success or negative on error. */ -int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data); +USBMUXD_API_MSC int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data); /** * Unsubscribe callback. * * @return only 0 for now. */ -int usbmuxd_unsubscribe(); +USBMUXD_API_MSC int usbmuxd_unsubscribe(); /** * Contacts usbmuxd and retrieves a list of connected devices. @@ -91,7 +97,7 @@ int usbmuxd_unsubscribe(); * @return number of attached devices, zero on no devices, or negative * if an error occured. */ -int usbmuxd_get_device_list(usbmuxd_device_info_t **device_list); +USBMUXD_API_MSC int usbmuxd_get_device_list(usbmuxd_device_info_t **device_list); /** * Frees the device list returned by an usbmuxd_get_device_list call @@ -100,7 +106,7 @@ int usbmuxd_get_device_list(usbmuxd_device_info_t **device_list); * * @return 0 on success, -1 on error. */ -int usbmuxd_device_list_free(usbmuxd_device_info_t **device_list); +USBMUXD_API_MSC int usbmuxd_device_list_free(usbmuxd_device_info_t **device_list); /** * Gets device information for the device specified by udid. @@ -113,7 +119,7 @@ int usbmuxd_device_list_free(usbmuxd_device_info_t **device_list); * @return 0 if no matching device is connected, 1 if the device was found, * or a negative value on error. */ -int usbmuxd_get_device_by_udid(const char *udid, usbmuxd_device_info_t *device); +USBMUXD_API_MSC int usbmuxd_get_device_by_udid(const char *udid, usbmuxd_device_info_t *device); /** * Request proxy connect to @@ -125,7 +131,7 @@ int usbmuxd_get_device_by_udid(const char *udid, usbmuxd_device_info_t *device); * * @return file descriptor socket of the connection, or -1 on error */ -int usbmuxd_connect(const int handle, const unsigned short tcp_port); +USBMUXD_API_MSC int usbmuxd_connect(const int handle, const unsigned short tcp_port); /** * Disconnect. For now, this just closes the socket file descriptor. @@ -134,7 +140,7 @@ int usbmuxd_connect(const int handle, const unsigned short tcp_port); * * @return 0 on success, -1 on error. */ -int usbmuxd_disconnect(int sfd); +USBMUXD_API_MSC int usbmuxd_disconnect(int sfd); /** * Send data to the specified socket. @@ -146,7 +152,7 @@ int usbmuxd_disconnect(int sfd); * * @return 0 on success, a negative errno value otherwise. */ -int usbmuxd_send(int sfd, const char *data, uint32_t len, uint32_t *sent_bytes); +USBMUXD_API_MSC int usbmuxd_send(int sfd, const char *data, uint32_t len, uint32_t *sent_bytes); /** * Receive data from the specified socket. @@ -159,7 +165,7 @@ int usbmuxd_send(int sfd, const char *data, uint32_t len, uint32_t *sent_bytes); * * @return 0 on success, a negative errno value otherwise. */ -int usbmuxd_recv_timeout(int sfd, char *data, uint32_t len, uint32_t *recv_bytes, unsigned int timeout); +USBMUXD_API_MSC int usbmuxd_recv_timeout(int sfd, char *data, uint32_t len, uint32_t *recv_bytes, unsigned int timeout); /** * Receive data from the specified socket with a default timeout. @@ -171,7 +177,7 @@ int usbmuxd_recv_timeout(int sfd, char *data, uint32_t len, uint32_t *recv_bytes * * @return 0 on success, a negative errno value otherwise. */ -int usbmuxd_recv(int sfd, char *data, uint32_t len, uint32_t *recv_bytes); +USBMUXD_API_MSC int usbmuxd_recv(int sfd, char *data, uint32_t len, uint32_t *recv_bytes); /** * Reads the SystemBUID @@ -181,7 +187,7 @@ int usbmuxd_recv(int sfd, char *data, uint32_t len, uint32_t *recv_bytes); * * @return 0 on success, a negative errno value otherwise. */ -int usbmuxd_read_buid(char** buid); +USBMUXD_API_MSC int usbmuxd_read_buid(char** buid); /** * Read a pairing record @@ -194,7 +200,7 @@ int usbmuxd_read_buid(char** buid); * * @return 0 on success, a negative error value otherwise. */ -int usbmuxd_read_pair_record(const char* record_id, char **record_data, uint32_t *record_size); +USBMUXD_API_MSC int usbmuxd_read_pair_record(const char* record_id, char **record_data, uint32_t *record_size); /** * Save a pairing record @@ -205,7 +211,7 @@ int usbmuxd_read_pair_record(const char* record_id, char **record_data, uint32_t * * @return 0 on success, a negative error value otherwise. */ -int usbmuxd_save_pair_record(const char* record_id, const char *record_data, uint32_t record_size); +USBMUXD_API_MSC int usbmuxd_save_pair_record(const char* record_id, const char *record_data, uint32_t record_size); /** * Delete a pairing record @@ -214,7 +220,7 @@ int usbmuxd_save_pair_record(const char* record_id, const char *record_data, uin * * @return 0 on success, a negative errno value otherwise. */ -int usbmuxd_delete_pair_record(const char* record_id); +USBMUXD_API_MSC int usbmuxd_delete_pair_record(const char* record_id); /** * Enable or disable the use of inotify extension. Enabled by default. @@ -222,9 +228,9 @@ int usbmuxd_delete_pair_record(const char* record_id); * This only has an effect on linux systems if inotify support has been built * in. Otherwise and on all other platforms this function has no effect. */ -void libusbmuxd_set_use_inotify(int set); +USBMUXD_API_MSC void libusbmuxd_set_use_inotify(int set); -void libusbmuxd_set_debug_level(int level); +USBMUXD_API_MSC void libusbmuxd_set_debug_level(int level); #ifdef __cplusplus } diff --git a/src/libusbmuxd.c b/src/libusbmuxd.c index 6a53adb..eb0ea5a 100644 --- a/src/libusbmuxd.c +++ b/src/libusbmuxd.c @@ -34,6 +34,9 @@ #include #include +#ifdef _MSC_VER + #define USBMUXD_API __declspec( dllexport ) +#else #ifdef WIN32 #define USBMUXD_API __declspec( dllexport ) #else @@ -43,6 +46,7 @@ #define USBMUXD_API #endif #endif +#endif #ifdef WIN32 #include @@ -68,7 +72,6 @@ #define USBMUXD_SOCKET_NAME "usbmuxd" #endif /* HAVE_INOTIFY */ -#include #include #include From a1fb9212a186c4d3db7c6c607a91e47a8cf55908 Mon Sep 17 00:00:00 2001 From: Frederik Carlier Date: Sun, 19 Apr 2015 15:03:59 +0200 Subject: [PATCH 5/6] Visual C++ compatibility fixes Include unistd.h in libusbmuxd.c Define strcasecmp for Visual C++ compat --- src/libusbmuxd.c | 1 + src/msc_config.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/libusbmuxd.c b/src/libusbmuxd.c index eb0ea5a..1388374 100644 --- a/src/libusbmuxd.c +++ b/src/libusbmuxd.c @@ -59,6 +59,7 @@ #define EBADMSG 104 #endif #else +#include #include #include #include diff --git a/src/msc_config.h b/src/msc_config.h index 7b16e11..9528843 100644 --- a/src/msc_config.h +++ b/src/msc_config.h @@ -26,4 +26,6 @@ #define _CRT_SECURE_NO_WARNINGS #define _WINSOCK_DEPRECATED_NO_WARNINGS #define __func__ __FUNCTION__ +#define strncasecmp _strnicmp +#define strcasecmp _stricmp #endif From b922dad67f53d11e42d85ad126abffad85eb0a2f Mon Sep 17 00:00:00 2001 From: Frederik Carlier Date: Sun, 19 Apr 2015 15:07:36 +0200 Subject: [PATCH 6/6] Visual C++ Compatibility Include unistd.h on non-WIN32 builds --- common/socket.c | 1 + 1 file changed, 1 insertion(+) diff --git a/common/socket.c b/common/socket.c index 4835b64..0ae6d9f 100644 --- a/common/socket.c +++ b/common/socket.c @@ -34,6 +34,7 @@ #include static int wsa_init = 0; #else +#include #include #include #include