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