int NC4_fileinfo_init(void) { int stat = NC_NOERR; unsigned major,minor,release; int super; size_t total = 0; /* Build nc properties */ memset((void*)&globalpropinfo,0,sizeof(globalpropinfo)); globalpropinfo.version = NCPROPS_VERSION; globalpropinfo.netcdfver[0] = '\0'; globalpropinfo.hdf5ver[0] = '\0'; stat = NC4_hdf5get_libversion(&major,&minor,&release); if(stat) goto done; snprintf(globalpropinfo.hdf5ver,sizeof(globalpropinfo.hdf5ver), "%1u.%1u.%1u",major,minor,release); strncpy(globalpropinfo.netcdfver,PACKAGE_VERSION,sizeof(globalpropinfo.netcdfver)); /* Now build actual attribute text */ total = 0; total += strlen(NCPVERSION); total += strlen("=00000000|"); total += strlen(NCPNCLIBVERSION); total += strlen(globalpropinfo.netcdfver); total += strlen("=|"); total += strlen(NCPHDF5LIBVERSION); total += strlen(globalpropinfo.hdf5ver); total += strlen("="); /* Last pair has no trailing '|' */ if(total >= sizeof(globalpropinfo.text)) { fprintf(stderr,"%s size is too small\n",NCPROPS); goto done; } globalpropinfo.text[0] = '\0'; snprintf(globalpropinfo.text,sizeof(globalpropinfo.text), "%s=%d|%s=%s|%s=%s", NCPVERSION,globalpropinfo.version, NCPNCLIBVERSION,globalpropinfo.netcdfver, NCPHDF5LIBVERSION,globalpropinfo.hdf5ver); done: return stat; }
int NC4_fileinfo_init(void) { int stat = NC_NOERR; unsigned major,minor,release; int super; /* Build nc properties */ memset((void*)&globalpropinfo,0,sizeof(globalpropinfo)); globalpropinfo.version = NCPROPS_VERSION; globalpropinfo.netcdfver[0] = '\0'; globalpropinfo.hdf5ver[0] = '\0'; stat = NC4_hdf5get_libversion(&major,&minor,&release); if(stat) goto done; snprintf(globalpropinfo.hdf5ver,sizeof(globalpropinfo.hdf5ver), "%1u.%1u.%1u",major,minor,release); strncpy(globalpropinfo.netcdfver,PACKAGE_VERSION,sizeof(globalpropinfo.netcdfver)); done: return stat; }
/** * @internal Initialize default provenance info * This will only be used for newly created files * or for opened files that do not contain an _NCProperties * attribute. * * @return ::NC_NOERR No error. * @author Dennis Heimbigner */ int NC4_provenance_init(void) { int stat = NC_NOERR; int i; NClist* other = NULL; char* name = NULL; char* value = NULL; unsigned major,minor,release; if(globalpropinitialized) return stat; /* Build _NCProperties info */ /* Initialize globalpropinfo */ memset((void*)&globalpropinfo,0,sizeof(globalpropinfo)); globalpropinfo.version = NCPROPS_VERSION; globalpropinfo.properties = nclistnew(); if(globalpropinfo.properties == NULL) {stat = NC_ENOMEM; goto done;} /* Insert primary library version as first entry */ if((name = strdup(NCPNCLIB2)) == NULL) {stat = NC_ENOMEM; goto done;} nclistpush(globalpropinfo.properties,name); name = NULL; /* Avoid multiple free() */ if((value = strdup(PACKAGE_VERSION)) == NULL) {stat = NC_ENOMEM; goto done;} nclistpush(globalpropinfo.properties,value); value = NULL; /* Insert the HDF5 as underlying storage format library */ if((name = strdup(NCPHDF5LIB2)) == NULL) {stat = NC_ENOMEM; goto done;} nclistpush(globalpropinfo.properties,name); name = NULL; stat = NC4_hdf5get_libversion(&major,&minor,&release); if(stat) goto done; { char sversion[64]; snprintf(sversion,sizeof(sversion),"%1u.%1u.%1u",major,minor,release); if((value = strdup(sversion)) == NULL) {stat = NC_ENOMEM; goto done;} } nclistpush(globalpropinfo.properties,value); value = NULL; /* Add any extra fields */ /*Parse them into an NClist */ other = nclistnew(); if(other == NULL) {stat = NC_ENOMEM; goto done;} #ifdef NCPROPERTIES stat = properties_parse(NCPROPERTIES_EXTRA,other); if(stat) goto done; #endif /* merge into the properties list */ for(i=0;i<nclistlength(other);i++) nclistpush(globalpropinfo.properties,strdup(nclistget(other,i))); nclistfreeall(other); other = NULL; done: if(name != NULL) free(name); if(value != NULL) free(value); if(other != NULL) nclistfreeall(other); if(stat && globalpropinfo.properties != NULL) { nclistfreeall(globalpropinfo.properties); globalpropinfo.properties = NULL; } if(stat == NC_NOERR) globalpropinitialized = 1; /* avoid repeating it */ return stat; }