2016-09-06 125 views
2

我试图在Linux上使用文件密封。这里有一个C程序的例子。F_SEAL_SEAL未声明,即使包含标题

#define _GNU_SOURCE 
#include <unistd.h> 
#include <fcntl.h> 

int main(void) { 
    (void)F_SEAL_SEAL; 
} 

您可以使用gcc -Wall -o ./linux_file_sealing linux_file_sealing.c或类似方式构建它。

当我建立它时,我得到一个关于F_SEAL_SEAL的错误。

gcc -Wall -o ./linux_file_sealing linux_file_sealing.c 
linux_file_sealing.c: In function ‘main’: 
linux_file_sealing.c:7:19: error: ‘F_SEAL_SEAL’ undeclared (first use in this function) 
    printf("%d\n",F_SEAL_SEAL); 
       ^
linux_file_sealing.c:7:19: note: each undeclared identifier is reported only once for each function it appears in 

我包括unistd.hfcntl.h,按照该男子页...所以还有什么我应该做的,而其中所描述? (这个手册页只是说密封是“特定于Linux”的,但没有提供进一步的细节,这就是包含GNU_SOURCE的定义的原因,这是你如何获得其他Linux特定的东西,但是对于F_SEAL_SEAL它似乎没有什么区别。)

(Ubuntu的LTS 16.04,Linux的4.4.0-36)

+0

您指的是哪个手册页? – alk

+0

我从'man fcntl'中得到的那个。看起来是这样的:http://man7.org/linux/man-pages/man2/fcntl.2.html - 但我没有检查每个字符! –

+0

我为此提出了一个手册页错误:https://bugzilla.kernel.org/show_bug.cgi?id=156231 –

回答

2

你想

#include <linux/fcntl.h> 

,而不是

#include <fcntl.h> 
+1

谢谢,这是有效的。这是记录在任何地方? –

+1

Nops,我在[searchcode](https://searchcode.com/?q=F_SEAL_SEAL%20repo:mirrors/linux-2.6)上找到它 –

+1

链接指出,谢谢 - 我相信这将证明有用。 –