如何为stat函数编写函数存根?

问题描述

我正在尝试从中为stat()函数编写存根。 我可以使用以下代码为fstat成功完成此操作:

static int fstat_count;
static int fstat_fail_instance;
int my_fstat(const int fd,struct stat * st) {
  fstat_count ++;
  if (fstat_count == fstat_fail_instance) {
    return EINVAL;
  }
  st->st_size = ST_SIZE;
  return EOK;
}
#undef fstat
#define fstat my_fstat

当我尝试使用stat执行此操作时,出现如下错误:

mkqfs_file_test.c:28:20: error: storage size of ‘sb’ isn’t known
  const struct stat sb;
我相信是因为

#undef stat #define stat my_stat 就像我对fstat所做的一样,它未定义struct stat而不是函数。 知道如何解决这个问题,也就是只能取消定义/重新定义功能吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)