6 static char *my_getline(FILE *file
) {
7 static size_t size
= 1024;
8 static char *buf
= NULL
;
9 static unsigned int i
= 0, r
= 0;;
12 buf
= (char*)malloc(size
);
15 memmove(buf
, buf
+i
, size
-i
);
23 buf
= (char*)realloc(buf
, size
);
27 r
+= fread(buf
+i
, 1, size
-i
, file
);
36 if(i
==r
|| buf
[i
] == '\n') {
44 int main(int argc
, char *argv
[]) {
45 char *line
, *pattern
, *module
;
49 fprintf(stderr
, "usage: resolve-modalias <alias file> <modalias>\n");
53 FILE *f
=fopen(argv
[1], "r");
55 perror("error opening alias file");
59 while((line
=my_getline(f
))!=NULL
) {
60 if(!strncmp(line
, "alias", strlen("alias"))) {
61 pos1
= index(line
, ' ');
62 pos2
= index(pos1
+1, ' ');
67 if(!fnmatch(pattern
, argv
[2], 0))
68 printf("%s\n", module
);
73 //vim: set ts=2 sw=2 et: