📄 syscalls.c
字号:
/* * syscalls.c * Program to illustrate common system calls. Doesn't actually * perform any useful function, but will later be expanded into * a program which does. */#include <unistd.h>#include <stdio.h>#include <fcntl.h>#include <sys/types.h>#include <sys/ioctl.h>#include <linux/soundcard.h>int main(){ int fd; /* device file descriptor */ int arg; /* argument for ioctl call */ unsigned char buf[1000]; /* buffer to hold data */ int status; /* return status of system calls */ /* open device */ status = fd = open("/dev/dsp", O_RDWR); if (status == -1) { perror("error opening /dev/dsp"); exit(1); } /* set a parameter using ioctl call */ arg = 8000; /* sampling rate */ status = ioctl(fd, SOUND_PCM_WRITE_RATE, &arg); if (status == -1) { perror("error from SOUND_PCM_WRITE_RATE ioctl"); exit(1); } /* read some data */ status = read(fd, buf, sizeof(buf)); if (status == -1) { perror("error reading from /dev/dsp"); exit(1); } /* write some data */ status = write(fd, buf, sizeof(buf)); if (status == -1) { perror("error writing to /dev/dsp"); exit(1); } /* close the device */ status = close(fd); if (status == -1) { perror("error closing /dev/dsp"); exit(1); } /* and exit */ return(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -