Annotation of coherent/d/usr/src/examples/fopen.c, revision 1.1.1.1

1.1       root        1: #include <stdio.h>
                      2: 
                      3: char buf[BUFSIZ];
                      4: void fatal();
                      5: 
                      6: main(argc, argv)
                      7: int argc; 
                      8: char *argv[];
                      9: {
                     10:        register FILE *ifp, *ofp;
                     11:        register unsigned int n;
                     12: 
                     13:        if (argc != 3)
                     14:                fatal("Usage: fopen source destination");
                     15:        if ((ifp = fopen(argv[1], "r")) == NULL)
                     16:                fatal("cannot open input file");
                     17:        if ((ofp = fopen(argv[2], "w")) == NULL)
                     18:                fatal("cannot open output file");
                     19: 
                     20:        while ((n = fread(buf, 1, BUFSIZ, ifp)) != 0) {
                     21:                if (fwrite(buf, 1, n, ofp) != n)
                     22:                        fatal("write error");
                     23:        }
                     24: 
                     25:        if (!feof(ifp))
                     26:                fatal("read error");
                     27:        if (fclose(ifp) == EOF || fclose(ofp) == EOF)
                     28:                fatal("cannot close");
                     29: 
                     30:        exit(0);
                     31: }
                     32: 
                     33: void fatal(message)
                     34: char *message;
                     35: {
                     36:        fprintf(stderr, "fatal: %s\n", message);
                     37:        exit(1);
                     38: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.