当前位置:网站首页>三种文件句柄之间的转换
三种文件句柄之间的转换
2022-06-21 23:52:00 【winux】
<- _fdopen <- <- _open_osfhandle
FILE* int fid OS HANDLE
-> _fileno -> -> _get_osfhandle
第一种FILE*是C语言里标准的文件指针。我们常说的stdin, stdout, stderr就是FILE*类型的
第二种是POSIX接口中的文件句柄。MSVC里提供的函数_open就返回这个句柄。(顺便提一句,Windows也是号称遵循POSIX标准的,虽然改的乱七八糟,毕竟还是有)。 其实stdin对应的句柄就是0, stdout是1,stderr是2。如果你windows帮助里查"重定向” 就能查到这几个数字。
第三中HANDLE是Windows 的API CreateFile返回的。
当然,最后前两种调用最后都会使用最后的CreateFile来打开文件,也就是在无论任何时候,OS HANDLE总是存在的。但是,使用HANDLE总是比使用前两种来的罗嗦,想一想Windows API那动辄十几的调用参数就够汗一把的。
为什么我们要在这几种句柄中间进行转换,我现在想到的原因有二:
1. 有些功能,比如获取文件的长度,没有对应的操作FILE*的函数能做的。函数POSIX函数_filelength就可以做到
2. 如果调用不同的函数库,不同的库可能要求的参数类型
边栏推荐
- Meetup03期回顾:Linkis新版本介绍以及DSS的应用实践
- 小小协议大威力,数字化转型为何缺不了NVMe全闪存?
- Have you stepped on the 8 most common SQL grammars at work?
- [2023 approval in advance] China Singapore SECCO
- Li Kou daily question - day 24 -485 Maximum number of consecutive 1
- Store API memo
- 企业可通过4个方法提高数据库安全
- 如何判断一个男人将来是穷还是富?
- 面试题目录收集
- How to judge pure IP? Where can I find it? Is it Expensive?
猜你喜欢

Go Technology Daily (June 20, 2022) -- go: simple optimization notes

Meetup03期回顾:Linkis新版本介绍以及DSS的应用实践

pytorch学习01:梯度下降实现简单线性回归

Transformation of DS and DXDY in surface integral of area
![[examination skills] memory method and simple derivation of Green formula](/img/26/f28a9f4abaca94988845b3fdaaf571.png)
[examination skills] memory method and simple derivation of Green formula

Lecture 3 of Data Engineering Series: characteristic engineering of data centric AI

0x00007ffff3d3ecd0 in Io Vfprintf Interne (S = 0x7ffff40b5620 < io 2 1 stdout >

唐太宗把微服务的“心跳机制”玩到了极致!

Query of the range of the cotolly tree chtolly tree old driver tree

导电滑环是如何工作的
随机推荐
前加后加探索和函数调用探索
You have a chance, here is a stage
HarmonyOS应用开发第二次作业笔记
SQL语句——数据更新、修改、删除
一文读懂LiveData 粘性事件
Simple analysis of three differences between cross-border trade and cross-border E-commerce
0x00007ffff3d3ecd0 in Io Vfprintf Interne (S = 0x7ffff40b5620 < io 2 1 stdout >
Meet webassembly again
eslint:错误
滴滴工程效能平台建设之路
pytorch学习05:索引和切片
How to gracefully count code time
记录一次小jsp的bug
目前主流的海外社交媒体有哪些?麻烦简单介绍一下?
Leetcode做题目录
纯净IP怎么判断?哪里有?贵吗?
Meetup03期回顾:Linkis新版本介绍以及DSS的应用实践
数字化转型的下一个目标:提供准时制信息
pytorch学习01:梯度下降实现简单线性回归
The next goal of digital transformation: providing just in time information