diff options
Diffstat (limited to 'usr.bin/cdio')
-rw-r--r-- | usr.bin/cdio/cdio.c | 15 | ||||
-rw-r--r-- | usr.bin/cdio/extern.h | 1 | ||||
-rw-r--r-- | usr.bin/cdio/mmc.c | 13 |
3 files changed, 15 insertions, 14 deletions
diff --git a/usr.bin/cdio/cdio.c b/usr.bin/cdio/cdio.c index 551ed77c1f9..0921579efae 100644 --- a/usr.bin/cdio/cdio.c +++ b/usr.bin/cdio/cdio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cdio.c,v 1.52 2006/06/06 23:22:28 deraadt Exp $ */ +/* $OpenBSD: cdio.c,v 1.53 2006/06/15 23:49:58 mjc Exp $ */ /* Copyright (c) 1995 Serge V. Vakulenko * All rights reserved. @@ -301,17 +301,18 @@ main(int argc, char **argv) if (argv[0] == NULL) usage(); tr->file = argv[0]; - if (stat(tr->file, &sb) != 0) { - warn("cannot stat file %s",tr->file); - return (-1); - } + tr->fd = open(tr->file, O_RDONLY, 0640); + if (tr->fd == -1) + err(1, "cannot open file %s", tr->file); + if (fstat(tr->fd, &sb) == -1) + err(1, "cannot stat file %s", tr->file); tr->sz = sb.st_size; if (tr->type == 'a') tr->sz -= WAVHDRLEN; if (SLIST_EMPTY(&tracks)) - SLIST_INSERT_HEAD(&tracks,tr,track_list); + SLIST_INSERT_HEAD(&tracks, tr, track_list); else - SLIST_INSERT_AFTER(cur_track,tr,track_list); + SLIST_INSERT_AFTER(cur_track, tr, track_list); cur_track = tr; } if (!open_cd(cdname, 1)) diff --git a/usr.bin/cdio/extern.h b/usr.bin/cdio/extern.h index 3096ffb7f3a..4a45c05ae57 100644 --- a/usr.bin/cdio/extern.h +++ b/usr.bin/cdio/extern.h @@ -30,6 +30,7 @@ struct cd_toc_entry; struct track_info { off_t sz; u_int blklen; + int fd; char *file; SLIST_ENTRY(track_info) track_list; char type; diff --git a/usr.bin/cdio/mmc.c b/usr.bin/cdio/mmc.c index 01a259e208d..a77b8fe808a 100644 --- a/usr.bin/cdio/mmc.c +++ b/usr.bin/cdio/mmc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mmc.c,v 1.10 2006/06/06 23:22:28 deraadt Exp $ */ +/* $OpenBSD: mmc.c,v 1.11 2006/06/15 23:49:58 mjc Exp $ */ /* * Copyright (c) 2006 Michael Coulter <mjc@openbsd.org> @@ -175,7 +175,7 @@ writetrack(struct track_info *tr) scsireq_t scr; u_int end_lba, lba; u_int tmp; - int r,rfd; + int r; u_char nblk; nblk = 65535/tr->blklen; @@ -208,14 +208,13 @@ writetrack(struct track_info *tr) } else { end_lba = tr->sz / tr->blklen + lba; } - rfd = open(tr->file, O_RDONLY, 0640); if (tr->type == 'a') { - if (lseek(rfd, WAVHDRLEN, SEEK_SET) == -1) - err(1, "seek failed"); + if (lseek(tr->fd, WAVHDRLEN, SEEK_SET) == -1) + err(1, "seek failed for file %s", tr->file); } while ((lba < end_lba) && (nblk != 0)) { while (lba + nblk <= end_lba) { - read(rfd, databuf, nblk * tr->blklen); + read(tr->fd, databuf, nblk * tr->blklen); scr.cmd[8] = nblk; scr.datalen = nblk * tr->blklen; r = ioctl(fd, SCIOCCOMMAND, &scr); @@ -236,7 +235,7 @@ writetrack(struct track_info *tr) } nblk--; } - close(rfd); + close(tr->fd); return (0); } |