sbase/eject.c

57 lines
878 B
C
Raw Normal View History

2013-09-04 12:31:06 +00:00
/* See LICENSE file for copyright and license details. */
#include <sys/ioctl.h>
2014-06-30 18:03:41 +00:00
#include <sys/stat.h>
#include <sys/types.h>
2013-09-04 12:31:06 +00:00
#include <fcntl.h>
#include <stdio.h>
2013-10-07 18:11:40 +00:00
#include <stdlib.h>
2014-06-30 18:03:41 +00:00
#include <unistd.h>
2013-09-04 12:31:06 +00:00
#include "util.h"
enum {
CDROM_EJECT = 0x5309,
CDROM_CLOSE_TRAY = 0x5319,
};
static void
usage(void)
{
eprintf("usage: %s [-t] [devname]\n", argv0);
2013-09-04 12:31:06 +00:00
}
int
main(int argc, char *argv[])
{
int fd, out;
char *cdrom = "/dev/sr0";
2013-09-04 12:31:06 +00:00
int tflag = 0;
ARGBEGIN {
case 't':
tflag = 1;
break;
default:
usage();
} ARGEND;
if (argc > 1)
usage();
else if (argc == 1)
cdrom = argv[0];
2013-09-04 12:31:06 +00:00
fd = open(cdrom, O_RDONLY | O_NONBLOCK);
if (fd < 0)
eprintf("open %s:", cdrom);
if (tflag) {
if (ioctl(fd, CDROM_CLOSE_TRAY, &out) < 0)
eprintf("ioctl:");
} else {
if (ioctl(fd, CDROM_EJECT, &out) < 0)
eprintf("ioctl:");
}
close(fd);
2013-10-07 18:11:40 +00:00
return EXIT_SUCCESS;
2013-09-04 12:31:06 +00:00
}