linux splice函数,[操作系统]splice()函数,SPLICE_F_MOVE SPLICE_F_NONBLOCK ‘SPLICE_F_MORE undeclared...

[操作系统]splice()函数,SPLICE_F_MOVE SPLICE_F_NONBLOCK ‘SPLICE_F_MORE undeclared

0 2016-01-01 01:00:26

1.编译含有splice()函数的程序时出现,'SPLICE_F_MOVE'  undeclared,'SPLICE_F_NONBLOCK' ‘SPLICE_F_MORE' 也是一样undeclared!

2.使用man splice查看,发现要定义宏_GNU_SOURCE1 #define _GNU_SOURCE /* See feature_test_macros(7) */2 #include 3 4 ssize_t splice(int fd_in, loff_t *off_in, int fd_out, loff_t *off_out, size_t len, unsigned int flags);

我们跟着后面宏的注释See feature_test_macros(7)1 $:man feature_test_macros

man手册上面的描述是:特性测试宏允许程序编译时控制系统头文件的宏定义!1 NAME2 feature_test_macros - feature test macros3 4 SYNOPSIS5 #include 6 7 DESCRIPTION8 Feature test macros allow the programmer to control the definitions that are exposed by system header files when a program is compiled.

3.我们找找看,splice()函数的这个几个flags参数宏定义在哪里。splice()函数定义在头文件里面,查看头文件1 $:vim /usr/include/fcntl.h

然而里面并没有这几个宏,但里面有包含了,文件,我们跟进去这2个文件。我的系统是64位的kail。

bits文件夹在/usr/include/x86_64-linux-gnu/bits/1 $:vim /usr/include/features.h2 $:vim /usr/include/x86_64-linux-gnu/bits/fcntl.h

这2个里面都也没有,文件里面又包含了。我们继续跟进。1 $:vim /usr/include/x86_64-linux-gnu/bits/fcntl-linux.h

这次我们找到了:1 /* Flags for SPLICE and VMSPLICE. */2 # define SPLICE_F_MOVE 1 /* Move pages instead of copying. */3 # define SPLICE_F_NONBLOCK 2 /* Don't block on the pipe splicing4 (but we may still block on the fd5 we splice from/to). */6 # define SPLICE_F_MORE 4 /* Expect more data. */7 # define SPLICE_F_GIFT 8 /* Pages passed in are a gift. */

4.现在我们根据这几个宏定义的上下文来查看跟_GNU_SOURCE宏的联系。

这4个宏包含在#ifdef __USE_GNU里面,我回头在看看features.h1 $:vim /usr/include/features.h

直接搜索__USE_GNU,发现里面有这个定义,跟_GNU_SOURCE关联。#ifdef _GNU_SOURCE# define __USE_GNU 1#endif

5.如果不注重里面的包含细节,直接用grep搜索,简单粗暴!!!$:grep -rn 'SPLICE_F' /usr/include/

转载请保留本文网址:http://www.shaoqun.com/a/174116.html

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:admin@shaoqun.com。

函数

0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值