#include <fcntl.h>
#include <linux/cdrom.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>
int main(void)
{
int fd = open("/dev/cdrom", O_RDONLY | O_NONBLOCK);
if (fd == -1)
{
printf("Failed opening CD-ROM.\n");
return -1;
}
if (!ioctl(fd, CDROMEJECT, NULL))
printf("Ejected CD-ROM successfully.\n");
else
printf("Failed ejecting CD-ROM.\n");
close(fd);
return 0;
}