eject.c

来自「在linux下多媒体开发实例linux下多媒体开发」· C语言 代码 · 共 40 行

C
40
字号
/* * eject.c * Example program to eject CD. */#include <unistd.h>#include <stdlib.h>#include <sys/ioctl.h>#include <fcntl.h>#include <linux/cdrom.h>/* CD-ROM device file name */#define DEVICE "/dev/cdrom"int main(){  int fd;           /* file descriptor for CD-ROM device */  int status;       /* return status for system calls */  /* open device */    status = fd = open(DEVICE, O_RDONLY);  if (status < 0) {    perror("unable to open "DEVICE);    exit(1);  }  /* eject */    status = ioctl(fd, CDROMEJECT);  if (status != 0) {    perror("CDROMEJECT ioctl failed");    exit(1);  }  /* close device */  status = close(fd);  if (status != 0) {    perror("unable to close "DEVICE);    exit(1);  }  exit(0);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?