Ticket #9: 800_win32_glib.patch

File 800_win32_glib.patch, 4.7 KB (added by hsattler, 18 months ago)

fix building of glib binding on win32

  • glib/obex-lowlevel.c

    old new  
    3030#include <malloc.h> 
    3131#include <string.h> 
    3232#include <time.h> 
     33 
     34#ifdef _WIN32 
     35#include <winsock2.h> 
     36#warning "Incomplete implementation: no gmtime_r() on win32!" 
     37#define gmtime_r(time_p,result) NULL 
     38#define EISCONN WSAEISCONN 
     39#define ENOTCONN WSAENOTCONN 
     40#else 
    3341#include <arpa/inet.h> 
     42#endif 
    3443 
    3544#include <glib.h> 
    3645 
  • glib/Makefile.am

    old new  
    88 
    99libopenobex_glib_la_SOURCES = obex-lowlevel.h obex-lowlevel.c obex-client.c obex-debug.h obex-error.c obex-error.h 
    1010 
    11 libopenobex_glib_la_LDFLAGS = -version-info 1:0:0 
     11libopenobex_glib_la_LDFLAGS = -no-undefined -version-info 1:0:0 
    1212 
    13 libopenobex_glib_la_LIBADD = @GLIB_LIBS@ $(top_builddir)/lib/libopenobex.la 
     13libopenobex_glib_la_LIBADD = @GLIB_LIBS@ $(top_builddir)/lib/libopenobex.la @EXTRA_LIBS@ 
    1414 
    1515BUILT_SOURCES = obex-marshal.h obex-marshal.c 
    1616 
  • glib/obex-error.c

    old new  
    2525#include <config.h> 
    2626#endif 
    2727 
     28#ifdef _WIN32 
     29#include <winsock2.h> 
     30#define EISCONN WSAEISCONN 
     31#define ENOTCONN WSAENOTCONN 
     32#endif 
     33 
    2834#include <errno.h> 
    2935 
    3036#include "obex-debug.h" 
  • glib/test-lowlevel.c

    old new  
    3030#include <fcntl.h> 
    3131#include <unistd.h> 
    3232#include <stdlib.h> 
     33 
     34#ifdef _WIN32 
     35#include <io.h> 
     36#define SOME_TTY "COM4" 
     37#else 
    3338#include <termios.h> 
     39#define SOME_TTY "/dev/rfcomm42" 
     40#endif 
    3441 
    3542#include "obex-lowlevel.h" 
    3643 
    3744static int open_device(const char *device) 
    3845{ 
    39         struct termios ti; 
    4046        int fd; 
     47#ifdef _WIN32 
     48        HANDLE h; 
     49        DCB ti; 
     50 
     51        h = CreateFile(device, 
     52                        GENERIC_READ|GENERIC_WRITE, 
     53                        0,NULL,OPEN_EXISTING,0,NULL); 
     54        if (h == INVALID_HANDLE_VALUE) 
     55                return -1; 
     56 
     57        //TODO: tcflush-equivalent function? 
     58        ti.StopBits = ONESTOPBIT; 
     59        ti.Parity = NOPARITY; 
     60        ti.ByteSize = 8; 
     61        ti.fNull = FALSE; 
     62        SetCommState(h,&ti); 
     63        fd = _open_osfhandle((intptr_t)h,0); 
     64#else 
     65        struct termios ti; 
    4166 
    4267        fd = open(device, O_RDWR | O_NOCTTY); 
    4368        if (fd < 0) 
     
    4772 
    4873        cfmakeraw(&ti); 
    4974        tcsetattr(fd, TCSANOW, &ti); 
    50  
     75#endif 
    5176        return fd; 
    5277} 
    5378 
     
    5681        obex_t *handle; 
    5782        int fd; 
    5883 
    59         fd = open_device("/dev/rfcomm42"); 
     84        fd = open_device(SOME_TTY); 
    6085        if (fd < 0) { 
    6186                perror("Can't open device"); 
    6287                exit(EXIT_FAILURE); 
  • glib/test-client.c

    old new  
    3232#include <stdlib.h> 
    3333#include <string.h> 
    3434#include <signal.h> 
    35 #include <termios.h> 
    3635#include <sys/types.h> 
    3736#include <sys/stat.h> 
    3837 
     38#ifdef _WIN32 
     39#include <windows.h> 
     40#include <io.h> 
     41#else 
     42#include <termios.h> 
     43#endif 
     44 
    3945#include "obex-client.h" 
    4046 
    4147#define FTP_UUID (guchar *) \ 
     
    5056 
    5157static int open_device(const char *device) 
    5258{ 
    53         struct termios ti; 
    5459        int fd; 
     60#ifdef _WIN32 
     61        HANDLE h; 
     62        DCB ti; 
     63 
     64        h = CreateFile(device, 
     65                        GENERIC_READ|GENERIC_WRITE, 
     66                        0,NULL,OPEN_EXISTING,0,NULL); 
     67        if (h == INVALID_HANDLE_VALUE) 
     68                return -1; 
     69 
     70        //TODO: tcflush-equivalent function? 
     71        ti.StopBits = ONESTOPBIT; 
     72        ti.Parity = NOPARITY; 
     73        ti.ByteSize = 8; 
     74        ti.fNull = FALSE; 
     75        SetCommState(h,&ti); 
     76        fd = _open_osfhandle((intptr_t)h,0); 
     77#else 
     78        struct termios ti; 
    5579 
    5680        fd = open(device, O_RDWR | O_NOCTTY); 
    5781        if (fd < 0) 
     
    6185 
    6286        cfmakeraw(&ti); 
    6387        tcsetattr(fd, TCSANOW, &ti); 
    64  
     88#endif 
    6589        return fd; 
    6690} 
    6791 
     
    154178int main(int argc, char *argv[]) 
    155179{ 
    156180        ObexClient *client; 
    157         struct sigaction sa; 
    158181        int fd, io = -1; 
     182#ifndef _WIN32 
     183        struct sigaction sa; 
     184#endif 
    159185 
    160186        g_type_init(); 
    161187 
     
    193219                obex_client_get_object(client, NULL, "telecom/devinfo.txt", NULL); 
    194220 
    195221 
     222#ifndef _WIN32 
    196223        memset(&sa, 0, sizeof(sa)); 
    197224        sa.sa_handler = sig_term; 
    198225        sigaction(SIGTERM, &sa, NULL); 
    199226        sigaction(SIGINT,  &sa, NULL); 
     227#endif 
    200228 
    201229        g_main_loop_run(mainloop); 
    202230