Skip to content

Instantly share code, notes, and snippets.

@micahalles
Created October 3, 2015 01:53
Show Gist options
  • Save micahalles/ca51a88abbfdbcd4a9d3 to your computer and use it in GitHub Desktop.
Save micahalles/ca51a88abbfdbcd4a9d3 to your computer and use it in GitHub Desktop.
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
int fdin, fdout, retval;
char buf[2048];
ssize_t nread, nwrote;
fdin = open("readfile", O_RDONLY);
fdout = open("writefile", O_CREAT | O_WRONLY, 0644);
nread = read(fdin, buf, 2048);
nwrote = write(fdout, buf, (size_t)nread);
retval = close(fdin);
retval = close(fdout);
// (calls can fail!!, read man pages and /usr/include/fcntl.h, also think
// of copying a file larger than 2048 bytes - try buffer at a time till done!)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment