Skip to content
Snippets Groups Projects
Commit e34bc9a9 authored by 최준영's avatar 최준영
Browse files

Add new file

parent 2a2a4906
No related branches found
No related tags found
No related merge requests found
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/sysmacros.h>
#define GAS_MAJOR_NUMBER 505
#define GAS_MINOR_NUMBER 100
#define GAS_DEV_PATH_NAME "/dev/gas_ioctl"
#define IOCTL_MAGIC_NUMBER 'g'
#define IOCTL_CMD_GAS_ON _IO(IOCTL_MAGIC_NUMBER, 0)
#define IOCTL_CMD_GAS_OFF _IO(IOCTL_MAGIC_NUMBER, 1)
int main(void) {
dev_t gas_dev;
int fd;
gas_dev = makedev(GAS_MAJOR_NUMBER, GAS_MINOR_NUMBER);
mknod(GAS_DEV_PATH_NAME, S_IFCHR | 0666, gas_dev);
fd = open(GAS_DEV_PATH_NAME, O_RDWR);
if (fd < 0) {
printf("fail to open gas\n");
return -1;
}
int i = 0;
while (i < 100) {
if (ioctl(fd, IOCTL_CMD_GAS_ON, 0) == 0) {
printf("gas on\n");
sleep(1);
i++;
}
else
printf("no gas\n");
sleep(1);
i++;
}
close(fd);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment