int dup_NC_dimarrayV(NC_dimarray *ncap, const NC_dimarray *ref) { int status = NC_NOERR; assert(ref != NULL); assert(ncap != NULL); if(ref->nelems != 0) { const size_t sz = ref->nelems * sizeof(NC_dim *); ncap->value = (NC_dim **) malloc(sz); if(ncap->value == NULL) return NC_ENOMEM; (void) memset(ncap->value, 0, sz); ncap->nalloc = ref->nelems; } ncap->nelems = 0; { NC_dim **dpp = ncap->value; const NC_dim **drpp = (const NC_dim **)ref->value; NC_dim *const *const end = &dpp[ref->nelems]; for( /*NADA*/; dpp < end; drpp++, dpp++, ncap->nelems++) { *dpp = dup_NC_dim(*drpp); if(*dpp == NULL) { status = NC_ENOMEM; break; } } } if(status != NC_NOERR) { free_NC_dimarrayV(ncap); return status; } assert(ncap->nelems == ref->nelems); return NC_NOERR; }
int ncmpii_dup_NC_dimarrayV(NC_dimarray *ncap, const NC_dimarray *ref) { int status = NC_NOERR; assert(ref != NULL); assert(ncap != NULL); if(ref->ndefined != 0) { const MPI_Offset sz = ref->ndefined * sizeof(NC_dim *); ncap->value = (NC_dim **) NCI_Malloc(sz); if(ncap->value == NULL) return NC_ENOMEM; (void) memset(ncap->value, 0, sz); ncap->nalloc = ref->ndefined; } ncap->ndefined = 0; { NC_dim **dpp = ncap->value; const NC_dim **drpp = (const NC_dim **)ref->value; NC_dim *const *const end = &dpp[ref->ndefined]; for( /*NADA*/; dpp < end; drpp++, dpp++, ncap->ndefined++) { *dpp = dup_NC_dim(*drpp); if(*dpp == NULL) { status = NC_ENOMEM; break; } } } if(status != NC_NOERR) { ncmpii_free_NC_dimarrayV(ncap); return status; } assert(ncap->ndefined == ref->ndefined); return NC_NOERR; }