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 #pragma ident "@(#) libf/pxf/pxfstructcopy.c 92.2 09/15/99 10:41:12"
00038
00039
00040 #include <liberrno.h>
00041 #include <errno.h>
00042 #include <fortran.h>
00043 #include <string.h>
00044 #include <malloc.h>
00045 #include "pxfstruct.h"
00046 #include "pxfstructtable.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 #define NUMCONST sizeof(strtble)/sizeof(struct strtble)
00056
00057 #define COPY_STRING(_DEST_, _SRC_, _ERR_)\
00058 if (_SRC_ != NULL) {\
00059 temp = (char *)malloc(sizeof(char)*(strlen(_SRC_)+1));\
00060 if (temp != NULL) {\
00061 (void)strcpy(temp,_SRC_);\
00062 _DEST_ = temp;\
00063 _ERR_ = 0;\
00064 } else {\
00065 _ERR_ = 1;\
00066 }\
00067 }
00068
00069 #define COPY_STRING_STRUCT(_DEST_, _SRC_, _STRUCTTYPE_, _COMP_, _ERR_) \
00070 COPY_STRING(((struct _STRUCTTYPE_ *)_DEST_)->_COMP_, ((struct _STRUCTTYPE_ *)_SRC_)->_COMP_, _ERR_)
00071
00072 #define FREE(_A_,_B_,_C_) free(((struct _A_ *)_B_)->_C_);
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 #ifdef _UNICOS
00118 void
00119 PXFSTRUCTCOPY(
00120 #else
00121 void
00122 _PXFSTRUCTCOPY(
00123 #endif
00124 _fcd STRUCTNAME,
00125 _f_int *JHANDLE1,
00126 _f_int *JHANDLE2,
00127 _f_int *IERROR
00128 )
00129 {
00130 char *cstructname, *temp;
00131 int i, found, error, num_mem;
00132 struct pxfhandle pxfhand1, pxfhand2;
00133 void *pxfstructptr1, *pxfstructptr2;
00134 void *tempstructptr;
00135
00136 pxfhand1 = _pxfhandle_table_lookup(&_pxfhandle_table, *JHANDLE1);
00137 pxfhand2 = _pxfhandle_table_lookup(&_pxfhandle_table, *JHANDLE2);
00138 if (pxfhand1.pxfstructptr == NULL || pxfhand2.pxfstructptr == NULL) {
00139 *IERROR = EBADHANDLE;
00140 return;
00141 }
00142 pxfstructptr1 = pxfhand1.pxfstructptr;
00143 pxfstructptr2 = pxfhand2.pxfstructptr;
00144
00145
00146 cstructname = _fc_acopy(STRUCTNAME);
00147 if (cstructname == NULL) {
00148 *IERROR = ENOMEM;
00149 return;
00150 }
00151
00152
00153 for (i = 0, found = 0; i < NUMCONST && !found; i++) {
00154 if (strcmp(cstructname,strtble[i].str) == 0) {
00155 found = 1;
00156 }
00157 }
00158
00159 free(cstructname);
00160
00161 if (found == 0 ||
00162 (pxfhand1.pxftype != pxfhand2.pxftype) ||
00163 (pxfhand1.pxftype != strtble[--i].type)) {
00164 *IERROR = ENONAME;
00165 return;
00166 }
00167
00168
00169 switch (pxfhand1.pxftype) {
00170
00171 case PXF_FLOCK:
00172 case PXF_UTIMBUF:
00173 case PXF_UNAMBUF:
00174 case PXF_STATBUF:
00175 case PXF_TMSBUF:
00176 (void)memcpy(pxfstructptr2,pxfstructptr1,strtble[i].size);
00177 break;
00178
00179 case PXF_GROUP:
00180
00181 if ((tempstructptr = calloc(1,strtble[i].size)) != NULL) {
00182
00183
00184 COPY_STRING_STRUCT(tempstructptr,pxfstructptr1,group,gr_name,error)
00185 if (!error) {
00186 COPY_STRING_STRUCT(tempstructptr,pxfstructptr1,group,gr_passwd,error)
00187 if (!error) {
00188 ((struct group *)tempstructptr)->gr_gid = ((struct group *)pxfstructptr1)->gr_gid;
00189 for(num_mem=0; ((struct group *)pxfstructptr1)->gr_mem[num_mem] != NULL; num_mem++);;
00190 if ((((struct group *)tempstructptr)->gr_mem
00191 = (char **)calloc(num_mem+1,sizeof(char *))) != NULL) {
00192 for(i=0; i < num_mem && !error; i++) {
00193 COPY_STRING(((struct group *)tempstructptr)->gr_mem[i],((struct group *)pxfstructptr1)->gr_mem[i],error)
00194 }
00195 if (!error) {
00196
00197 FREE(group,pxfstructptr2,gr_name)
00198 FREE(group,pxfstructptr2,gr_passwd)
00199 if (((struct group *)pxfstructptr2)->gr_mem != NULL) {
00200 for(i=0; ((struct group *)pxfstructptr2)->gr_mem[i] != NULL; i++) {
00201 free(((struct group *)pxfstructptr2)->gr_mem[i]);
00202 }
00203 FREE(group,pxfstructptr2,gr_mem)
00204 }
00205
00206
00207 _pxfhandle_table_replace(&_pxfhandle_table, *JHANDLE2,
00208 tempstructptr, pxfhand2.pxftype);
00209 break;
00210 }
00211
00212
00213 for(i--; i >= 0; i--) {
00214 free(((struct group *)tempstructptr)->gr_mem[i]);
00215 }
00216 FREE(group,tempstructptr,gr_mem)
00217 }
00218 }
00219 FREE(group,tempstructptr,gr_name)
00220 }
00221 *IERROR = ENOMEM;
00222 FREE(group,tempstructptr,gr_passwd)
00223 free(tempstructptr);
00224 } else {
00225 *IERROR = ENOMEM;
00226 }
00227 return;
00228
00229 case PXF_PASSWD:
00230
00231 if ((tempstructptr = calloc(1,strtble[i].size)) != NULL) {
00232
00233
00234 COPY_STRING_STRUCT(tempstructptr,pxfstructptr1,passwd,pw_name,error)
00235 if (!error) {
00236 COPY_STRING_STRUCT(tempstructptr,pxfstructptr1,passwd,pw_passwd,error)
00237 if (!error) {
00238 ((struct passwd *)tempstructptr)->pw_uid = ((struct passwd *)pxfstructptr1)->pw_uid;
00239 ((struct passwd *)tempstructptr)->pw_gid = ((struct passwd *)pxfstructptr1)->pw_gid;
00240 #ifndef _LITTLE_ENDIAN
00241 COPY_STRING_STRUCT(tempstructptr,pxfstructptr1,passwd,pw_age,error)
00242 if (!error) {
00243 COPY_STRING_STRUCT(tempstructptr,pxfstructptr1,passwd,pw_comment,error)
00244 if (!error) {
00245 #endif
00246 COPY_STRING_STRUCT(tempstructptr,pxfstructptr1,passwd,pw_gecos,error)
00247 if (!error) {
00248 COPY_STRING_STRUCT(tempstructptr,pxfstructptr1,passwd,pw_dir,error)
00249 if (!error) {
00250 COPY_STRING_STRUCT(tempstructptr,pxfstructptr1,passwd,pw_shell,error)
00251 if (!error) {
00252
00253 FREE(passwd,pxfstructptr2,pw_name)
00254 FREE(passwd,pxfstructptr2,pw_passwd)
00255 #ifndef _LITTLE_ENDIAN
00256 FREE(passwd,pxfstructptr2,pw_age)
00257 FREE(passwd,pxfstructptr2,pw_comment)
00258 #endif
00259 FREE(passwd,pxfstructptr2,pw_gecos)
00260 FREE(passwd,pxfstructptr2,pw_dir)
00261 FREE(passwd,pxfstructptr2,pw_shell)
00262
00263
00264 _pxfhandle_table_replace(&_pxfhandle_table, *JHANDLE2,
00265 tempstructptr,
00266 pxfhand2.pxftype);
00267 break;
00268 }
00269 FREE(passwd,tempstructptr,pw_shell)
00270 }
00271 FREE(passwd,tempstructptr,pw_dir)
00272 }
00273 FREE(passwd,tempstructptr,pw_gecos)
00274 #ifndef _LITTLE_ENDIAN
00275 }
00276 FREE(passwd,tempstructptr,pw_comment)
00277 }
00278 FREE(passwd,tempstructptr,pw_age)
00279 #endif
00280 }
00281 FREE(passwd,tempstructptr,pw_passwd)
00282 }
00283
00284 *IERROR = ENOMEM;
00285 FREE(passwd,tempstructptr,pw_name)
00286 free(tempstructptr);
00287 } else {
00288 *IERROR = ENOMEM;
00289 }
00290 return;
00291
00292 default:
00293 *IERROR = ENONAME;
00294 return;
00295
00296 }
00297 *IERROR = 0;
00298 }
00299
00300
00301 #ifndef _UNICOS
00302 void
00303 pxfstructcopy_(
00304 char *STRUCTNAME,
00305 _f_int *JHANDLE1,
00306 _f_int *JHANDLE2,
00307 _f_int *IERROR,
00308 _f_int structnamelen
00309 )
00310 {
00311 _PXFSTRUCTCOPY(_cptofcd(STRUCTNAME,structnamelen),
00312 JHANDLE1, JHANDLE2, IERROR);
00313 }
00314 #endif
00315
00316
00317