00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 static char USMID[] = "@(#) libf/pxf/pxfstructcreate.c 92.1 09/15/99 10:42:00";
00042 #include <fortran.h>
00043 #include <malloc.h>
00044 #include <errno.h>
00045 #include <liberrno.h>
00046 #include <string.h>
00047 #include "pxfstruct.h"
00048 #include "pxfstructtable.h"
00049 #include "table.h"
00050
00051 #ifndef _UNICOS
00052 #include <stddef.h>
00053 #endif
00054
00055 extern char *_fc_acopy(_fcd f);
00056
00057 #define NUMCONST sizeof(strtble)/sizeof(struct strtble)
00058
00059 #define FREE(_A_,_B_) free(((_A_)pxfhand.pxfstructptr)->_B_);
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 #ifdef _UNICOS
00075 void
00076 PXFSTRUCTCREATE(
00077 #else
00078 void
00079 _PXFSTRUCTCREATE(
00080 #endif
00081 _fcd structname, _f_int *jhandle, _f_int *ierror)
00082 {
00083 char *name;
00084 int i;
00085 _f_int jhandle_temp;
00086 void *structp;
00087
00088 name = _fc_acopy(structname);
00089
00090 if (name == NULL) {
00091 *ierror = ENOMEM;
00092 return;
00093 }
00094
00095
00096 for (i = 0; i < NUMCONST; i++) {
00097 if (strcmp(name,strtble[i].str) == 0) {
00098
00099
00100
00101
00102
00103 structp = calloc(1,strtble[i].size);
00104 if (structp==NULL){
00105 *ierror = ENOHANDLE;
00106 } else {
00107 jhandle_temp =
00108 _pxfhandle_table_add(&_pxfhandle_table,
00109 structp,
00110 strtble[i].type);
00111 if (jhandle_temp < 0) {
00112 *ierror = ENOHANDLE;
00113 } else {
00114 *ierror = 0;
00115 *jhandle = jhandle_temp;
00116 }
00117 }
00118 free(name);
00119 return;
00120 }
00121 }
00122 free(name);
00123 *ierror = ENONAME;
00124 }
00125
00126
00127 #ifndef _UNICOS
00128 void
00129 pxfstructcreate_(
00130 char *structname,
00131 _f_int *jhandle,
00132 _f_int *ierror,
00133 _f_int structnamelen)
00134 {
00135 _PXFSTRUCTCREATE(_cptofcd(structname, structnamelen),
00136 jhandle, ierror);
00137 }
00138
00139 #endif
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 #ifdef _UNICOS
00153 void
00154 PXFSTRUCTFREE(
00155 #else
00156 void
00157 _PXFSTRUCTFREE(
00158 #endif
00159 _f_int *jhandle,
00160 _f_int *ierror)
00161 {
00162 int i;
00163 struct pxfhandle pxfhand;
00164
00165 pxfhand = _pxfhandle_table_lookup(&_pxfhandle_table, *jhandle);
00166 if (pxfhand.pxfstructptr == NULL) {
00167 *ierror = EBADHANDLE;
00168 return;
00169 }
00170
00171 switch (pxfhand.pxftype) {
00172 case PXF_FLOCK:
00173 case PXF_UTIMBUF:
00174 case PXF_UNAMBUF:
00175 case PXF_STATBUF:
00176 case PXF_TMSBUF:
00177 case PXF_DIRENT:
00178 case PXF_SIGSET:
00179 case PXF_SIGACTION:
00180
00181 break;
00182
00183 case PXF_GROUP:
00184 FREE(struct group *,gr_name)
00185 FREE(struct group *,gr_passwd)
00186 if (((struct group *)pxfhand.pxfstructptr)->gr_mem != NULL) {
00187 for(i=0;((struct group *)pxfhand.pxfstructptr)->gr_mem[i] != NULL; i++) {
00188 FREE(struct group *,gr_mem[i])
00189 }
00190 }
00191 break;
00192 case PXF_PASSWD:
00193 FREE(struct passwd *,pw_name)
00194 FREE(struct passwd *,pw_dir)
00195 FREE(struct passwd *,pw_shell)
00196
00197 FREE(struct passwd *,pw_passwd)
00198 #ifndef _LITTLE_ENDIAN
00199 FREE(struct passwd *,pw_age)
00200 FREE(struct passwd *,pw_comment)
00201 #endif
00202 FREE(struct passwd *,pw_gecos)
00203 break;
00204
00205 case PXF_TERMIOS:
00206 FREE(struct termios *,c_cc)
00207 break;
00208 }
00209
00210 _pxfhandle_table_remove(&_pxfhandle_table, *jhandle);
00211 *ierror = 0;
00212 return;
00213 }
00214
00215 #ifndef _UNICOS
00216 void
00217 pxfstructfree_(
00218 _f_int *jhandle,
00219 _f_int *ierror)
00220 {
00221 _PXFSTRUCTFREE(jhandle, ierror);
00222 }
00223
00224 #endif
00225
00226