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/pxfmkfifo.c 92.2 06/29/99 11:36:06" 00038 00039 /* 00040 * PXFMKFIFO -- Make a FIFO special File 00041 * (section 5.4.2 of Posix 1003.9-1992) 00042 * 00043 * Synopsis: 00044 * 00045 * SUBROUTINE PXFMKFIFO(path, ilen, mode, ierror) 00046 * INTEGER ilen, mode, ierror 00047 * CHARACTER PATH*(*) 00048 * 00049 * Description: 00050 * 00051 * PXFMKFIFO uses the mkfifo() utility to create special first-in, 00052 * first-out files. 00053 * 00054 * The arguments are: 00055 * 00056 * path - default character input variable containing the 00057 * path name of the FIFO special file to be created. 00058 * ilen - default input integer variable containing the 00059 * length of path. 00060 * mode - default input integer variable specifying the 00061 * mode for the new file. 00062 * ierror - default integer output variable that contains zero 00063 * if the operation was successful or nonzero if the 00064 * operation was not successful. 00065 * 00066 * PXFMKFIFO may return one of the following error values: 00067 * 00068 * EACCES If search permission is denied for a component of the 00069 * path prefix or if write permission is denied to the 00070 * parent directory. 00071 * 00072 * EEXIST If the specified file exists. 00073 * 00074 * EFAULT If path points outside the allocated process address 00075 * space. 00076 * 00077 * EINVAL If the call contains an argument that is not valid or 00078 * the special file would be on an NFS-mounted system. 00079 * 00080 * ENOENT If component of path does not exist or path is an 00081 * empty string. 00082 * 00083 * ENOMEM If PXFREAD is unable to obtain memory to create an 00084 * internal buffer. 00085 * 00086 * ENOTDIR If component of path is not a directory. 00087 * 00088 * 00089 * ENXIO If the device associated with ifildes is a character 00090 * special file that does not exist or the file pointer 00091 * is out of range. 00092 * 00093 * On PVP systems, PXFMKFIFO may also return: 00094 * 00095 * EFLNEQ If active security label of calling process is outside 00096 * range of the file system on which the file will reside. 00097 * 00098 * EIO If a physical I/O error has occurred, or the read is 00099 * cannot access the device. or If ifildes has O_DIRECT 00100 * or FDIRECT set and nbytes is greater than the number 00101 * of bytes between the current file pointer position 00102 * and the end of file. 00103 * 00104 * On IRIX systems, PXFMKFIFO may also return: 00105 * 00106 * EROFS If the parent directory for the new file is on a 00107 * read-only system. 00108 * 00109 * ENAMETOOLONG If the length of path or a pathname component 00110 * exceeds the maximum allowed. 00111 * 00112 * ENOSPC If the parent directory cannot be extended because 00113 * the file system has no space available. 00114 * 00115 * EDQUOT If the parent directory cannot be extended because 00116 * the disk or inode quota on the file system has been 00117 * exhausted. 00118 * 00119 */ 00120 00121 #include <errno.h> 00122 #include <fortran.h> 00123 #include <liberrno.h> 00124 #include <stdlib.h> 00125 #include <string.h> 00126 #include <sys/errno.h> 00127 #include <sys/stat.h> 00128 #include <sys/types.h> 00129 #include <unistd.h> 00130 00131 extern char *_fc_acopy(_fcd f); 00132 00133 #ifdef _UNICOS 00134 void 00135 PXFMKFIFO( 00136 #else /* _UNICOS */ 00137 void 00138 _PXFMKFIFO( 00139 #endif /* _UNICOS */ 00140 _fcd path, 00141 _f_int *ilen, 00142 _f_int *mode, 00143 _f_int *ierror) 00144 { 00145 char *copy_path_adr; 00146 char *path_adr; 00147 int errsts = 0; 00148 long copy_ilen; 00149 long path_len; 00150 mode_t copy_mode; 00151 00152 copy_ilen = *ilen; 00153 *ierror = 0; 00154 copy_mode = (mode_t)*mode; 00155 path_len = _fcdlen(path); 00156 path_adr = _fcdtocp(path); 00157 00158 if (copy_ilen < 0 || copy_ilen > path_len) 00159 errsts = EINVAL; 00160 else { 00161 /* if ilen is zero, strip trailing blanks. 00162 * Otherwise, malloc memory and copy the 00163 * string and add a NULL terminator. 00164 */ 00165 if (copy_ilen == 0) 00166 copy_path_adr = _fc_acopy(path); 00167 else 00168 copy_path_adr = (char *) malloc(copy_ilen + 1); 00169 if (copy_path_adr == NULL) 00170 errsts = ENOMEM; 00171 else { 00172 if (copy_ilen != 0) { 00173 00174 /* copy the path argument */ 00175 (void) memcpy(copy_path_adr, path_adr, 00176 copy_ilen); 00177 copy_path_adr[copy_ilen] = '\0'; 00178 } 00179 if ((errsts = mkfifo(copy_path_adr, copy_mode)) == -1); 00180 errsts = errno; 00181 free(copy_path_adr); 00182 } 00183 } 00184 *ierror = (_f_int)errsts; 00185 return; 00186 } 00187 00188 #ifndef _UNICOS 00189 /* assume default integer */ 00190 void 00191 pxfmkfifo_( 00192 char *path, 00193 _f_int *ilen, 00194 _f_int *mode, 00195 _f_int *ierror, 00196 int lenpath) 00197 { 00198 _PXFMKFIFO(_cptofcd(path, lenpath), ilen, mode, ierror); 00199 } 00200 00201 /* assume integer(kind=8) */ 00202 void 00203 pxfmkfifo64_( 00204 char *path, 00205 _f_int8 *ilen, 00206 _f_int8 *mode, 00207 _f_int8 *ierror, 00208 int lenpath) 00209 { 00210 _f_int ierror4; 00211 _f_int ilen4; 00212 _f_int mode4; 00213 00214 ilen4 = *ilen; 00215 mode4 = *mode; 00216 _PXFMKFIFO(_cptofcd(path, lenpath), &ilen4, &mode4, &ierror4); 00217 *ierror = ierror4; 00218 } 00219 #elif defined(_UNICOS) && defined(_CRAYMPP) 00220 /* assume integer(kind=4) arguments and default 64-bit integer */ 00221 void 00222 PXFMKFIFO32( 00223 _fcd path, 00224 _f_int4 *ilen, 00225 _f_int4 *mode, 00226 _f_int4 *ierror) 00227 { 00228 _f_int ilen8; 00229 _f_int mode8; 00230 _f_int ierror8; 00231 00232 ilen8 = *ilen; 00233 mode8 = *mode; 00234 PXFMKFIFO(path, &ilen8, &mode8, &ierror8); 00235 *ierror = ierror8; 00236 } 00237 #endif /* end _UNICOS and _CRAYMPP */
1.5.6