Added a bit of error checking and such
This commit is contained in:
@@ -8,7 +8,8 @@
|
||||
|
||||
const char* program_name;
|
||||
|
||||
static inline void die(int code, const char* message){
|
||||
static inline void die(int code, const char* message, int fd){
|
||||
if(fd != -1) close(fd);
|
||||
fprintf(stderr, "%s: %s\n", program_name, message);
|
||||
exit(code);
|
||||
}
|
||||
@@ -19,17 +20,18 @@ int main(int argc, char** argv){
|
||||
struct cdrom_tochdr toc_hdr;
|
||||
struct cdrom_tocentry toc_entry;
|
||||
|
||||
if(!argv) die(127, "How did you do that? No argv?", -1);
|
||||
program_name = argv[0];
|
||||
|
||||
if((fd = open("/dev/cdrom", O_RDONLY)) == -1){
|
||||
if(errno == ENOMEDIUM)
|
||||
die(127, "No CD in drive");
|
||||
die(127, "No CD in drive", fd);
|
||||
else
|
||||
die(127, "Cannot open /dev/cdrom");
|
||||
die(127, "Cannot open /dev/cdrom", fd);
|
||||
}
|
||||
|
||||
if(ioctl(fd, CDROMREADTOCHDR, &toc_hdr) == -1)
|
||||
die(127, "Cannot get header");
|
||||
die(127, "Cannot get header", fd);
|
||||
|
||||
printf("First track: %d\nLast track: %d\n\n trackno) length\n",
|
||||
toc_hdr.cdth_trk0, toc_hdr.cdth_trk1);
|
||||
@@ -39,7 +41,7 @@ int main(int argc, char** argv){
|
||||
toc_entry.cdte_format = CDROM_MSF;
|
||||
|
||||
if(ioctl(fd, CDROMREADTOCENTRY, &toc_entry) == -1)
|
||||
die(127, "Cannot get table of contents");
|
||||
die(127, "Cannot get table of contents", fd);
|
||||
|
||||
printf(" %2d)\t%02d:%02d.%02d\n", i, toc_entry.cdte_addr.msf.minute,
|
||||
toc_entry.cdte_addr.msf.second,
|
||||
|
Reference in New Issue
Block a user