---

来源:互联网 发布:oracle需要使用的端口 编辑:程序博客网 时间:2024/04/30 13:00
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
int main()
{
int fd = 0;
char buf[32] = {'\0'};
int ret = 0;

ret = access("msg.txt", F_OK);
printf("%d\n",ret);
if (ret == 0)               
{
printf("file exist\n");
fd = open("msg.txt", O_WRONLY); 
if (fd < 0)
{
perror("open file error");
return 1;
}
while(1)
{
memset(buf, '\0', sizeof(buf));
ret = read(fd, buf, sizeof(buf) - 1);
if (ret < 0)
{
perror("read file error");
return 1;
}
if (ret == 0)
{
break;
}
printf("%s",buf);
}
}
else
{

}

close(fd);
return 1;
}










/*  




int ts = tcsetattr(fd,TCSNOW,termios* _termios_p _termios_p);
struct termios 
newattr.c_cflag &=~ CSIZE;
newattr.c_cflag 1= CS8;
necattr.c_cflag &= ~CSTOPB;//1位停止位
newattr.c_cflag &=~ PARENB;// 无校验


*/















0 0
原创粉丝点击