UNIX에서 system call을 이용한 파일 복사
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#define MAX_SIZE 1024
int main(void)
{
char buf[MAX_SIZE] = {0,};
char input_Name[MAX_SIZE] = {0,};
char output_Name[MAX_SIZE] = {0,};
int input_File, output_File;
int testnum;
write(1,"Input file name : ",sizeof("Input file name : "));
testnum = read(1,input_Name,sizeof(input_Name));
if(testnum < 0)
{
write(1,"Input error!!",sizeof("Input error!!"));
exit(1);
}
else
{
input_Name[testnum-1] = '\0';
}
write(1,"Output file name : ",sizeof("Output file name : "));
testnum = read(1,output_Name,sizeof(output_Name));
if(testnum < 0)
{
write(1,"Output error!!",sizeof("Input error!!"));
exit(1);
}
else
{
output_Name[testnum-1] = '\0';
}
input_File = open(input_Name , O_RDONLY);
if(input_File == -1)
{
write(1,"Input file open error!!\n", sizeof("Input file open error!!"));
exit(1);
}
output_File = open(output_Name ,O_EXCL | O_WRONLY | O_CREAT,0644);
if(input_File == -1)
{
write(1,"Output file open error!!\n", sizeof("Output file open error!!"));
exit(1);
}
while( read(input_File, buf, sizeof(buf)) )
{
write(output_File, buf, sizeof(buf));
}
close(output_File);
close(input_File);
return 0;
}
'Programming' 카테고리의 다른 글
[Security/BOF] [Level 3] cobolt -> goblin (0) | 2014.04.07 |
---|---|
[Security/BOF] [Level 2] gremlin -> cobolt (0) | 2014.04.06 |
[Security/ShellCode] shell code (0) | 2014.03.31 |
[Security/BOF] [Level 1] gate -> gremlin (0) | 2014.03.30 |
[Security/BOF] [펌]shell code(쉘 코드) 만드는법 (0) | 2014.03.30 |