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/pxfgetcwd.c 92.1 06/29/99 11:36:06" 00038 00039 00040 #include <errno.h> 00041 #include <fortran.h> 00042 #include <liberrno.h> 00043 #include <string.h> 00044 #include <unistd.h> 00045 #include <sys/param.h> 00046 00047 #ifndef _UNICOS 00048 #include <stddef.h> 00049 #endif 00050 00051 #define BLANK ((int) ' ') 00052 00053 /* 00054 * PXFGETCWD -- get working directory pathname 00055 * (section 5.2.2 of Posix 1003.9-1992) 00056 * 00057 * Call from Fortran: 00058 * 00059 * SUBROUTINE PXFGETCWD(BUF, ILEN, IERROR) 00060 * CHARACTER*(*) BUF 00061 * INTEGER ILEN, IERROR 00062 * 00063 * Where: 00064 * 00065 * BUF is an output character variable or array element 00066 * for the current working directory. The longest 00067 * pathname will cannot be longer than PATH_MAX for 00068 * Unicos or MAXPATHLEN for Solaris and IRIX as 00069 * defined in <sys/param.h>. 00070 * 00071 * ILEN is an output integer variable containing the 00072 * character length of BUF. 00073 * 00074 * IERROR is an output integer variable that will contain 00075 * the status: 00076 * 00077 * zero - the working directory path was 00078 * successfully copied into BUF. 00079 * 00080 * nonzero - PXFGETCWD was not successful. 00081 * 00082 * PXFGETCWD may return any of the following error 00083 * values: 00084 * 00085 * ETRUNC If the length of BUF is less than the 00086 * complete path length. 00087 * 00088 * EACCESS If read or search permission for any 00089 * component of the current working directory 00090 * path was denied. 00091 * 00092 * 00093 */ 00094 00095 #ifdef _UNICOS 00096 void 00097 PXFGETCWD( 00098 #else 00099 void 00100 _PXFGETCWD( 00101 #endif 00102 _fcd BUF, /* buffer for full path */ 00103 _f_int *ILEN, /* buffer length in characters */ 00104 _f_int *IERROR /* error status */ 00105 ) 00106 { 00107 int bufsize, /* size of the fortran string */ 00108 pathlen, /* lenth of the current working directory path */ 00109 movelen, /* number of characters to copy from pathbuf to 00110 * user variable */ 00111 #ifdef _UNICOS 00112 pathbufsize = PATH_MAX+1; 00113 char pathbuf[PATH_MAX+1]; 00114 #else 00115 pathbufsize = MAXPATHLEN; 00116 char pathbuf[MAXPATHLEN]; 00117 #endif 00118 char *bufptr; 00119 00120 *IERROR = 0; 00121 bufsize = _fcdlen(BUF); 00122 bufptr = _fcdtocp(BUF); 00123 00124 if (getcwd(pathbuf, pathbufsize) == NULL) { 00125 *IERROR = errno; 00126 } else { 00127 00128 /* If path length for current working directory is larger 00129 * than user variable BUF's size, the path must be 00130 * truncated. 00131 */ 00132 00133 pathlen = strlen(pathbuf); 00134 *ILEN = pathlen; 00135 if (pathlen > bufsize) { 00136 *IERROR = ETRUNC; 00137 movelen = bufsize; 00138 } else { 00139 movelen = pathlen; 00140 } 00141 00142 /* copy argument to user variable */ 00143 00144 if (movelen > 0) { 00145 (void) memcpy(bufptr, pathbuf, movelen); 00146 } 00147 00148 00149 /* blank-fill user variable BUF */ 00150 if (bufsize > movelen) { 00151 (void) memset(bufptr + sizeof(char)*movelen, BLANK, 00152 bufsize - movelen); 00153 } 00154 00155 } 00156 } 00157 00158 00159 #ifndef _UNICOS 00160 void 00161 pxfgetcwd_( 00162 char *BUF, 00163 _f_int *ILEN, 00164 _f_int *IERROR, 00165 _f_int buflen) 00166 { 00167 _PXFGETCWD(_cptofcd(BUF, buflen), ILEN, IERROR); 00168 } 00169 00170 #endif
1.5.6