diff options
author | ddennedy <ddennedy@53a565d1-3bb7-0310-b661-cf11e63c67ab> | 2007-02-17 02:24:16 +0000 |
---|---|---|
committer | ddennedy <ddennedy@53a565d1-3bb7-0310-b661-cf11e63c67ab> | 2007-02-17 02:24:16 +0000 |
commit | 4a129dd960eab819d7f87fc83c0afc2b938fb1cf (patch) | |
tree | 61162545fbe0f0b805bb59a47e1b5580110512de | |
parent | fa981a8b96ec3d09385a0b14b4342e574b7bbe29 (diff) | |
download | libraw1394-4a129dd960eab819d7f87fc83c0afc2b938fb1cf.tar.gz |
add support for RAW1394DEV environment variable to override default /dev/raw1394, but also attempt to failover to default.
git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@170 53a565d1-3bb7-0310-b661-cf11e63c67ab
-rw-r--r-- | src/main.c | 25 |
1 files changed, 20 insertions, 5 deletions
@@ -115,6 +115,7 @@ static unsigned int init_rawdevice(struct raw1394_handle *h) struct raw1394_handle *raw1394_new_handle(void) { struct raw1394_handle *handle; + const char *defaultDevice = "/dev/raw1394"; handle = malloc(sizeof(struct raw1394_handle)); if (!handle) { @@ -122,17 +123,31 @@ struct raw1394_handle *raw1394_new_handle(void) return NULL; } - handle->fd = open("/dev/raw1394", O_RDWR); + handle->fd = open(getenv("RAW1394DEV") ? getenv("RAW1394DEV"): defaultDevice, O_RDWR); if (handle->fd < 0) { - free(handle); - return NULL; + /* failover to default in attempt to idiot proof */ + handle->fd = open(defaultDevice, O_RDWR); + if (handle->fd < 0) { + free(handle); + return NULL; + } } handle->generation = init_rawdevice(handle); if (handle->generation == -1) { + /* failover to default in attempt to idiot proof */ close(handle->fd); - free(handle); - return NULL; + handle->fd = open(defaultDevice, O_RDWR); + if (handle->fd < 0) { + free(handle); + return NULL; + } + handle->generation = init_rawdevice(handle); + if (handle->generation == -1) { + close(handle->fd); + free(handle); + return NULL; + } } handle->err = 0; |