Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/cdplay replace guts of opencd() with call to opendis...



details:   https://anonhg.NetBSD.org/src/rev/7bde65177a46
branches:  trunk
changeset: 500673:7bde65177a46
user:      lukem <lukem%NetBSD.org@localhost>
date:      Sat Dec 16 01:36:00 2000 +0000

description:
replace guts of opencd() with call to opendisk(). prevents coredump
when a device with a leading / (e.g, `/dev/cd0') is given, as well as
promotes code reuse ;-)

diffstat:

 usr.bin/cdplay/Makefile |   6 +++---
 usr.bin/cdplay/cdplay.c |  24 +++++-------------------
 2 files changed, 8 insertions(+), 22 deletions(-)

diffs (77 lines):

diff -r 44cbd9e716a6 -r 7bde65177a46 usr.bin/cdplay/Makefile
--- a/usr.bin/cdplay/Makefile   Fri Dec 15 23:42:22 2000 +0000
+++ b/usr.bin/cdplay/Makefile   Sat Dec 16 01:36:00 2000 +0000
@@ -1,9 +1,9 @@
-#      $NetBSD: Makefile,v 1.2 1999/11/26 18:34:58 msaitoh Exp $
+#      $NetBSD: Makefile,v 1.3 2000/12/16 01:36:00 lukem Exp $
 
 PROG=  cdplay
 SRCS=  cdplay.c
 
-LDADD+= -ledit -ltermcap
-DPADD+= ${LIBEDIT} ${LIBTERMCAP}
+LDADD+= -ledit -ltermcap -lutil
+DPADD+= ${LIBEDIT} ${LIBTERMCAP} ${LIBUTIL}
 
 .include <bsd.prog.mk>
diff -r 44cbd9e716a6 -r 7bde65177a46 usr.bin/cdplay/cdplay.c
--- a/usr.bin/cdplay/cdplay.c   Fri Dec 15 23:42:22 2000 +0000
+++ b/usr.bin/cdplay/cdplay.c   Sat Dec 16 01:36:00 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cdplay.c,v 1.10 2000/10/11 14:46:01 is Exp $   */
+/*     $NetBSD: cdplay.c,v 1.11 2000/12/16 01:36:00 lukem Exp $        */
 
 /*
  * Copyright (c) 1999 Andrew Doran.
@@ -50,13 +50,13 @@
  */
 
 /*
- * XXX there are too many oppertunities to trash the stack from the command
+ * XXX there are too many opportunities to trash the stack from the command
  * line - ad
  */
  
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: cdplay.c,v 1.10 2000/10/11 14:46:01 is Exp $");
+__RCSID("$NetBSD: cdplay.c,v 1.11 2000/12/16 01:36:00 lukem Exp $");
 #endif /* not lint */
 
 #include <sys/endian.h>
@@ -72,6 +72,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <util.h>
 
 #include <machine/disklabel.h>
 
@@ -1032,26 +1033,11 @@
 opencd()
 {
        char devbuf[80];
-       size_t len;
 
        if (fd > -1)
                return (1);
 
-       if (*cdname == '/')
-               strcpy(devbuf, cdname);
-       else
-               if (*cdname == 'r')
-                       len = sprintf(devbuf, "/dev/%s", cdname);
-               else
-                       len = sprintf(devbuf, "/dev/r%s", cdname);
-
-       fd = open(devbuf, O_RDONLY);
-
-       if (fd < 0 && errno == ENOENT) {
-               devbuf[len] = 'a' + RAW_PART;
-               devbuf[len + 1] = '\0';
-               fd = open(devbuf, O_RDONLY);
-       }
+       fd = opendisk(cdname, O_RDONLY, devbuf, sizeof(devbuf), 0);
 
        if (fd < 0) {
                if (errno == ENXIO) {



Home | Main Index | Thread Index | Old Index