All pastes #481940 Raw Edit

Someone

public text v1 · immutable
·published 2007-05-11 02:14 UTC
rendered paste body
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void usage(char *name) {
        fprintf(stderr, "usage: %s <filename>\n", name);
        exit(1);
}

int main(int argc, char **argv) {
        FILE *p;
        char bof[1024];
        if (argc < 2) usage( argv[0] );
        if ( access(argv[1], R_OK) != 0 ) {
                fprintf(stderr, "You do not have read access.\n");
                exit(1);
        }

        p = fopen(argv[1], "r");
        if ( p == NULL ) {
                fprintf(stderr, "Error opening file\n");
                exit(1);
        }
        while ( !feof(p) ) {
                memset(bof, 0, 1024);
                fgets(bof, 1023, p);
                printf("%s", bof);
        }
        return 0;
}