Annotation of GNUtools/libg++/libio/iofdopen.c, revision 1.1

1.1     ! root        1: /* 
        !             2: Copyright (C) 1993 Free Software Foundation
        !             3: 
        !             4: This file is part of the GNU IO Library.  This library is free
        !             5: software; you can redistribute it and/or modify it under the
        !             6: terms of the GNU General Public License as published by the
        !             7: Free Software Foundation; either version 2, or (at your option)
        !             8: any later version.
        !             9: 
        !            10: This library is distributed in the hope that it will be useful,
        !            11: but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            12: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        !            13: GNU General Public License for more details.
        !            14: 
        !            15: You should have received a copy of the GNU General Public License
        !            16: along with GNU CC; see the file COPYING.  If not, write to
        !            17: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
        !            18: 
        !            19: As a special exception, if you link this library with files
        !            20: compiled with a GNU compiler to produce an executable, this does not cause
        !            21: the resulting executable to be covered by the GNU General Public License.
        !            22: This exception does not however invalidate any other reasons why
        !            23: the executable file might be covered by the GNU General Public License. */
        !            24: 
        !            25: #include "libioP.h"
        !            26: 
        !            27: _IO_FILE *
        !            28: _IO_fdopen (fd, mode)
        !            29:      int fd;
        !            30:      const char *mode;
        !            31: {
        !            32:   int read_write;
        !            33:   struct _IO_FILE_plus *fp;
        !            34: 
        !            35:   switch (*mode++)
        !            36:     {
        !            37:     case 'r':
        !            38:       read_write = _IO_NO_WRITES;
        !            39:       break;
        !            40:     case 'w':
        !            41:       read_write = _IO_NO_READS;
        !            42:       break;
        !            43:     case 'a':
        !            44:       read_write = _IO_NO_READS|_IO_IS_APPENDING;
        !            45:       break;
        !            46:     default:
        !            47: #ifdef EINVAL
        !            48:       errno = EINVAL;
        !            49: #endif
        !            50:       return NULL;
        !            51:   }
        !            52:   if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+'))
        !            53:     read_write &= _IO_IS_APPENDING;
        !            54: 
        !            55:   fp = (struct _IO_FILE_plus*)malloc(sizeof(struct _IO_FILE_plus));
        !            56:   if (fp == NULL)
        !            57:     return NULL;
        !            58:   _IO_init(&fp->_file, 0);
        !            59:   fp->_file._jumps = &_IO_file_jumps;
        !            60:   _IO_file_init(&fp->_file);
        !            61:   fp->_vtable = NULL;
        !            62:   if (_IO_file_attach(&fp->_file, fd) == NULL)
        !            63:     {
        !            64:       _IO_un_link(&fp->_file);
        !            65:       free (fp);
        !            66:       return NULL;
        !            67:     }
        !            68:   fp->_file._flags &= ~_IO_DELETE_DONT_CLOSE;
        !            69: 
        !            70:   fp->_file._IO_file_flags = 
        !            71:     _IO_mask_flags(&fp->_file, read_write,
        !            72:                   _IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING);
        !            73: 
        !            74:   return (_IO_FILE*)fp;
        !            75: }

unix.superglobalmegacorp.com

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