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 #pragma ident "@(#) libf/pxf/pxfctermid.c 92.1 06/29/99 11:36:06" 00038 00039 00040 #include <errno.h> 00041 #include <liberrno.h> 00042 #include <fortran.h> 00043 #include <stdio.h> 00044 #include <string.h> 00045 00046 #define BLANK ((int) ' ') 00047 00048 /* 00049 * PXFCTERMID -- Gernerate Terminal Pathname 00050 * (section 4.7.1 of Posix 1003.9-1992) 00051 * 00052 * Synopsis: 00053 * 00054 * SUBROUTINE PXFCTERMID(S,ILEN,IERROR) 00055 * CHARACTER*(*) S 00056 * INTEGER ILEN,IERROR 00057 * 00058 * Function description: 00059 * 00060 * The routine PXFCTERMID uses ctermid() [(3S) on IRIX and Solaris 00061 * systems and (3C) on UNICOS systems] to generate a string which 00062 * is the pathname for the current process' controlling terminal. 00063 * If the pathname for the controlling terminal cannot be determined, 00064 * the ILEN variable is set to zero. 00065 * 00066 * Description of Arguments: 00067 * 00068 * S is an output character array or character element variable 00069 * for the pathname for the current process' controlling 00070 * terminal. 00071 * 00072 * ILEN is an output interger variable for the length of S. 00073 * 00074 * IERROR is an output integer variable for the completion status of 00075 * PXFCTERMID. IERROR may contain: 00076 * 00077 * zero - PXFCTERMID was successful. 00078 * 00079 * nonzero - PXFCTERMID was not successful. 00080 * 00081 * PXFCTERMID may return any of the following error 00082 * values: 00083 * 00084 * ETRUNC If the output variable S cannot contain the pathname 00085 * for the current process' controlling termina and so 00086 * the pathname was truncated. 00087 * 00088 * 00089 */ 00090 00091 #ifdef _UNICOS 00092 void 00093 PXFCTERMID( 00094 #else 00095 void 00096 _PXFCTERMID( 00097 #endif 00098 _fcd S, 00099 _f_int *ILEN, 00100 _f_int *IERROR 00101 ) 00102 { 00103 int sptrlen, slen, copylen; 00104 char *sptr; 00105 00106 slen = _fcdlen(S); 00107 *IERROR = 0; 00108 00109 if ((sptr = ctermid(NULL)) == NULL) { 00110 /* cannot determine controlling terminal for current process */ 00111 *ILEN = 0; 00112 } else { 00113 /* check for truncation error condition */ 00114 sptrlen = strlen(sptr); 00115 *ILEN = sptrlen; 00116 if (sptrlen > slen) { 00117 *IERROR = ETRUNC; 00118 copylen = slen; 00119 } else { 00120 copylen = sptrlen; 00121 } 00122 00123 /* copy the string */ 00124 (void)memcpy(_fcdtocp(S), sptr, copylen*sizeof(char)); 00125 (void)memset(_fcdtocp(S) + sizeof(char)*copylen, BLANK, 00126 (slen-copylen)*sizeof(char)); 00127 } 00128 } 00129 00130 #ifndef _UNICOS 00131 void 00132 pxfctermid_( 00133 char *S, 00134 _f_int *ILEN, 00135 _f_int *IERROR, 00136 _f_int slen 00137 ) 00138 { 00139 _PXFCTERMID(_cptofcd(S,slen), ILEN, IERROR); 00140 } 00141 #endif 00142 00143 00144
1.5.6