LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 640|回复: 1

请教个程序:)

[复制链接]
发表于 2003-10-18 20:45:29 | 显示全部楼层 |阅读模式
老师让编一个程序:如果启用添加标志打开一文件以便读写能否用lseek在任意位置读?能否在任意部分更新数据,写程序验证。这是一段程序,可是我看不懂,帮我解释一下好吗?
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "ourhdr.h"
#define BUFFSIZE 1024

int
main(int argc, char **argv)
{
  int fd,n;
  char buf[BUFFSIZE];
  
  if (argc!=2)
    err_quit("usage: chapter3_6 testfile");
  if ((fd=open(argv[1],O_RDWR | O_APPEND))<0)
    err_sys("open error");
  if (lseek(fd,6,SEEK_SET)<0)
    err_sys("lseek error");
  if ((n=read(fd,buf,BUFFSIZE))<0)
    err_sys("read error");
  if (write(STDOUT_FILENO,buf,n)<0)
    err_sys("write to stdout error");
  if (lseek(fd,6,SEEK_SET)<0)
    err_sys("lseek2 error");
  if (write(fd,buf,n)<0)
    err_sys("write to testfile error");
  close(fd);
  exit(0);
}
发表于 2003-10-18 23:38:58 | 显示全部楼层
看man 吧

对每个函数看man 或是google

答案是不能
但是你 程序中使用到的那几个函数看man就好了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表