source: trunk/minix/commands/simple/eject.c@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 746 bytes
Line 
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>
12
13void fatal(char *label)
14{
15 fprintf(stderr, "eject: %s: %s\n", label, strerror(errno));
16 exit(1);
17}
18
19void main(int argc, char **argv)
20{
21 char *device;
22 int fd;
23
24 if (argc != 2) {
25 fprintf(stderr, "Usage: eject <device>\n");
26 exit(1);
27 }
28
29 device= argv[1];
30
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);
35
36 /* Tell it to eject. */
37 if (ioctl(fd, DIOCEJECT, nil) < 0) fatal(device);
38 exit(0);
39}
Note: See TracBrowser for help on using the repository browser.