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/pxfchroot.c 92.1 06/29/99 11:36:06" 00038 #include <errno.h> 00039 #include <fortran.h> 00040 #include <liberrno.h> 00041 #include <malloc.h> 00042 #include <string.h> 00043 #include <unistd.h> 00044 00045 extern char *_fc_acopy(_fcd f); 00046 00047 /* 00048 * PXFCHROOT Change the root directory to the 00049 * specified directory. 00050 * 00051 * Call from Fortran: 00052 * 00053 * SUBROUTINE PXFCHROOT (PATH, ILEN, IERROR) 00054 * CHARACTER * (*) PATH 00055 * INTEGER ILEN, IERROR 00056 * 00057 * Where: 00058 * 00059 * PATH is an input character variable or array element 00060 * containing the name of the new directory. 00061 * 00062 * ILEN is an input integer variable containing the length 00063 * of PATH in characters. If ILEN is zero, all 00064 * trailing blanks are removed before calling chroot(). 00065 * 00066 * IERROR is an output integer variable that will contain the 00067 * status: 00068 * 00069 * Zero if PXFCHROOT is successful; otherwise nonzero. 00070 * 00071 * In addition to the errors returned by the chroot(2) 00072 * system call, PXFCHROOT may return the following errors: 00073 * 00074 * EINVAL If ILEN < 0 or ILEN > LEN(PATH) 00075 * 00076 * ENOMEM If PXFCHROOT is unable to obtain memory to 00077 * copy PATH. 00078 */ 00079 00080 #ifdef _UNICOS 00081 void 00082 PXFCHROOT( 00083 #else 00084 void 00085 _PXFCHROOT( 00086 #endif 00087 _fcd PATH, /* Character variable containing path */ 00088 /* of new directory */ 00089 _f_int *ILEN, /* Length of pathname */ 00090 _f_int *IERROR) /* Error Status */ 00091 { 00092 _f_int arglen, errsts, length; 00093 char *argstr, *pthstr; 00094 errsts = 0; 00095 argstr = _fcdtocp(PATH); 00096 arglen = (_f_int) _fcdlen (PATH); 00097 length = *ILEN; 00098 if (length < 0 || length > arglen) 00099 errsts = EINVAL; 00100 else { 00101 /* 00102 * If length is zero, strip trailing blanks. Otherwise, 00103 * malloc memory and copy the string; adding a NULL 00104 * terminator. 00105 */ 00106 if (length == 0) 00107 pthstr = _fc_acopy(PATH); 00108 else 00109 pthstr = (char *) malloc(length + 1); 00110 if (pthstr == NULL) /* If no memory allocated */ 00111 errsts = ENOMEM; 00112 else { 00113 if (length != 0) { /* Copy argument */ 00114 (void) memcpy(pthstr, argstr, length); 00115 pthstr[length] = '\0'; 00116 } 00117 /* Change directories through chdir() to path. */ 00118 if (chroot(pthstr) == -1) 00119 errsts = errno; 00120 free(pthstr); 00121 } 00122 } 00123 *IERROR = errsts; 00124 return; 00125 } 00126 00127 00128 00129 #ifndef _UNICOS 00130 void 00131 pxfchroot_( 00132 char *PATH, /* Character variable containing path */ 00133 /* of new directory */ 00134 _f_int *ILEN, /* Length of pathname */ 00135 _f_int *IERROR, /* Error Status */ 00136 _f_int pathlen) 00137 { 00138 _PXFCHROOT(_cptofcd(PATH, pathlen), ILEN, IERROR); 00139 } 00140 #endif
1.5.6