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/pxfutime.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 <sys/types.h> 00045 #include <utime.h> 00046 #include "pxfstruct.h" 00047 #include "table.h" 00048 00049 #ifndef _UNICOS 00050 #include <stddef.h> 00051 #endif 00052 00053 extern char *_fc_acopy(_fcd f); 00054 00055 /* 00056 * PXFUTIME Sets access and modification times of a file 00057 * 00058 * From section 5.6.6.1 of Posix 1003.9 00059 * 00060 * Call from Fortran: 00061 * 00062 * SUBROUTINE PXFUTIME (PATH, ILEN, JUTIMBUF, IERROR) 00063 * CHARACTER * (*) PATH 00064 * INTEGER ILEN, JUTIMBUF, IERROR 00065 * 00066 * Where: 00067 * 00068 * PATH is an input character variable or array element 00069 * containing the name of the file. 00070 * 00071 * ILEN is an input integer variable containing the length 00072 * of PATH in characters. If ILEN is zero, any and 00073 * all trailing blanks are removed. 00074 * 00075 * JUTIMBUF is an input integer variable. It is a handle 00076 * for a structure of type utimbuf 00077 * 00078 * IERROR is an output integer variable that will contain the 00079 * status: Zero if PXFUTIME is successful; otherwise 00080 * nonzero. 00081 * 00082 * In addition to the error statuses returned by the 00083 * utime(2) system call, PXFUTIME may return the 00084 * following error statuses: 00085 * 00086 * EINVAL If ILEN < 0 or ILEN > LEN(PATH) 00087 * 00088 * ENOMEM If PXFUTIME is unable to obtain memory to 00089 * copy PATH. 00090 * 00091 * EBADHANDLE If JUTIMBUF is invalid. 00092 */ 00093 00094 #ifdef _UNICOS 00095 void 00096 PXFUTIME( 00097 #else 00098 void 00099 _PXFUTIME( 00100 #endif 00101 _fcd PATH, /* Character variable containing argument */ 00102 _f_int *ILEN, /* Significant length of argument */ 00103 _f_int *JUTIMBUF, /* handle for struct utimbuf */ 00104 _f_int *IERROR /* Error status */ 00105 ) 00106 { 00107 int arglen, errsts, length; 00108 char *argstr, *pthstr; 00109 struct utimbuf *times; 00110 struct pxfhandle pxfhand; 00111 00112 errsts = 0; 00113 argstr = _fcdtocp(PATH); 00114 arglen = _fcdlen (PATH); 00115 length = *ILEN; 00116 00117 if (*JUTIMBUF == 0) { 00118 pxfhand.pxfstructptr = NULL; 00119 } else { 00120 pxfhand = _pxfhandle_table_lookup(&_pxfhandle_table, *JUTIMBUF); 00121 if (pxfhand.pxfstructptr == NULL || pxfhand.pxftype != PXF_UTIMBUF) { 00122 *IERROR = EBADHANDLE; 00123 return; 00124 } 00125 } 00126 00127 if (length < 0 || length > arglen) 00128 errsts = EINVAL; 00129 else { 00130 00131 /* 00132 * If length is zero, user wants trailing blanks stripped. 00133 * Otherwise, malloc memory and copy the string; adding a 00134 * NULL terminator. 00135 */ 00136 00137 if (length == 0) 00138 pthstr = _fc_acopy(PATH); 00139 else 00140 pthstr = (char *) malloc(length + 1); 00141 00142 if (pthstr == NULL) /* If no memory allocated */ 00143 errsts = ENOMEM; 00144 else { 00145 00146 if (length != 0) { /* Copy argument */ 00147 (void) memcpy(pthstr, argstr, length); 00148 pthstr[length] = '\0'; 00149 } 00150 00151 times = pxfhand.pxfstructptr; 00152 00153 /* call utime */ 00154 if (utime(pthstr, times) == -1) 00155 errsts = errno; 00156 00157 free(pthstr); 00158 } 00159 } 00160 00161 *IERROR = errsts; 00162 00163 return; 00164 } 00165 00166 #ifndef _UNICOS 00167 void 00168 pxfutime_( 00169 char *PATH, /* Character variable containing argument */ 00170 _f_int *ILEN, /* Significant length of argument */ 00171 _f_int *JUTIMBUF, /* handle for struct utimbuf */ 00172 _f_int *IERROR, /* Error status */ 00173 _f_int pathlen 00174 ) 00175 { 00176 _PXFUTIME(_cptofcd(PATH, pathlen), ILEN, JUTIMBUF, IERROR); 00177 } 00178 #endif
1.5.6