FU Logo
  • Startseite
  • Kontakt
  • Impressum
  • Home
  • Listenauswahl
  • Anleitungen

Re: [linux-minidisc] compiling libnetmd and netmdcli on windows

<-- thread -->
<-- date -->
  • From: Michael Karcher <Michael.Karcher@fu-berlin.de>
  • To: Thomas Arp <manner.moe@gmx.de>
  • Date: Tue, 13 Sep 2011 23:53:50 +0200
  • Cc: linux-minidisc@lists.fu-berlin.de
  • Subject: Re: [linux-minidisc] compiling libnetmd and netmdcli on windows

Am Dienstag, den 13.09.2011, 09:03 +0200 schrieb Thomas Arp:
> 1. libnetmd/common.c :  sleep() is not defined/implemented
> I fixed this using windows Sleep() function by adding following lines
> to common.c
> 
> #ifdef WIN32 /* use windows internal Sleep() function */ 
> #include <windows.h>
> #define sleep(x) Sleep(x)
> #endif
Good start, but not quite.

#define sleep(x) Sleep(x*1000)

even better:
#ifdef WIN32
#include <windows.h>
#define msleep(x) Sleep(x)
#else
#include <unistd.h>
#define msleep(x) usleep(1000*x)
#endif

and replace the "sleep(1)" by "msleep(200)".

A polling frequency of 1Hz is quite low. I guess sleep was originally
used, as there is common belief (even I fell into that trap) that sleep
would be portable ANSI C.

> 2. libnetmd/utils.h and utils.c :  "int min(int a,int b)" is already
> defined in windows.h
> I fixed this by defining NOMINMAX to not use the windows function.
> I just added following line to libnetmd.pro and netmdcli.pro
> 
> win32:DEFINES += NOMINMAX
Great, that change is fine. The other alternative would be to rename out
min funciton.

> 3. libnetmd/utils.h :  missind definition of ETIMEDOUT in errno.h
> I fixed this by defining it.
> #ifdef WIN32 /* add missing definitions for errno on windows */ 
> #define ETIMEDOUT 70 // Operation timed out
> #endif
NACK. We are using a libusb 1.0 call here, and the libusb documentation
documents "LIBUSB_ERROR_TIMEOUT" as the right value to compare against.
Replace ETIMEDOUT by that, don't try to define ETIMEDOUT.

> 4. libnetmd/secure.c and netmdcli/netmdcli.c :  ramdo) is not defined
> and implemented
> I fixed this as a "bloody hack" in utils.h using
> #ifdef WIN32 
> #include <stdlib.h>
> #include <time.h>
> static int random(){srand(time(NULL));return rand();};
> #endif

Reseding every time is a real bad idea(tm). It is quite likely that
time(NULL) returns the same value on two successive calls (it changes
once per second). As we don't care about sniffing, just using rand() in
the library should be fine, if the caller didn't srand so be it.

In netmdcli.c, add "srand(time(NULL));" to the beginning of main. Then
replace random by rand.

Regards,
  Michael Karcher




<-- thread -->
<-- date -->
  • Follow-Ups:
    • Re: [linux-minidisc] compiling libnetmd and netmdcli on windows
      • From: Thomas Arp <manner.moe@gmx.de>
  • References:
    • [linux-minidisc] compiling libnetmd and netmdcli on windows
      • From: Thomas Arp <manner.moe@gmx.de>
  • linux-minidisc - September 2011 - Archives indexes sorted by:
    [ thread ] [ subject ] [ author ] [ date ]
  • Complete archive of the linux-minidisc mailing list
  • More info on this list...

Hilfe

  • FAQ
  • Dienstbeschreibung
  • ZEDAT Beratung
  • postmaster@lists.fu-berlin.de

Service-Navigation

  • Startseite
  • Listenauswahl

Einrichtung Mailingliste

  • ZEDAT-Portal
  • Mailinglisten Portal