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