替换不同平台中的fpos_t和fpos_t._POS
replace fpos_t and fpos_t._pos in different platform
In Linux(ubuntu) fpos_t is in a struct
typedef fpos_t {
size_t _pos,
size_t _state
}
在 Windows 中,未定义fpos_t。在代码库中,它是以这种方式定义的。
#ifndef _FPOS_T_DEFINED
typedef __int64 fpos_t;
#define _FPOS_T_DEFINED
#endif /* _FPOS_T_DEFINED */
但是,在我的代码中
foo () {
fpos_t fsize;
fgetpos(fp, &fsize); // Function A
bar.len = (unsigned int)fsize; // for windows Function B
bar.body = (char *)SAFE_MALLOC( (size_t)fsize); // for windows
//bar.len = (unsigned int)fsize._pos; // for linux Function B
//bar.body = (char *)SAFE_MALLOC( (size_t)fsize._pos);// for linux
}
问题是,在不同平台上编译时,将fsize._pos替换为 fsize 的优雅方法是什么。我知道的方法
#if defined(LINUX)
//code for linux
#else
//code for windows
#endif
fpos_t
结构被定义为不透明;没有可移植的方法可以从fpos_t
中提取文件偏移量(将fpos_t转换为 int 或 char)。
如果要获取文件位置的字节偏移量,请在二进制模式下打开文件并使用ftello
(ftello/fseeko vs fgetpos/fsetpos)。
相关文章:
- "std::list::splice(std::const_iterator pos, std::list&& other)"是否保证将"其他"留空?
- 将卡诺地图简化器从 SOP 更改为 POS 结果
- QT 事件过滤器 mouseEvent->pos().x() 始终为零,但 mouseEvent->pos().y() 工作正常
- 尝试使用QNetworkAccessManager get()而不是QNetworkAccess Manager pos
- 我可以在 SDL 窗口外跟踪我的鼠标 pos 吗?
- 为什么字符串(常量字符* s,size_t pos,size_t len = npos)有效?
- 为什么 gl_FragCoord.z 与 ((pos.z / pos.w) + 1.0) * 0.5 不同?
- 获取使用 Qt c++ 在 Linux 中通过 USB 连接的 ESC/POS 打印机的状态
- “POS”未在此范围内声明
- 在 POS 打印机上打印条形码字体
- 变量'pos'正在使用未初始化
- 如何实现 std::map::查找包含两个结构'Pos'结构的比较逻辑,每个结构包含 x 和 y 坐标
- forward_list::splice_after( const_iterator pos, forward_list&other, const_iterator i ) 功能
- 提前钻头操纵,在任何POS中留下空位
- seekg 和 seekp :seek(streampos pos) 和 seek(streamoff off, ios
- C++子字符串POS
- 盈透证券C++ POS API 示例
- 单元测试框架-POS应用程序
- Delphi & C++ POS 与 DLL 的通信
- Qt TouchBegin touchPoint.pos() is stuck at 0,0