C警告:函数’fchmod’的隐式声明
发布时间:2020-12-16 09:34:35 所属栏目:百科 来源:网络整理
导读:我有一个使用fchmod的函数createFile: int createFile(char *pFileName) { int ret; if ((ret = open(pFileName,O_RDWR | O_CREAT | O_TRUNC)) 0) errorAndQuit(2); fchmod(ret,S_IRUSR | S_IWUSR); return ret;} 在我的文件顶部,我有以下内容: #include s
我有一个使用fchmod的函数createFile:
int createFile(char *pFileName) { int ret; if ((ret = open(pFileName,O_RDWR | O_CREAT | O_TRUNC)) < 0) errorAndQuit(2); fchmod(ret,S_IRUSR | S_IWUSR); return ret; } 在我的文件顶部,我有以下内容: #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <sys/stat.h> #include <fcntl.h> 编译时:编译器吐出: warning: implicit declaration of function ‘fchmod’ 我包含了所有正确的文件,但却得到了这个警告.该程序运行正常,即使有警告. 解决方法
巧合的是,feature_test_macros(7)联机帮助页直接回答了您的问题:
Specification of feature test macro requirements in manual pages When a function requires that a feature test macro is defined,the manual page SYNOPSIS typically includes a note of the following form (this example from the chmod(2) manual page): #include <sys/stat.h> int chmod(const char *path,mode_t mode); int fchmod(int fd,mode_t mode); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): fchmod(): _BSD_SOURCE || _XOPEN_SOURCE >= 500 The || means that in order to obtain the declaration of fchmod(2) from <sys/stat.h>,either of the following macro definitions must be made before including any header files: #define _BSD_SOURCE #define _XOPEN_SOURCE 500 /* or any value > 500 */ Alternatively,equivalent definitions can be included in the compilation command: cc -D_BSD_SOURCE cc -D_XOPEN_SOURCE=500 # Or any value > 500 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- c# – 如何在resharper中关闭“将扩展方法转换为纯静态”自
- 有时候执行的oracle,sql语句要查看下性能情况,可以用这个
- VB备忘录(8) 窗体
- postgresql – pg_dump:命令行参数太多
- c# – JObject和CamelCase与JSON.Net的转换
- c# – 用于验证逗号分隔的电子邮件地址的正则表达式?
- Vue2实时监听表单变化的示例讲解
- ruby-on-rails – Ruby on Rails应用程序的FTPS(TLS / SSL)
- c# – 在泛型(Y)方法中使用泛型(X)委托,其中Y扩展了一些基类
- 有没有办法通过settings.xml禁用maven-deploy-plugin的部署