aboutsummaryrefslogtreecommitdiff
path: root/libmpio/src
diff options
context:
space:
mode:
Diffstat (limited to 'libmpio/src')
-rw-r--r--libmpio/src/io.c29
-rw-r--r--libmpio/src/mpio.c11
2 files changed, 27 insertions, 13 deletions
diff --git a/libmpio/src/io.c b/libmpio/src/io.c
index 6c1f1eb..61ddd4f 100644
--- a/libmpio/src/io.c
+++ b/libmpio/src/io.c
@@ -1,5 +1,5 @@
/*
- * $Id: io.c,v 1.11 2004/04/23 18:17:56 germeier Exp $
+ * $Id: io.c,v 1.12 2004/04/24 16:09:58 germeier Exp $
*
* libmpio - a library for accessing Digit@lways MPIO players
* Copyright (C) 2002-2004 Markus Germeier
@@ -511,6 +511,9 @@ mpio_device_open(mpio_t *m){
int ret, i;
m->use_libusb=1;
+ if (m->fd)
+ return MPIO_OK;
+
#ifdef USE_KMODULE
debugn(2, "trying kernel module\n");
m->fd = open(MPIO_DEVICE, O_RDWR);
@@ -549,12 +552,12 @@ mpio_device_open(mpio_t *m){
if (ret < 0)
{
debugn(2, "Error claiming device: %d \"%s\"\n", ret, usb_strerror());
+ usb_close(m->usb_handle);
return MPIO_ERR_PERMISSION_DENIED;
} else {
debugn(2, "claimed interface 0\n");
}
-
interface = dev->config->interface->altsetting;
for (i = 0 ; i < interface->bNumEndpoints; i++) {
@@ -572,8 +575,10 @@ mpio_device_open(mpio_t *m){
}
}
+ m->fd=1;
if (!(m->usb_in_ep && m->usb_out_ep)) {
debugn(2, "Did not find USB bulk endpoints.\n");
+ mpio_device_close(m);
return MPIO_ERR_PERMISSION_DENIED;
}
@@ -583,22 +588,28 @@ mpio_device_open(mpio_t *m){
}
}
}
-
+
+ if (m->usb_handle)
+ usb_close(m->usb_handle);
return MPIO_ERR_PERMISSION_DENIED;
}
int
mpio_device_close(mpio_t *m) {
if(m->use_libusb) {
- debugn(2, "closing libusb\n");
- usb_close(m->usb_handle);
- m->fd=0;
+ if (m->fd) {
+ debugn(2, "closing libusb\n");
+ usb_close(m->usb_handle);
+ m->fd=0;
+ }
}
#ifdef USE_KMODULE
else {
- debugn(2, "closing kernel module\n");
- close(m->fd);
- m->fd=0;
+ if (m->fd) {
+ debugn(2, "closing kernel module\n");
+ close(m->fd);
+ m->fd=0;
+ }
}
#endif
diff --git a/libmpio/src/mpio.c b/libmpio/src/mpio.c
index d5667d1..229644e 100644
--- a/libmpio/src/mpio.c
+++ b/libmpio/src/mpio.c
@@ -1,5 +1,5 @@
/*
- * $Id: mpio.c,v 1.14 2004/04/23 19:21:07 germeier Exp $
+ * $Id: mpio.c,v 1.15 2004/04/24 16:09:58 germeier Exp $
*
* libmpio - a library for accessing Digit@lways MPIO players
* Copyright (C) 2002-2004 Markus Germeier
@@ -95,9 +95,9 @@ static mpio_error_t mpio_errors[] = {
{ MPIO_ERR_DIR_NOT_EMPTY,
"The selected directory is not empty." },
{ MPIO_ERR_DEVICE_NOT_READY,
- "Could not open " MPIO_DEVICE "\n"
- "Verify that the mpio module is loaded and "
- "your MPIO is\nconnected and powered up.\n" },
+ "Could not access the player\n"
+ "Verify that the the player is\n"
+ "connected and powered up.\n" },
{ MPIO_ERR_OUT_OF_MEMORY,
"Out of Memory." },
{ MPIO_ERR_INTERNAL,
@@ -314,11 +314,14 @@ mpio_init(mpio_callback_init_t progress_callback)
new_mpio = malloc(sizeof(mpio_t));
if (!new_mpio) {
debug ("Error allocating memory for mpio_t");
+ _mpio_errno = MPIO_ERR_OUT_OF_MEMORY;
return NULL;
}
memset(new_mpio, 0, sizeof(mpio_t));
+ new_mpio->fd=0;
if (mpio_device_open(new_mpio) != MPIO_OK) {
+ free(new_mpio);
_mpio_errno = MPIO_ERR_DEVICE_NOT_READY;
return NULL;
}