Open64 (mfef90, whirl2f, and IR tools)
TAG: version-openad; SVN changeset: 916
|
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/uptr.c 92.1 06/18/99 18:38:26" 00039 00040 #include <string.h> 00041 #include <stdlib.h> 00042 #include <errno.h> 00043 #include <liberrno.h> 00044 #include <fortran.h> 00045 #include <unistd.h> 00046 #include <cray/assign.h> 00047 #include <sys/stat.h> 00048 #include "fio.h" 00049 00050 /* 00051 * _setuptr() - This routine is called by library routines that 00052 * do auxiliary types of i/o (e.g., aqio and waio). 00053 * It finds the appropriate entry in the unit table 00054 * corresponding to the file being opened and 00055 * initializes values in the unit table. 00056 * 00057 * returns: NULL on error (errno is set) 00058 * pointer into the unit table if successful. 00059 */ 00060 00061 unit * 00062 _setuptr( 00063 unum_t uid, /* unit number */ 00064 int rfd, /* real file descriptor */ 00065 char *uname, /* file name from open */ 00066 char *realname, /* file name after resolving aliases */ 00067 assign_info *aip) /* assign info, or NULL */ 00068 { 00069 register int private; 00070 unit *cup; 00071 00072 MEM_LOCK(&_openlock); 00073 00074 cup = _get_cup(uid); 00075 00076 if (cup != NULL) { /* Already open! */ 00077 errno = FEOPOTHR; 00078 goto error; 00079 } 00080 00081 #ifdef _CRAYMPP 00082 private = 1; /* private units are default on MPP */ 00083 #else 00084 private = 0; /* global units are default on other systems */ 00085 #endif 00086 if (aip != NULL && aip->P_ioscop_flg) 00087 private = (aip->P_ioscop == 'p'); 00088 00089 /* Allocate, initialize and lock unit */ 00090 00091 cup = _alloc_unit(uid, private); 00092 00093 if (cup == NULL) 00094 goto done; /* errno has error status */ 00095 00096 cup->usysfd = rfd; /* file descriptor */ 00097 _set_device_and_inode(rfd, &cup->udevice, &cup->uinode); 00098 00099 if (_uniqinod(cup, aip) == -1) 00100 goto error; 00101 /* 00102 * Set the "-m on" flag in the unit table entry. 00103 */ 00104 if (aip != NULL && aip->m_multup_flg && aip->m_multup) 00105 cup->umultup = 1; 00106 00107 cup->ufs = FS_AUX; 00108 /* 00109 * Allocate cup->ufnm and cup->alfnm strings. 00110 */ 00111 cup->ufnm = strdup(uname); 00112 00113 if (cup->ufnm == NULL) { 00114 errno = FENOMEMY; 00115 goto error; 00116 } 00117 00118 cup->alfnm = strdup(realname); 00119 00120 if (cup->alfnm == NULL) { 00121 free(cup->ufnm); 00122 cup->ufnm = NULL; 00123 errno = FENOMEMY; 00124 goto error; 00125 } 00126 00127 _release_cup(cup); 00128 00129 done: 00130 MEM_UNLOCK(&_openlock); 00131 return(cup); 00132 00133 error: 00134 if (cup != NULL) 00135 _release_cup(cup); 00136 00137 cup = NULL; 00138 goto done; 00139 } 00140 00141 /* 00142 * _clruptr(uptr) - clears a unit table entry 00143 * returns: -1 on error (errno is set) 00144 * 0 if ok 00145 */ 00146 00147 _clruptr(unit *cup) 00148 { 00149 00150 MEM_LOCK(&_openlock); 00151 /* 00152 * We should really pass the uid in to _clruptr, not the unit pointer. 00153 */ 00154 cup = _get_cup(cup->uid); /* lock the unit if it's open */ 00155 00156 if (cup == NULL) { 00157 MEM_UNLOCK(&_openlock); 00158 return(0); /* probably deep weeds */ 00159 } 00160 00161 if ( cup->ufs != FS_AUX ) { 00162 MEM_UNLOCK(&_openlock); 00163 _release_cup(cup); /* unlock the unit */ 00164 errno = FEINTUNK; 00165 return(-1); /* definitely deep weeds */ 00166 } 00167 00168 if ((cup->alfnm != cup->ufnm) && (cup->alfnm != NULL)) 00169 free(cup->alfnm); 00170 if (cup->ufnm != NULL) 00171 free(cup->ufnm); 00172 cup->ufs = 0; 00173 00174 _release_cup(cup); /* unlock the unit */ 00175 MEM_UNLOCK(&_openlock); 00176 00177 return(0); 00178 }