Re: CDROM Ejection

Tigran Aivazian (tigran@saturn.home.uk)
Sun, 7 Apr 1996 13:10:37 +0000 (GMT)


On Sat, 30 Mar 1996, Alan Cox wrote:

> > i=ioctl(fd, CDROMEJECT);
>
> i=ioctl(fd, CDROMEJECT, 0);
>
> Or it wont compile.
>
> Alan

Yes, it will. The program below compiles and runs just fine.
Cheers,
Tigran.

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/cdrom.h>

main(int argc, char *argv[])
{
int i, fd, cmd;

if ( (argc == 2) && (!strcmp(argv[1], "-c")) )
cmd = CDROMCLOSETRAY;
else
cmd = CDROMEJECT;

if ( -1 == (fd=open("/dev/cdrom", O_RDONLY)) )
{
perror("open()");
exit(1);
}

if ( -1 == (i=ioctl(fd, cmd)) )
{
perror("ioctl()");
exit(1);
}

if ( -1 == close(fd) )
{
perror("close()");
exit(1);
}

return 0;
}