[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

setmode vs. fdopen



After reading the SUN manual pages, I would say that 'fdopen' is a better
method to handle the problem:

FOPEN(3V)              C LIBRARY FUNCTIONS              FOPEN(3V)

NAME
     fopen, freopen, fdopen - open a stream

SYNOPSIS
     #include <stdio.h>

     FILE *fopen(filename, type)
     char *filename, *type;

     FILE *freopen(filename, type, stream)
     char *filename, *type;
     FILE *stream;

     FILE *fdopen(fd, type)
     int fd;
     char *type;

DESCRIPTION
     fopen() opens the file named by filename  and  associates  a
     stream  with  it.   If  the open succeeds, fopen() returns a
     pointer to be used to  identify  the  stream  in  subsequent
     operations.

     filename points to a character string that contains the name
     of the file to be opened.

     type is a character  string  having  one  of  the  following
     values:

          r         open for reading

          w         truncate or create for writing

          a         append: open for writing at end of  file,  or
                    create for writing

          r+        open for update (reading and writing)

          w+        truncate or create for update

          a+        append; open or create for update at EOF

     freopen() opens the file named by  filename  and  associates
     the  stream pointed to by stream with it.  The type argument
     is used just as in fopen.  The original  stream  is  closed,
     regardless  of whether the open ultimately succeeds.  If the
     open succeeds,  freopen()  returns  the  original  value  of
     stream.

     freopen() is typically used to attach the preopened  streams
     associated with stdin, stdout, and stderr to other files.
     fdopen() associates a stream with the  file  descriptor  fd.
     File  descriptors  are  obtained  from  calls like open(2V),
     dup(2V), creat(2V), or pipe(2V), which open files but do not
     return streams.  Streams are necessary input for many of the
     Section 3S library routines.  The type of  the  stream  must
     agree with the access permissions of the open file.


...and so on...

-- 
________________ cut here _________________________
Julian F. Reschke, Hensenstr. 142, D-W4400 Muenster
  eMail: julian@math.uni-muenster.de, jr@ms.maus.de
________ correct me if I'm wrong __________________