2016-09-06 71 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

鏈接指出,謝謝 - 我相信這將證明有用。 –