/* * USB FM Radio Control utility * Copyright (c) 2002-2004 Nicola S. Vitale * All rights reserved. */ /* * NAME * open_radio * * DESCRIPTION * The function opens the device, specified as argument. * * ARGUMENTS * A string that specifies the path of the radio device. * * RETURN VALUES * A file descriptor (a non-negative integer) to use * in all next calls to other library functions. * -1 on failure. * * $Id: open_radio.c,v 1.3 2004/01/03 09:47:45 nivit Exp $ */ #if 0 #include /* PATH_MAX => FILENAME_MAX */ #endif #include #include #include #include #include "libufm.h" int open_radio(const char *radio_device) { int fd, len; char devpath[FILENAME_MAX + 1]; fd = -1; len = 0; if (radio_device != NULL) len = strlen(radio_device); else return -1; if (len > 0 && len <= FILENAME_MAX) { if (*radio_device != '/') sprintf(devpath, "%s%s", _PATH_DEV, radio_device); else sprintf(devpath, "%s", radio_device); fd = open(devpath, O_RDWR); if (fd < 0) DPRINT("impossible to open device"); } return fd; }