Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ freopen(3C) — DG/UX 4.00

Media Vault

Software Library

Restoration Projects

Artifacts Sought



                                                              freopen(3C)



        _________________________________________________________________
        freopen                                                  function
        Close a stream and reopen a file or device.
        _________________________________________________________________


        Calling Sequence

        #include <stdio.h>
        FILE *oldfile, *freopen();
        char *newfile, *type;
        freopen(newfile, type, oldfile);


        where
             newfile is a byte pointer to the new pathname.

             oldfile is a pointer to the FILE stream of the currently
             open file.

             type is a byte pointer to a string specifying the standard
             opening types, all of which are UNIX compatible:

           a     Open for appending only.
           a+    Open for appending (read and write).
           r     Open for reading only.
           r+    Open for read/write access.  Return an error if the
                 file does not exist.
           w     Delete, re-create, and open for writing only.
           w+    Delete, re-create, and open a file for read/write
                 access.



        Description

        Use the freopen function to close a FILE stream and reopen a file
        or device. As long as your file is a disk file, you need not take
        any special action to alternate between reading and writing; the
        I/O routines correctly switch from one mode to the other.  If
        your program will run under other C compilers, or if your file is
        not a disk file, you may have to use an fseek(stream, 0L, 1) when
        switching I/O types.


        Returns

        The function returns a null if an opening error occurs.
        Otherwise, it returns the pointer oldfile.





        DG/UX 4.00                                                 Page 1
               Licensed material--property of copyright holder(s)





                                                              freopen(3C)



        Related Functions

        See also the fclose, fdopen, and fopen functions.


        Example

        /* Program test for the freopen() function */

        #include <stdio.h>

        FILE   *fp, *fopen(), *freopen();
        int     i = 1;

        main(argc, argv)
        int     argc;
        char    *argv[];
        {
            fp = fopen(argv[i], "r");
            putchar(fgetc(fp));

            while (i+1 < argc) {
                fp = freopen(argv[i+1], "r", fp);
                putchar(fgetc(fp));
                i++;
            }
        }

        Calling the program test with the valid filenames filea, fileb,
        filec, filed, and filee, which contain abcd, bbbb, cdef, dcba,
        and eeee respectively, generates the output

        abcde





















        DG/UX 4.00                                                 Page 2
               Licensed material--property of copyright holder(s)



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026