Skip to content

Instantly share code, notes, and snippets.

@halit
Created April 25, 2013 14:20
Show Gist options
  • Select an option

  • Save halit/5460067 to your computer and use it in GitHub Desktop.

Select an option

Save halit/5460067 to your computer and use it in GitHub Desktop.
My cat program with low level
/*
* =====================================================================================
*
* 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