文件操作举例 / Open the input file and create the output file * in_ fd= open(argv[1],ORDONLY): / open the source file * if (in_fd 0)exit(2): if it cannot be opened, exit * out_ fd=creat(argv[2], OUTPUT_ MODE); /* create the destination file * if (out_fd O)exit (3); / if it cannot be created. exit * / Copy loop * while(TRUE)I rd- count= read(in_fd, buffer, BUF SIZE); * read a block of data * if (rd_count <= 0)break / if end of file or error, exit loop * wt_count= write(out_fd, buffer, rd_ count); / write data * if (wt_count < O)exit(4); /* wt count <=0 is an error * /* Close the files * close(in_ fd) close(out fd); if(rd_count = 0) /* no error on last read exit(O) else 2002 exit(5 / error on last read * 10 东北2002-7-5 东北大学软件所 于戈 第五章 分布式文件管理 10 文件操作举例