直接来个例子说明:
----------------------------------- 
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
//#incude <fcntl.h>  //这里必须屏蔽掉
// Must use Linux specific fcntl header.
#include </usr/include/linux/fcntl.h>
/* add for compile warnning */
extern int fcntl(int fd, int cmd, ... /* arg */ );
extern int open( const char * pathname, int flags);
int pipe_resize(int fd, int pipe_resize) {
if ( fd < 0 || pipe_resize > 1024*1024 || pipe_resize < 0 ){
eloge(mTag, "param error!");
return -1;
}
long pipe_size = (long)fcntl(fd, F_GETPIPE_SZ);
if (pipe_size == -1) {
perror("get pipe size failed.");
return -1;
}
elogi(mTag, "default pipe size: %ld\n", pipe_size);
int ret = fcntl(fd, F_SETPIPE_SZ, pipe_resize);
if (ret < 0) {
perror("set pipe size failed.");
return -1;
}
pipe_size = (long)fcntl(fd, F_GETPIPE_SZ);
if (pipe_size == -1) {
perror("get pipe size 2 failed.");
return -1;
}
elogi(mTag, "new pipe size: %ld\n", pipe_size);
return 0;
}
-----------------------------------
对于代码里面
-----------------------------------
//#incude <fcntl.h>  //这里必须屏蔽掉
// Must use Linux specific fcntl header.
#include </usr/include/linux/fcntl.h>
/* add for compile warnning */
extern int fcntl(int fd, int cmd, ... /* arg */ );
extern int open( const char * pathname, int flags);
-----------------------------------
屏蔽掉//#incude <fcntl.h>,而使用#include </usr/include/linux/fcntl.h>和函数声明
原因见后文的linux-specific使用说明
可以不屏蔽//#incude <fcntl.h>,自己手动添加 F_SETPIPE_SZ和F_GETPIPE_SZ宏定义
=======
#define F_LINUX_SPECIFIC_BASE   1024
/*
* Set and get of pipe page size array
*/
#define F_SETPIPE_SZ    (F_LINUX_SPECIFIC_BASE + 7)
#define F_GETPIPE_SZ    (F_LINUX_SPECIFIC_BASE + 8)
=======
linux-specific使用说明:
从两个地方入手,首先得了解用户空间调用内核系统函数的过程
可以参考:
先了解 SYSCALL_DEFINEx 的使用方法
http://blog.csdn.net/hazir/article/details/11835025
fcntl的例子网上的说明文章不多,以open为例
http://blog.csdn.net/shanshanpt/article/details/39852249
http://blog.csdn.net/viewsky11/article/details/77934608
http://blog.chinaunix.net/uid-20522771-id-4419666.html
http://blog.csdn.net/fyfcauc/article/details/37757915
http://blog.csdn.net/fyfcauc/article/details/37757947
上面所有的参考都只为说明一点,用户空间的 fcntl函数的
最终实现在:
kernel\linux-3.4.y\fs\fcntl.c
SYSCALL_DEFINE3(fcntl, unsigned int, fd, unsigned int, cmd, unsigned long, arg)
系统接口在:
kernel\linux-3.4.y\include\linux\syscalls.h
asmlinkage long sys_fcntl(unsigned int fd, unsigned int cmd, unsigned long arg);
关于Linux系统调用(syscall)原理,不清楚的可以参考
http://gityuan.com/2016/05/21/syscall/
对于系统函数的封装调用细节不管,但肯定是用户空间应用调用 ‘fcntl’,内核空间调用到 ‘sys_fcntl’
最终call到了kernel\linux-3.4.y\fs\fcntl.c中SYSCALL_DEFINE3(fcntl, unsigned int, fd, unsigned int, cmd, unsigned long, arg)这个函数
而对于编译器默认路径,fcntl头文件路径是:
#include <fcntl.h> //即 /opt/hisi-linux/x86-arm/arm-hisiv300-linux/target/usr/include/fcntl.h
这个头文件里面是没有F_GETPIPE_SZ、F_SETPIPE_SZ这些宏定义的
参考:https://linux.die.net/man/2/fcntl  它是linux独有的
所以需要用到另外一个路径的头文件/opt/hisi-linux/x86-arm/arm-hisiv300-linux/target/usr/include/linux/fcntl.h
用它就需要添加头文件包含
#include </usr/include/linux/fcntl.h> 
//实际上这里可以简写为 #include <linux/fcntl.h>,
//因为编译器默认路径已经包含到了/opt/hisi-linux/x86-arm/arm-hisiv300-linux/target/usr/include/
而此时打开这个fcntl.h你会发现里面并没有fcntl这个函数的声明,
但是编译器和连接器是可以从/opt/hisi-linux/x86-arm/arm-hisiv300-linux/target/usr/lib/libc.a或者libc.so中找到fcntl函数这个符号的
所以如果忽略警告的话,编译链接都没问题,只要参数不用错,也不会出问题。
但对于警告:
error: implicit declaration of function ‘fcntl’ [-Werror=implicit-function-declaration]
error: implicit declaration of function ‘open’ [-Werror=implicit-function-declaration]
不容忽视,详见下面链接的文章说明
http://daiyuwen.freeshell.org/gb/programming/about_header_files.html
所以我们需要再添加函数的声明
extern int fcntl(int fd, int cmd, ... /* arg */ );
extern int open( const char * pathname, int flags);

