Initial commit
This commit is contained in:
45
src/cd_check_read_toc.c
Normal file
45
src/cd_check_read_toc.c
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user