Win平台,文件句柄类型的相互转换

Win平台,文件句柄类型的相互转换

已知:

CreateFile返回的是HANDLE,

fopen返回的是FILE *,

_open返回的是个int,

 

转换:

1、FILE * => int

Gets the file descriptor associated with a stream.

int _fileno( 
   FILE *stream 
);
 
2、int => HANDLE

Returns operating-system file handle associated with existing low-level file descriptor.

long _get_osfhandle( 
   int fd 
);
 
3、HANDLE => int

Associates a C run-time file descriptor with an existing operating-system file handle.

int _open_osfhandle (
   intptr_t osfhandle,
      int flags 
);
 
4、FILE * => int
应该就是FILE结构中的_file字段。

你可能感兴趣的:(Win平台,文件句柄类型的相互转换)