2 Device File Virtualization Guest Preload Library Helpers
4 (c) Akhil Guliani and William Gross, 2015
6 Adapted from MPI module (c) 2012 Peter Dinda
10 #define MAX_DEV_NAME_LENGTH 80
11 #define MAX_DEVICES 100
19 #include <sys/types.h>
25 ({ __typeof__ (a) _a = (a); \
26 __typeof__ (b) _b = (b); \
30 char *strcpy(char *dest, const char *src)
33 for (i=0; src[i] != '\0'; ++i)
39 size_t strlen(const char * str)
42 for (s = str; *s; ++s) {}
47 //taken from: https://stuff.mit.edu/afs/sipb/project/tcl80/src/tcl8.0/compat/strstr.c
48 char* strstr(const char* string,char* substring)
49 // register char *string; /* String to search. */
50 // char *substring; /* Substring to try to find in string. */
54 /* First scan quickly through the two strings looking for a
55 * * single-character match. When it's found, then compare the
56 * * rest of the substring.
63 for ( ; *string != 0; string += 1) {
82 //Used to keep track of the active file descriptor for the supported devices
83 //Initially the fd is -1 to indicate that the device has not yet been opened
84 typedef struct dev_file_fd_tracker {
85 char devName[MAX_DEV_NAME_LENGTH];
90 dev_tracker dtrack[] = {
93 {"/dev/input/mouse0",-1},
94 {"/dev/input/event0",-1},
95 {"/dev/input/event1",-1},
100 {"/dev/newDevice",-1}
105 //returns -1, means no match is found
106 //other than -1, is the index in the dtracker array of the match
107 int check_name(const char* path, dev_tracker tracker[]){
109 for(i=0; i<DEV_COUNT; i++){
110 if (strstr(path,tracker[i].devName)!=NULL){
116 //returns -1, means no match found
117 //other than -1, is the index in the dtracker array of the match
118 int check_fd(int fd, dev_tracker tracker[]){
120 for(i=0; i<DEV_COUNT; i++){
121 if(tracker[i].devFD == fd){