Fix some of the tests for MinGW and fix the use of Sleep/usleep for MinGW & MSVC platforms
* Sleep takes ms, not s * Use sleep/Sleep rather than usleep in the cdchange sample, as usleep is not available on recent MinGW platforms From pbatard branch.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011
|
||||
Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
|
||||
Rocky Bernstein <rocky@gnu.org>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
@@ -26,10 +26,12 @@
|
||||
#include <cdio/cdio.h>
|
||||
|
||||
/* Test media changed */
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_STDIO_H
|
||||
# include <stdio.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIMITS_H
|
||||
#include <limits.h>
|
||||
# include <limits.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDLIB_H
|
||||
@@ -51,22 +53,22 @@
|
||||
#ifdef HAVE_WINDOWS_H
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_USLEEP
|
||||
#error usleep() unimplemented
|
||||
#if !defined(HAVE_SLEEP) && defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#define sleep(s) Sleep(1000*s)
|
||||
#endif
|
||||
|
||||
int
|
||||
main(int argc, const char *argv[])
|
||||
{
|
||||
CdIo_t *p_cdio;
|
||||
unsigned long i_sleep_ms = (30 * 1000000);
|
||||
unsigned int i_sleep = 30;
|
||||
if (argc > 1) {
|
||||
p_cdio = cdio_open (argv[1], DRIVER_DEVICE);
|
||||
if (argc > 2) {
|
||||
errno = 0;
|
||||
i_sleep_ms = strtol(argv[2], (char **)NULL, 10) * 1000000;
|
||||
if ( (LONG_MIN == i_sleep_ms || LONG_MAX == i_sleep_ms) && errno != 0 ) {
|
||||
i_sleep = strtol(argv[2], (char **)NULL, 10);
|
||||
if ( (LONG_MIN == i_sleep || LONG_MAX == i_sleep) && errno != 0 ) {
|
||||
printf("Invalid sleep parameter %s\n", argv[2]);
|
||||
printf("Error reported back from strtol: %s\n", strerror(errno));
|
||||
return 2;
|
||||
@@ -86,13 +88,9 @@ main(int argc, const char *argv[])
|
||||
else
|
||||
printf("Initial media status: not changed\n");
|
||||
|
||||
printf("Giving you %g seconds to change CD if you want to do so.\n",
|
||||
i_sleep_ms / 1000000.0);
|
||||
{
|
||||
int i_ret = usleep(i_sleep_ms);
|
||||
if (0 != i_ret)
|
||||
fprintf(stderr, "Something went wrong with usleep\n");
|
||||
}
|
||||
printf("Giving you %d seconds to change CD if you want to do so.\n",
|
||||
i_sleep);
|
||||
sleep(i_sleep);
|
||||
if (cdio_get_media_changed(p_cdio))
|
||||
printf("Media status: changed\n");
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user