实例13-13.c

来自「linuxc编程书里的每章节课后全部的源代码 需要的人下载」· C语言 代码 · 共 38 行

C
38
字号
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/cdrom.h>

/* CD驱动器对应的设备文件 */
#define DEVICE "/dev/cdrom"
int main() 
{
  int fd;
  int status;
  struct cdrom_volctrl volume;
  /* 打开设备 */
  fd = open(DEVICE, O_RDONLY);
  if (fd < 0) {
    perror("unable to open " DEVICE);
    exit(1);
  }
  /* 设备音量 */
  volume.channel0 = 128;
  volume.channel1 = 128;
  volume.channel2 = 0;
  volume.channel3 = 0;
  status = ioctl(fd, CDROMVOLCTRL, &volume);
  if (status != 0) {
    perror("CDROMVOLCTRL ioctl failed");
    exit(1);
  }
  /* 关闭设备 */
  status = close(fd);
  if (status != 0) {
    perror("unable to close " DEVICE);
    exit(1);
  }
  return 0;
}

⌨️ 快捷键说明

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