unstack, sort: cleanup and improvement
[minix.git] / commands / eject / eject.c
blobf0821296cfb83e8f6f4dde7542f734b6e8364932
1 /* eject 1.3 - Eject removable media Author: Kees J. Bot
2 * 11 Dec 1993
3 */
4 #define nil 0
5 #include <sys/types.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <errno.h>
9 #include <fcntl.h>
10 #include <string.h>
11 #include <sys/ioctl.h>
13 void fatal(char *label)
15 fprintf(stderr, "eject: %s: %s\n", label, strerror(errno));
16 exit(1);
19 int main(int argc, char **argv)
21 char *device;
22 int fd;
24 if (argc != 2) {
25 fprintf(stderr, "Usage: eject <device>\n");
26 exit(1);
29 device= argv[1];
31 /* Try to open it in whatever mode. */
32 fd= open(device, O_RDONLY);
33 if (fd < 0 && errno == EACCES) fd= open(device, O_WRONLY);
34 if (fd < 0) fatal(device);
36 /* Tell it to eject. */
37 if (ioctl(fd, DIOCEJECT, nil) < 0) fatal(device);
38 exit(0);