Updated for better error messages
This commit is contained in:
@@ -6,26 +6,30 @@
|
||||
#include <fcntl.h>
|
||||
#include <linux/cdrom.h>
|
||||
|
||||
const char* program_name;
|
||||
|
||||
static inline void die(int code, const char* message){
|
||||
fprintf(stderr, "%s\n", message);
|
||||
fprintf(stderr, "%s: %s\n", program_name, message);
|
||||
exit(code);
|
||||
}
|
||||
|
||||
int main(){
|
||||
int main(int argc, char** argv){
|
||||
register int fd;
|
||||
register unsigned char i;
|
||||
struct cdrom_tochdr toc_hdr;
|
||||
struct cdrom_tocentry toc_entry;
|
||||
|
||||
program_name = argv[0];
|
||||
|
||||
if((fd = open("/dev/cdrom", O_RDONLY)) == -1){
|
||||
if(errno == ENOMEDIUM)
|
||||
die(127, "cd_check_read_toc: No CD in drive");
|
||||
die(127, "No CD in drive");
|
||||
else
|
||||
die(127, "cd_check_read_toc: Cannot open /dev/cdrom");
|
||||
die(127, "Cannot open /dev/cdrom");
|
||||
}
|
||||
|
||||
if(ioctl(fd, CDROMREADTOCHDR, &toc_hdr) == -1)
|
||||
die(127, "cd_check_read_toc: Cannot get header");
|
||||
die(127, "Cannot get header");
|
||||
|
||||
printf("First track: %d\nLast track: %d\n\n trackno) length\n",
|
||||
toc_hdr.cdth_trk0, toc_hdr.cdth_trk1);
|
||||
@@ -35,7 +39,7 @@ int main(){
|
||||
toc_entry.cdte_format = CDROM_MSF;
|
||||
|
||||
if(ioctl(fd, CDROMREADTOCENTRY, &toc_entry) == -1)
|
||||
die(127, "cd_check_read_toc: Cannot get table of contents");
|
||||
die(127, "Cannot get table of contents");
|
||||
|
||||
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