Mingw32 fixes
diff --git a/ChangeLog b/ChangeLog
index 645dff2..2a94081 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-01-10 Linus Walleij <triad@df.lth.se>
+
+ * src/libmtp.h.in: mingw32 fixes from James Ravenscroft.
+ * src/libmtp.c: dito.
+ * src/Makefile.am: dito.
+ * examples/albumart.c: dito.
+
2009-01-06 Linus Walleij <triad@df.lth.se>
* src/Makefile.am: patch from Rafael Laboissiere removing a
diff --git a/examples/albumart.c b/examples/albumart.c
index 0b36919..c1fc7ad 100644
--- a/examples/albumart.c
+++ b/examples/albumart.c
@@ -97,7 +97,7 @@
imagedata = malloc(filesize * sizeof(uint8_t));
#ifdef __WIN32__
- if ( (fd = open(path, O_RDONLY|O_BINARY) == -1 ) {
+ if ( (fd = open(path, O_RDONLY|O_BINARY) == -1) ) {
#else
if ( (fd = open(path, O_RDONLY)) == -1) {
#endif
diff --git a/examples/thumb.c b/examples/thumb.c
index 59401d3..ddb5549 100644
--- a/examples/thumb.c
+++ b/examples/thumb.c
@@ -77,7 +77,7 @@
imagedata = malloc(filesize * sizeof(uint16_t));
#ifdef __WIN32__
- if ( (fd = open(path, O_RDONLY|O_BINARY) == -1 ) {
+ if ( (fd = open(path, O_RDONLY|O_BINARY) == -1) ) {
#else
if ( (fd = open(path, O_RDONLY)) == -1) {
#endif
diff --git a/src/Makefile.am b/src/Makefile.am
index 885129b..b9fbc68 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -35,7 +35,7 @@
if COMPILE_MINGW32
noinst_DATA=libmtp.lib
-W32LF=-export-dynamic
+W32LF=-export-dynamic -liconv -ws2_32
libmtp.def: libmtp.sym
echo "LIBRARY \"@PACKAGE@\"" > libmtp.def
echo "DESCRIPTION \"Media Transfer Protocol (MTP) library\"" >> libmtp.def
@@ -50,7 +50,7 @@
$(INSTALL) libmtp.lib $(DESTDIR)$(libdir)
endif
-libmtp_la_LDFLAGS=@LDFLAGS@ -no-undefined -export-symbols libmtp.sym -version-info $(W32LF) $(SOVERSION)
+libmtp_la_LDFLAGS=@LDFLAGS@ -no-undefined -export-symbols libmtp.sym -version-info $(SOVERSION) $(W32LF)
libmtp_la_DEPENDENCIES=libmtp.sym
DISTCLEANFILES = _stdint.h
diff --git a/src/libmtp.c b/src/libmtp.c
index d2245e2..077330a 100644
--- a/src/libmtp.c
+++ b/src/libmtp.c
@@ -54,6 +54,10 @@
#define USE_WINDOWS_IO_H
#include <io.h>
#endif
+#ifdef __WIN32__
+/* Windows does not have rindex */
+#define rindex strrchr
+#endif
/* To enable PTP level debug prints (all ptp_debug(...)), switch on this */
//#define ENABLE_PTP_DEBUG
@@ -3840,7 +3844,7 @@
#ifdef USE_WINDOWS_IO_H
if ( (fd = _open(path, O_RDWR|O_CREAT|O_TRUNC|O_BINARY,_S_IREAD)) == -1 ) {
#else
- if ( (fd = open(path, O_RDWR|O_CREAT|O_TRUNC|O_BINARY,S_IRWXU|S_IRGRP)) == -1 ) {
+ if ( (fd = open(path, O_RDWR|O_CREAT|O_TRUNC|O_BINARY,S_IRWXU)) == -1 ) {
#endif
#else
#ifdef __USE_LARGEFILE64
@@ -4044,9 +4048,9 @@
// Open file
#ifdef __WIN32__
#ifdef USE_WINDOWS_IO_H
- if ( (fd = _open(path, O_RDONLY|O_BINARY) == -1 ) {
+ if ( (fd = _open(path, O_RDONLY|O_BINARY) == -1) ) {
#else
- if ( (fd = open(path, O_RDONLY|O_BINARY) == -1 ) {
+ if ( (fd = open(path, O_RDONLY|O_BINARY) == -1) ) {
#endif
#else
#ifdef __USE_LARGEFILE64
@@ -4217,9 +4221,9 @@
// Open file
#ifdef __WIN32__
#ifdef USE_WINDOWS_IO_H
- if ( (fd = _open(path, O_RDONLY|O_BINARY) == -1 ) {
+ if ( (fd = _open(path, O_RDONLY|O_BINARY) == -1) ) {
#else
- if ( (fd = open(path, O_RDONLY|O_BINARY) == -1 ) {
+ if ( (fd = open(path, O_RDONLY|O_BINARY) == -1) ) {
#endif
#else
#ifdef __USE_LARGEFILE64
diff --git a/src/libmtp.h.in b/src/libmtp.h.in
index 55682a1..869e367 100644
--- a/src/libmtp.h.in
+++ b/src/libmtp.h.in
@@ -38,16 +38,10 @@
#define __WIN32__
#define snprintf _snprintf
#define ssize_t SSIZE_T
-#endif
-
-#include <stdio.h>
-#include <usb.h>
-#include <stdint.h>
-
-#ifdef __WIN32__
/*
- * Windows specific code, types that do not exist in Windows
- * sys/types.h
+ * Types that do not exist in Windows
+ * sys/types.h, but they exist in mingw32
+ * sys/types.h.
*/
typedef char int8_t;
typedef unsigned char uint8_t;
@@ -58,6 +52,10 @@
typedef unsigned __int64 uint64_t;
#endif
+#include <stdio.h>
+#include <usb.h>
+#include <stdint.h>
+
/**
* @defgroup types libmtp global type definitions
* @{