Section 8.2 - Read and Write

Question

Copy input to output by using read and write system calls.

/*copy input to output */

#include <sys/syscall.h>
#include <unistd.h>

#define BUFSIZ 1024

int main() /* copy input to output */
{
    char buf[BUFSIZ];
    int n;

    while ((n = read(0, buf, BUFSIZ)) > 0)
        write(1, buf, n);
    return 0;
}

Explanation

This uses the read and write system calls to copy input to output.