Skip to content

Instantly share code, notes, and snippets.

@marcusmueller
Created March 16, 2026 16:44
Show Gist options
  • Select an option

  • Save marcusmueller/b2bed3da42b8aac50ceba1c7ae17168a to your computer and use it in GitHub Desktop.

Select an option

Save marcusmueller/b2bed3da42b8aac50ceba1c7ae17168a to your computer and use it in GitHub Desktop.
// Copyright 2026 Marcus Müller
// SPDX-identifier: EUPL-1.2
#include <errno.h>
#include <fcntl.h>
#include <linux/cdrom.h>
#include <stdio.h>
#include <sys/ioctl.h>
int main(int argc, char *argv[]) {
if (argc != 2) {
fprintf(stderr, "USAGE:\n%s /dev/DEVICENAME\n", argv[0]);
return -2;
}
int fd = open(argv[1], O_RDWR|O_NONBLOCK);
if (fd == -1) {
perror("Error opening file");
return errno;
}
int retval = ioctl(fd, CDROMCLOSETRAY, 0);
if(retval == -1) {
perror("Error executing ioctl");
return errno;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment