【发布时间】:2021-04-09 12:39:38
【问题描述】:
我已经让inotifyFunc 监控两条路径。除了最后一行 [我从主函数中获取的代码] 即monitor.wd[0],没有什么给我错误。错误是
警告:传递“inotifyFunc”的参数 3 使指针从 没有强制转换的整数
不知道是什么问题?虽然上面这行monitor.wd[0] = *pathname1; 没有给我报错。
void inotifyFunc(char *path, uint32_t *maskPtr, int *wd[2]){
monitor.fd = inotify_init();
if(fcntl(monitor.fd, F_SETFL, O_NONBLOCK)){
perror("inotify not initialized: ");
exit(0);
}
*wd[0] = inotify_add_watch(monitor.fd, path, *maskPtr);
*wd[1] = inotify_add_watch(monitor.fd, path, *maskPtr);
if(*wd[0] < 0 || *wd[1] < 0){
perror("Sorry");
exit(1);
}
}
取自主函数的代码
monitor.mask[0] = ENOENT;
monitor.mask[1] = IN_CREATE;
printf("Choose the source path: ");
scanf("%s", pathname1);
monitor.wd[0] = *pathname1;
inotifyFunc(pathname1, &monitor.mask[0], monitor.wd[0]);
【问题讨论】:
-
这可能只是我的无知(我从未使用过inotify),但如果
monitor是struct inotify_event类型,我怀疑wd是int类型绝对不是字符串数组。此外,同一结构的mask字段的类型为uint32_t,所以我不明白你为什么将它用作数组。能否请您发布monitor类型的结构定义? -
我认为你选择了一个坏名字
wd。这个名字是什么意思?您可以使用哪个更具描述性的名称?也许,如果你回答这个问题,你可以解决你的问题。或者,如果不是,您至少可以澄清您最初的问题。 -
从不在 scanf 中使用
"%s"。不比gets好。如果您要为此使用 scanf,至少在转换说明符中使用宽度。例如char path[256]; scanf("%255s", path);