Initial commit

This commit is contained in:
Veit Heller
2014-09-15 17:57:04 +02:00
parent 36c0d500a2
commit 3dc5b6f5e0
5 changed files with 195 additions and 0 deletions

45
src/cd_check_read_toc.c Normal file
View File

@@ -0,0 +1,45 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.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, i;
struct cdrom_tochdr toc_hdr;
struct cdrom_tocentry toc_entry;
if((fd = open("/dev/cdrom", O_RDONLY)) == -1)
if(errno == ENOMEDIUM)
die(127, "cd_check_read_toc: No CD in drive");
else
die(127, "cd_check_read_toc: Cannot open /dev/cdrom");
if(ioctl(fd, CDROMREADTOCHDR, &toc_hdr) == -1)
die(127, "cd_check_read_toc: Cannot get header");
printf("First track: %d\nLast track: %d\n\n trackno) length\n",
toc_hdr.cdth_trk0, toc_hdr.cdth_trk1);
for(i = toc_hdr.cdth_trk0; i <= toc_hdr.cdth_trk1; i++){
toc_entry.cdte_track = i;
toc_entry.cdte_format = CDROM_MSF;
if(ioctl(fd, CDROMREADTOCENTRY, &toc_entry) == -1)
die(127, "cd_check_read_toc: 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,
(toc_entry.cdte_addr.msf.frame*100+27)/75);
}
close(fd);
return 0;
}