转载于:https://www.cnblogs.com/cutelinux/p/7868332.html

fcntl函数参数F_GETPIPE_SZ、F_SETPIPE_SZ报错引出的关于linux-specific头文件的使用方法...相关推荐

  1. 【错误记录】Groovy 函数参数动态类型报错 ( Caught: groovy.lang.MissingMethodException: No signature of method )

    文章目录 一.报错信息 二.解决方案 一.报错信息 定义 Groovy 函数 , void fun(object) {object.hello() } 如果传入的 实例对象 中 , 没有定义 hell ...

  2. C/C++多个链接库含有同名函数,编译会报错吗

    C/C++多个链接库含有同名函数,编译会报错吗 起因 基本概念 同名函数测试 测试1:`.o`目标文件 测试2:静态库 测试3:动态库 同名函数的应用 起因 由于业务需要,我司使用了Mellanox某 ...

  3. 详解ArcGIS (Pro)面积制表(区域制表)参数设置及报错处理

    1.参数设置 2.报错处理 1.参数设置 ArcGIS中的"面积制表"功能对应ArcGIS Pro中的"区域制表"功能: 二者设定参数的方法是类似的.例如现在我 ...

  4. oracle log block size,案例:Oracle无法启动报错ORA-00218: block size 0 重建控制文件

    天萃荷净 oracle数据库无法启动报错ORA-00218故障,通过重建控制文件解决文件损坏问题 遇到一个案例在数据库启动的时候报ORA-00218错误,而这个故障的引起原因是因为重建控制文件的时候, ...

  5. eclipse启动报错 Java was started but returned exit code=13 解决方法

    目录 报错如下: 问题原因及解决: 1.eclipse安装版本与jdk不一致 2.eclipse配置参数有问题 报错如下: 问题原因及解决: 1.eclipse安装版本与jdk不一致 如果jdk安装版 ...

  6. http请求报错Illegal character in query at index 303的解决方法

    http请求报错"Illegal character in query at index 303"的解决方法 执行jmeter的http请求时,请求失败,在Sampler resu ...

  7. cmake编译安装完成后 执行cmake --version报错 bash: /usr/bin/cmake: 没有那个文件或目录

    cmake编译安装完成后 执行cmake --version报错 bash: /usr/bin/cmake: 没有那个文件或目录 cmake 没有那个目录 - 未完代码 - 博客园 因为直接使用cma ...

  8. svn update 报错,必须先cleanup,然后cleanup失败解决方法

    svn update 报错,必须先cleanup,然后cleanup失败解决方法 参考文章: (1)svn update 报错,必须先cleanup,然后cleanup失败解决方法 (2)https: ...

  9. C#操作FTP报错,远程服务器返回错误:(550)文件不可用(例如,未找到文件,无法访问文件)的解决方法

    C#操作FTP报错,远程服务器返回错误:(550)文件不可用(例如,未找到文件,无法访问文件)的解决方法 参考文章: (1)C#操作FTP报错,远程服务器返回错误:(550)文件不可用(例如,未找到文 ...

最新文章

  1. 使用 UIBezierPath 进行简单的图形绘制
  2. 【NLP】情感分析实战:金融市场中的NLP
  3. 列车时刻管理c语言程序设计,列车时刻表信息管理系统实践报告C语言源代码
  4. unity手机 通过php连接mysql_如何从Unity连接到数据库
  5. 两个unit取和会溢出吗_真正“爱”一个人时,就会涌现这种强烈的感觉,你曾经体验过吗?...
  6. 蓝桥集训之BFS、DFS和链式前向星
  7. Greenplu数据库的部署
  8. java虚拟机是什么?
  9. java heapdump 分析工具_Heapdump分析软件
  10. vcpkg安装库时异常解决
  11. 逆火软件测试工资,世界级人体工学设计:HyperX Pulsefire FPS逆火鼠标评测
  12. win10应用商店不见了
  13. 两台服务器联通如何配置文件,两个服务器之间数据库怎么连接
  14. exactly-once在Flink里的实现
  15. 2023前端大厂面试题之JavaScript篇(4)
  16. 社会工程学攻击案例-伪装木马
  17. ie11 开发者工具
  18. V神全面回应币安下架BSV:万字长文、4大要点 (全文)
  19. php 生成 rtf,php 实现html转为rtf格式_php
  20. 人生苦短,我用 Python,如何学习 Python 网络爬虫?

热门文章

  1. 每个zone的low memory是怎么计算出来的
  2. 编程3:仅用递归函数和栈操作逆序一个栈
  3. [CodeForces1070C]Cloud Computing(2018-2019 ICPC, NEERC, Southern Subregional Contest )
  4. [JSOI 2011]分特产
  5. information_schema系列八(事物,锁)
  6. 营销区块链技术的艺术
  7. RocketMQ性能压测分析(转载)
  8. 最常用的6种原型文件格式对比
  9. Linux压缩解压缩命令
  10. Java中Volatile的理解