【问题标题】:How to save the uint32_t mask as a pointer variable?如何将 uint32_t 掩码保存为指针变量?
【发布时间】:2021-04-08 16:41:49
【问题描述】:

这个void inotifyFunc() 包含一个变量作为参数,它是char *path。我还想添加另一个变量,它应该包含uint32_t mask 的地址,基本上是 ENOENT、IN_CREATE、IN_DELETE 等,它存在于inotify_add_watch() 中,但我不知道如何保存@ 987654325@作为变量。

我的主要目标是在主函数中调用这个函数,方法是编写一个路径,一次我应该分配给路径的一个命令(IN_CREATE、IN_DELETE 等)。

希望你能理解我的问题。

void inotifyFunc(char *path){
    monitor.fd = inotify_init();
    if(fcntl(monitor.fd, F_SETFL, O_NONBLOCK)){
       perror("inotify not initialized: ");
       exit(0);
    }

    monitor.wd = inotify_add_watch(monitor.fd, path, ENOENT);
    if(monitor.wd < 0){
        perror("Sorry");
        exit(1);
    }
    else{
        printf("Location '%s' is being monitored\n\n", path);
    }
}

【问题讨论】:

  • 不清楚你有什么困难。为什么不能只在函数中添加一个uint32_t *mask 参数?为什么它必须是地址/指针?
  • @kaylum 我想调用这个函数在一个主函数中并给出路径和我想分配给路径的命令。就像我要监控路径被创建或修改或删除等。

标签: c function inotify


【解决方案1】:

如果我做对了

变化:

void inotifyFunc(char *path) {

收件人:

void inotifyFunc(char *path, uint32_t *mask ) {

然后

uint32_t mask = ENOENT;
inotifyFunc("....", &mask); // Address of (pointer to) mask

然后使用

monitor.wd = inotify_add_watch(monitor.fd, path, mask);

编辑

因为我刚刚阅读了手册页 - 请参阅评论

然后

monitor.wd = inotify_add_watch(monitor.fd, path, *mask);

或者

void inotifyFunc(char *path, uint32_t mask ) {

 inotifyFunc("....", mask);

【讨论】:

猜你喜欢
  • 2019-02-22
  • 1970-01-01
  • 1970-01-01
  • 2021-05-06
  • 2020-04-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多