Created
March 16, 2026 16:44
-
-
Save marcusmueller/b2bed3da42b8aac50ceba1c7ae17168a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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