diff --git a/Makefile b/Makefile index 806f14c..5f198b0 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,12 @@ -override CFLAGS+=-Werror -Wall -g -fPIC -O2 -DNDEBUG -std=c99 -ftrapv -Wfloat-equal -Wundef -Wwrite-strings -Wconversion -Wuninitialized +STD=c11 +override CFLAGS+=-Werror -Wall -g -fPIC -O2 -DNDEBUG -std=$(STD) -ftrapv -Wfloat-equal -Wundef -Wwrite-strings -Wconversion -Wuninitialized PREFIX=/usr/bin/cd_check/ BUILDDIR=bin/ SRCDIR=src/ #Makes everything all: - mkdir $(BUILDDIR) 2> /dev/null || true + mkdir -p $(BUILDDIR) 2> /dev/null || true cc $(CFLAGS) $(SRCDIR)cd_check_eject.c -o $(BUILDDIR)cd_check_eject cc $(CFLAGS) $(SRCDIR)cd_check_capabilities.c -o $(BUILDDIR)cd_check_capabilities cc $(CFLAGS) $(SRCDIR)cd_check_read_toc.c -o $(BUILDDIR)cd_check_read_toc @@ -13,7 +14,7 @@ all: #Uses picky extensions and makes everything(Extensions may break compiling) dev: - make all CFLAGS+=-Wshadow -Wunreachable-code -Wswitch-enum -Wswitch-default -Wcast-align -Winit-self -Wpointer-arith -Weffc++ + make all CFLAGS+="-Wshadow -Wunreachable-code -Wswitch-enum -Wswitch-default -Wcast-align -Winit-self -Wpointer-arith -Weffc++" #Cleans directory(no uninstall!) clean: @@ -27,7 +28,6 @@ install: install $(BUILDDIR)cd_check_read_toc $(PREFIX)cd_check_read_toc install $(BUILDDIR)cd_check_read $(PREFIX)cd_check_read - #Uninstalls from specified(or default)directory uninstall: rm -rf $(PREFIX) diff --git a/src/cd_check_capabilities.c b/src/cd_check_capabilities.c index 3aa8be6..77a7f9d 100644 --- a/src/cd_check_capabilities.c +++ b/src/cd_check_capabilities.c @@ -7,7 +7,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); } @@ -15,13 +16,16 @@ static inline void die(int code, const char* message){ int main(int argc, char** argv){ register int fd, caps; + if(!argv) die(127, "How did you do that? No argv?", -1); program_name = argv[0]; if((fd = open("/dev/cdrom", O_RDONLY | O_NONBLOCK)) == -1) - die(127, "Cannot open /dev/cdrom"); + die(127, "Cannot open /dev/cdrom", fd); if((caps = ioctl(fd, CDROM_GET_CAPABILITY)) == -1) - die(127, "ioctl failed"); + die(127, "ioctl failed", fd); + + close(fd); 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", @@ -39,6 +43,5 @@ int main(int argc, char** argv){ (caps & CDC_PLAY_AUDIO) ? "yes" : "no", (caps & CDC_SELECT_DISC) ? "yes" : "no"); - close(fd); return 0; } diff --git a/src/cd_check_eject.c b/src/cd_check_eject.c index e334aa5..03539dd 100644 --- a/src/cd_check_eject.c +++ b/src/cd_check_eject.c @@ -7,7 +7,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); } @@ -15,13 +16,14 @@ static inline void die(int code, const char* message){ int main(int argc, char** argv){ register int fd; + if(!argv) die(127, "How did you do that? No argv?", -1); program_name = argv[0]; if((fd = open("/dev/cdrom", O_RDONLY | O_NONBLOCK)) == -1) - die(127, "Cannot open /dev/cdrom"); + die(127, "Cannot open /dev/cdrom", fd); if(ioctl(fd, CDROMEJECT) == -1) - die(127, "ioctl() failed"); + die(127, "ioctl() failed", fd); close(fd); diff --git a/src/cd_check_read.c b/src/cd_check_read.c index e48eb31..66e54ce 100644 --- a/src/cd_check_read.c +++ b/src/cd_check_read.c @@ -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); } @@ -18,20 +19,21 @@ int main(int argc, char** argv){ struct cdrom_tocentry toc_entry; struct cdrom_msf start_stop; + 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); } toc_entry.cdte_track = 1; toc_entry.cdte_format = CDROM_MSF; if(ioctl(fd, CDROMREADTOCENTRY, &toc_entry) == -1) - die(127, "ioctl() failed"); + die(127, "ioctl() failed", fd); start_stop.cdmsf_min0 = toc_entry.cdte_addr.msf.minute; start_stop.cdmsf_sec0 = toc_entry.cdte_addr.msf.second; @@ -41,20 +43,20 @@ int main(int argc, char** argv){ toc_entry.cdte_format = CDROM_MSF; if(ioctl(fd, CDROMREADTOCENTRY, &toc_entry) == -1) - die(127, "ioctl() failed"); + die(127, "ioctl() failed", fd); start_stop.cdmsf_min1 = toc_entry.cdte_addr.msf.minute; start_stop.cdmsf_sec1 = toc_entry.cdte_addr.msf.second; start_stop.cdmsf_frame1 = toc_entry.cdte_addr.msf.frame; if(ioctl(fd, CDROMPLAYMSF, &start_stop) == -1) - die(127, "ioctl() failed"); + die(127, "ioctl() failed", fd); printf("Press anything to stop playing.\n"); getchar(); if(ioctl(fd, CDROMSTOP) == -1) - die(127, "ioctl() failed"); + die(127, "ioctl() failed", fd); close(fd); return 0; diff --git a/src/cd_check_read_toc.c b/src/cd_check_read_toc.c index 806d128..2e04d60 100644 --- a/src/cd_check_read_toc.c +++ b/src/cd_check_read_toc.c @@ -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,