Linux C

#include
#include
#include
#include
#include
#include
/*
// close
*/
int cdr_close(char *dev) {
int fd;
if((fd = open(dev, O_RDONLY|O_NONBLOCK)) == -1)
return -1;
else if(ioctl(fd, CDROMCLOSETRAY) == -1)
return -1;
else
close(fd);
return 0;
}
/*
// eject
*/
int cdr_eject(char *dev) {
int fd;
if((fd = open(dev, O_RDONLY|O_NONBLOCK)) == -1)
return -1;
else if(ioctl(fd, CDROMEJECT) == -1)
return -1;
else
close(fd);
return 0;
}
/*
// lock
// - if lock == 1, lock
// - if lock == 0, unlock
*/
int cdlock(char *dev, int lock) {
int fd;
if((fd = open(dev, O_RDONLY|O_NONBLOCK)) == -1)
return -1;
else if(ioctl(fd, CDROM_LOCKDOOR, lock) == -1)
return -1;
else
close(fd);
return 0;
}