Created
April 25, 2013 14:20
-
-
Save halit/5460067 to your computer and use it in GitHub Desktop.
My cat program with low level
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * ===================================================================================== | |
| * | |
| * Filename: cat2.c | |
| * | |
| * Description: My cat program with low level | |
| * | |
| * Version: 1.0 | |
| * Created: 25-04-2013 17:01:46 | |
| * Compiler: gcc | |
| * | |
| * Author: Halit Alptekin, info@halitalptekin.com | |
| * | |
| * ===================================================================================== | |
| */ | |
| #include <syscall.h> | |
| #include <unistd.h> | |
| #include <stdio.h> | |
| #include <fcntl.h> | |
| void error(char *fmt, ...); | |
| int main(int argc, char *argv[]) | |
| { | |
| int fd; | |
| char *fname = argv[0]; | |
| void copyFile(int, int); | |
| if(argc == 1){ | |
| copyFile(0, 1); | |
| }else{ | |
| while(--argc > 1){ | |
| if((fd = open(*++argv, O_RDONLY)) == -1){ | |
| error("%s: dosya acilamadi %s\n", fname, *argv); | |
| }else{ | |
| copyFile(fd, 1); | |
| close(fd); | |
| } | |
| } | |
| } | |
| return 0; | |
| } | |
| void copyFile(int ifd, int ofd){ | |
| int n; | |
| char buffer[BUFSIZ]; | |
| while((n = read(ifd, buffer, BUFSIZ)) > 0) | |
| if(write(ofd, buffer, n) != n) | |
| error("yazma hatasi\n"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment