Repository navigation
Expand file tree
/
Copy pathfiller.c
More file actions
48 lines (43 loc) · 1.39 KB
/
Copy pathfiller.c
File metadata and controls
48 lines (43 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
/*
@brief
- took help from stackoverflow/GFG for understanding the cammand line arguments concept argc, argv
- argc (ARGument Count) is an integer variable that stores the number of command-line arguments passed by the user including the name of the program.
So if we pass a value to a program, the value of argc would be 2 (one for argument and one for program name)
- argv (ARGument Vector) is an array of character pointers listing all the arguments.
*/
#define PUSH_DATA _IOW('q', 2, struct queue_data)
struct queue_data{
int length;
char *data;
};
int main(int argc, char *argv[]){
// ensuring right no. of arguments are being passed
if (argc != 2) {
fprintf(stderr, "Usage: %s <string argument needed>\n", argv[0]);
return EXIT_FAILURE;
}
printf("No. of arguments %d ", argc);
char *data = argv[1];
struct queue_data qd;
qd.length = strlen(data) + 1;
qd.data = data;
int fd = open("/dev/shrish", O_RDWR);
if (fd < 0){
perror("Failed to open the device");
return EXIT_FAILURE;
}
if (ioctl(fd, PUSH_DATA, &qd) < 0){
perror("Failed to push data");
close(fd);
return EXIT_FAILURE;
}
printf("Data pushed successfully : %s\n", data);
close(fd);
return EXIT_SUCCESS;
}