Skip to content

Instantly share code, notes, and snippets.

@lethean
Created October 24, 2016 08:45
Show Gist options
  • Save lethean/15c932cba9b6b716fae46a63c059d1d8 to your computer and use it in GitHub Desktop.
Save lethean/15c932cba9b6b716fae46a63c059d1d8 to your computer and use it in GitHub Desktop.
Simple CD-ROM Eject
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/cdrom.h>
int
main (int argc,
char **argv)
{
int fd;
char *devname = argv[1];
fd = open (devname, O_RDWR | O_NONBLOCK);
if (fd < 0)
fd = open (devname, O_RDONLY | O_NONBLOCK);
if (fd >= 0)
{
if (ioctl (fd, CDROM_LOCKDOOR, 0) >= 0)
ioctl (fd, CDROMEJECT);
close (fd);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment