Initial commit
This commit is contained in:
40
src/cd_check_capabilities.c
Normal file
40
src/cd_check_capabilities.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/cdrom.h>
|
||||
|
||||
static inline void die(int code, const char* message){
|
||||
fprintf(stderr, "%s\n", message);
|
||||
exit(code);
|
||||
}
|
||||
|
||||
int main(){
|
||||
register int fd, caps;
|
||||
|
||||
if((fd = open("/dev/cdrom", O_RDONLY | O_NONBLOCK)) == -1)
|
||||
die(127, "cd_check_capabilities: Cannot open /dev/cdrom");
|
||||
|
||||
if((caps = ioctl(fd, CDROM_GET_CAPABILITY)) == -1)
|
||||
die(127, "cd_check_capabilities: ioctl failed");
|
||||
|
||||
printf("This drive is capable of playing CD-R: %s\n\t\t\t"
|
||||
"CD-RW: %s\n\t\t\tDVD: %s\n\t\t\tDVD-R: %s\n",
|
||||
(caps & CDC_CD_R) ? "yes" : "no",
|
||||
(caps & CDC_CD_RW) ? "yes" : "no",
|
||||
(caps & CDC_DVD) ? "yes" : "no",
|
||||
(caps & CDC_DVD_R) ? "yes" : "no");
|
||||
|
||||
printf("It can open the tray: %s\n\t\tclose the tray: %s\n\t\t"
|
||||
"lock the tray: %s\n\t\tplay audio: %s\n\t\t"
|
||||
"select discs:%s\n",
|
||||
(caps & CDC_OPEN_TRAY) ? "yes" : "no",
|
||||
(caps & CDC_CLOSE_TRAY) ? "yes" : "no",
|
||||
(caps & CDC_LOCK) ? "yes" : "no",
|
||||
(caps & CDC_PLAY_AUDIO) ? "yes" : "no",
|
||||
(caps & CDC_SELECT_DISK) ? "yes" : "no");
|
||||
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user