- 论坛徽章:
- 0
|
- /*
- gcc -o 1 1.c by wzt
- */
- #include <stdio.h>
- #include <string.h>
- #include <unistd.h>
- #include <fcntl.h>
- #define BUFF 1024
- void usage(char *pro)
- {
- printf("usage:%s <file1> <file2>\n",pro);
- exit(0);
- }
- int modify_data(int fd1,int fd2)
- {
- char line[BUFF];
- int pos,i,len;
- while ( (len = read(fd1,line,BUFF)) > 0 ) {
- pos = strlen(line);
- for ( i = 0; i < pos; i++ ) {
- if ( line[i] == ' ' )
- line[i] = '\n';
- }
- printf("%s",line);
- write(fd2,line,len);
- }
- }
- int main(int argc,char **argv)
- {
- int fd1,fd2;
- if ( argc == 1 ) usage(argv[0]);
- if ( (fd1 = open(argv[1],O_RDONLY)) == -1 ) {
- printf("can't open %s.\n",argv[1]);
- exit(0);
- }
- if ( (fd2 = creat(argv[2],0777)) == -1 ) {
- printf("can't open %s.\n",argv[2]);
- exit(0);
- }
- modify_data(fd1,fd2);
- printf("[+] done.\n");
- close(fd1);
- close(fd2);
- return 0;
- }
复制代码 |
|