File Copy LowLevel

C & C++ 관련 : 2007. 3. 28. 21:18
반응형
01: #include<stdio.h>
02: #include<fcntl.h>
03: #include<sys/stat.h>
04: void main(int argc, char *argv[])
05: {
06:      int src, dest;
07:      int readnum;
08:      void *buf;
09: 
10:      src=open(argv[1],O_RDONLY);
11:      dest=open(argv[2],O_CREAT | O_WRONLY | O_TRUNC, S_IXUSR|S_IRUSR|S_IWUSR)  ;
12:      buf=malloc(sizeof(src));
13:      for (;;) {
14:           readnum=read(src,buf,sizeof(src));
15:           if (readnum == 0) {
16:               break;
17:           }
18:           write(dest,buf,readnum);
19:      }
20:      close(src);
21:      close(dest);
22:      free(buf);
23: }











반응형

'C & C++ 관련' 카테고리의 다른 글

realloc() 예제  (0) 2007.04.09
C++ file pointer 연습  (0) 2007.03.28
socket을 옳바르게 닫기  (0) 2007.03.26
Posted by Real_G