Section 8.2 - Read and Write

Question

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

/*copy input to output */

#include <unistd.h>
#include <sys/syscall.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;

}
Run this

Explanation

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

Comments by Disqus