File:  [MW Coherent from dump] / coherent / a / usr / man / MULTI / fdopen
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:34 2019 UTC (7 years ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent



fdopen()                  STDIO Function                 fdopen()




Open a stream for standard I/O

#iinncclluuddee <ssttddiioo.hh>
FFIILLEE *ffddooppeenn(_f_d, _t_y_p_e) iinntt _f_d; cchhaarr *_t_y_p_e;

ffddooppeenn allocates and returns a FFIILLEE structure, or stream, for the
file descriptor  fd, as obtained from open,  creat, dduupp, or ppiippee.
type is the manner in which you want fd to be opened, as follows:


             rr       Read a file
             ww       Write into a file
             aa       Append onto a file


***** Example *****

The following  example obtains a  file descriptor with  open, and
then uses ffddooppeenn to build a pointer to the FFIILLEE structure.


#include <ctype.h>
#include <stdio.h>



void adios(message)
char *message;
{
        fprintf(stderr, "%s\n", message);
        exit(1);
}



main(argc, argv)
int argc; char *argv[];
{
        extern FILE *fdopen();
        FILE *fp;
        int fd;
        int holder;



        if (--argc != 1)
                adios("Usage: example filename");









COHERENT Lexicon                                           Page 1




fdopen()                  STDIO Function                 fdopen()



        if ((fd = open(argv[1], 0)) == -1)
                adios("open failed.");
        if ((fp = fdopen(fd, "r")) == NULL)
                adios("fdopen failed.");



        while ((holder = fgetc(fp)) != EOF) {
                if ((holder > '\177') && (holder < ' '))
                        switch(holder) {
                        case '\t':
                        case '\n':
                                break;
                        default:
                                fprintf(stderr, "Seeing char %d\n", holder);
                                exit(1);
                        }
                fputc(holder, stdout);
        }
}


***** See Also *****

creat(), dup(), fopen(), open(), STDIO

***** Diagnostics *****

fdopen returns NULL if it cannot allocate a FFIILLEE structure.  Cur-
rently, only 20 FFIILLEE structures can be allocated per program, in-
cluding ssttddiinn, ssttddoouutt, and ssttddeerrrr.


























COHERENT Lexicon                                           Page 2



unix.superglobalmegacorp.com

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