Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
initunit.c
Go to the documentation of this file.
00001 /*
00002 
00003   Copyright (C) 2000, 2001, Silicon Graphics, Inc.  All Rights Reserved.
00004 
00005   This program is free software; you can redistribute it and/or modify it
00006   under the terms of version 2.1 of the GNU Lesser General Public License 
00007   as published by the Free Software Foundation.
00008 
00009   This program is distributed in the hope that it would be useful, but
00010   WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013   Further, this software is distributed without any warranty that it is
00014   free of the rightful claim of any third person regarding infringement 
00015   or the like.  Any license provided herein, whether implied or 
00016   otherwise, applies only to this software file.  Patent licenses, if
00017   any, provided herein do not apply to combinations of this program with 
00018   other software, or any other product whatsoever.  
00019 
00020   You should have received a copy of the GNU Lesser General Public 
00021   License along with this program; if not, write the Free Software 
00022   Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, 
00023   USA.
00024 
00025   Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pky,
00026   Mountain View, CA 94043, or:
00027 
00028   http://www.sgi.com
00029 
00030   For further information regarding this notice, see:
00031 
00032   http://oss.sgi.com/projects/GenInfo/NoticeExplan
00033 
00034 */
00035 
00036 
00037 
00038 #pragma ident "@(#) libf/fio/initunit.c 92.1    06/22/99 11:11:33"
00039 #include "fio.h"
00040 #include <string.h>
00041 #include <stddef.h>
00042 #include <stdlib.h>
00043 
00044 /*
00045  *      If the macro DEBUG_MTIO is set, then this hard reference to TSKSTART
00046  *      will cause linking in of multitasking locking code even when the
00047  *      program is not multitasked.   This causes the library locking and 
00048  *      unlocking to be activated for increased exercise/test coverage of the 
00049  *      library locking paths.
00050  *
00051  *      The reference to TSKSTART is placed in this module because this 
00052  *      module is guaranteed to be loaded when any Fortran I/O routines
00053  *      are loaded. 
00054  */
00055 #if     defined(DEBUG_MTIO) && defined(_CRAY1)
00056 extern int TSKSTART();
00057 int _debug_mtio = (int)TSKSTART;
00058 #endif
00059 
00060 /*
00061  *      _init_unit
00062  *
00063  *              Sets default unit table values.  This routine should be called 
00064  *              some time before every unit open.  Any freeing of memory 
00065  *              pointed to by a unit table entry should be freed at close 
00066  *              time, not in this routine.
00067  */
00068 void
00069 _init_unit(unit *cup)
00070 {
00071         /*
00072          * Clear the unit table, except for the leading few fields.  The
00073          * leading fields are initialized once when allocating new units in a 
00074          * hash chain or are used for locking.
00075          */
00076 
00077         (void) memset ((char*)cup + UNIT_HEADER, 0, sizeof(unit) - UNIT_HEADER);
00078 
00079         /*
00080          * Now, set parameterized or nonzero fields
00081          */
00082 
00083         cup->ufs        = FS_DEFAULT;   /* File structure */
00084         cup->unitchk    = 1;            /* Unit was checked */
00085         cup->utrunc     = 1;            /* Truncation after write is default */
00086         cup->usysfd     = -1;           /* Default no associated system file */
00087 
00088         return;
00089 }
00090 
00091 /*
00092  *      _init_internal_unit 
00093  *
00094  *              Is called by the first call to _get_int_cup() to set up the 
00095  *              unit structure used by internal file I/O.
00096  */
00097 unit *
00098 _init_internal_unit(void)
00099 {
00100         unit            *cup;
00101 /*
00102  *      Lock _openlock to ensure that _fort_internal_unit is allocated only 
00103  *      once.
00104  */
00105         OPENLOCK();
00106 
00107         if (! _i_fortran_io_is_init)
00108                 _initialize_i_fortran_io();
00109 
00110         if (_fort_internal_unit == NULL) {
00111                 cup = malloc(sizeof(unit));
00112                 if (cup == NULL) {
00113                         OPENUNLOCK();
00114                         _lerror(_LELVL_ABORT, FENOMEMY);
00115                 }
00116 
00117                 cup->hashlink   = NULL;         /* not used */
00118                 cup->uid        = -1;           /* not used */
00119                 INITIALIZE_LOCK(cup->uiolock);
00120 
00121                 _init_unit(cup);
00122 
00123                 cup->ufmt       = 1;            /* FORM='FORMATTED'     */
00124                 cup->useq       = 1;            /* ACCESS='SEQUENTIAL'  */
00125                 cup->ublnk      = 0;            /* BLANK='NULL'         */
00126                 cup->upad       = OS_YES;       /* PAD='YES'            */
00127                 cup->udelim     = OS_NONE;      /* DELIM='NONE'         */
00128                 cup->uaction    = OS_READWRITE; /* ACTION='READWRITE'   */
00129 
00130                 _set_ok_flags(cup);             /* set up the cup->ok_* flags */
00131 
00132                 /*
00133                  * Ensure that the previous memory stores complete before any 
00134                  * other task uses the internal unit.
00135                  */
00136                 FLSH_MEM();
00137 
00138                 _fort_internal_unit = cup; 
00139         }
00140 
00141         OPENUNLOCK();
00142 
00143         return(_fort_internal_unit);
00144 }
00145 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines