在windows下面用open操作文件描述符,该怎么处理

如题所述

第1个回答  推荐于2016-10-25
如果你在windows下用gcc,
这里有个范例.

1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6
7
8 #define BSIZE 200
9 int main(int argc, char *argv[])
10 {
11 int fp, rsize ;
12 char buf[BSIZE] ;
13
14 if ( access(argv[1], F_OK) !=0) {
15 printf( "file not exists\n ");
16 exit(1) ;
17 }
18
19 fp = open(argv[1], O_RDONLY) ;
20 while ((rsize =read(fp, buf, BSIZE)) > 0) {
21 write(fileno(stdout), buf, rsize) ;
22 }
23
24
25 close(fp) ;
26 exit(0) ;
27 }本回答被提问者和网友采纳
相似回答