libnczarr/zattr.c
int
ncz_makeattr(NC_OBJ* container, NCindex* attlist, const char* name, nc_type typeid, size_t len, void* values, NC_ATT_INFO_T** attp)
{
    int stat = NC_NOERR;
    NC_ATT_INFO_T* att = NULL;
    NCZ_ATT_INFO_T* zatt = NULL;
    void* clone = NULL;
    size_t typesize, clonesize;
    NC_GRP_INFO_T* grp = (container->sort == NCGRP ? (NC_GRP_INFO_T*)container
                                                   : ((NC_VAR_INFO_T*)container)->container);

    /* Duplicate the values */
    if ((stat = nc4_get_typelen_mem(grp->nc4_info, typeid, &typesize))) goto done;
    clonesize = len*typesize;
    if((clone = malloc(clonesize))==NULL) {stat = NC_ENOMEM; goto done;}
    memcpy(clone,values,clonesize);

    if((stat=nc4_att_list_add(attlist,name,&att)))
	goto done;
    if((zatt = calloc(1,sizeof(NCZ_ATT_INFO_T))) == NULL)
	{stat = NC_ENOMEM; goto done;}
    if(container->sort == NCGRP) {
        zatt->common.file = ((NC_GRP_INFO_T*)container)->nc4_info;
    } else if(container->sort == NCVAR) {
        zatt->common.file = ((NC_VAR_INFO_T*)container)->container->nc4_info;
    } else
	abort();
    att->container = container;
    att->format_att_info = zatt;
    /* Fill in the attribute's type and value  */
    att->nc_typeid = typeid;
    att->len = len;
    att->data = clone; clone = NULL;
    att->dirty = NC_TRUE;
    if(attp) {*attp = att; att = NULL;}

done:
    nullfree(clone);
    if(stat) {
	if(att) nc4_att_list_del(attlist,att);
	nullfree(zatt);
    }
    return THROW(stat);
}
/* Create an attribute; This is an abbreviated form
   of ncz_put_att above */
Create an attribute; This is an abbreviated form
of ncz_put_att above
Create an attribute ; This is an abbreviated form of ncz_put_att above
int
ncz_makeattr(NC_OBJ* container, NCindex* attlist, const char* name, nc_type typeid, size_t len, void* values, NC_ATT_INFO_T** attp)
{
    int stat = NC_NOERR;
    NC_ATT_INFO_T* att = NULL;
    NCZ_ATT_INFO_T* zatt = NULL;
    void* clone = NULL;
    size_t typesize, clonesize;
    NC_GRP_INFO_T* grp = (container->sort == NCGRP ? (NC_GRP_INFO_T*)container
                                                   : ((NC_VAR_INFO_T*)container)->container);
    if ((stat = nc4_get_typelen_mem(grp->nc4_info, typeid, &typesize))) goto done;
    clonesize = len*typesize;
    if((clone = malloc(clonesize))==NULL) {stat = NC_ENOMEM; goto done;}
    memcpy(clone,values,clonesize);
    if((stat=nc4_att_list_add(attlist,name,&att)))
	goto done;
    if((zatt = calloc(1,sizeof(NCZ_ATT_INFO_T))) == NULL)
	{stat = NC_ENOMEM; goto done;}
    if(container->sort == NCGRP) {
        zatt->common.file = ((NC_GRP_INFO_T*)container)->nc4_info;
    } else if(container->sort == NCVAR) {
        zatt->common.file = ((NC_VAR_INFO_T*)container)->container->nc4_info;
    } else
	abort();
    att->container = container;
    att->format_att_info = zatt;
    att->nc_typeid = typeid;
    att->len = len;
    att->data = clone; clone = NULL;
    att->dirty = NC_TRUE;
    if(attp) {*attp = att; att = NULL;}
done:
    nullfree(clone);
    if(stat) {
	if(att) nc4_att_list_del(attlist,att);
	nullfree(zatt);
    }
    return THROW(stat);
}
int ncz_makeattr ( NC_OBJ * container , NCindex * attlist , const char * name , nc_type typeid , size_t len , void * values , NC_ATT_INFO_T * * attp ) { int stat = NC_NOERR ; NC_ATT_INFO_T * att = NULL ; NCZ_ATT_INFO_T * zatt = NULL ; void * clone = NULL ; size_t typesize , clonesize ; NC_GRP_INFO_T * grp = ( container -> sort == NCGRP ? ( NC_GRP_INFO_T * ) container : ( ( NC_VAR_INFO_T * ) container ) -> container ) ; if ( ( stat = nc4_get_typelen_mem ( grp -> nc4_info , typeid , & typesize ) ) ) goto done ; clonesize = len * typesize ; if ( ( clone = malloc ( clonesize ) ) == NULL ) { stat = NC_ENOMEM ; goto done ; } memcpy ( clone , values , clonesize ) ; if ( ( stat = nc4_att_list_add ( attlist , name , & att ) ) ) goto done ; if ( ( zatt = calloc ( 1 , sizeof ( NCZ_ATT_INFO_T ) ) ) == NULL ) { stat = NC_ENOMEM ; goto done ; } if ( container -> sort == NCGRP ) { zatt -> common . file = ( ( NC_GRP_INFO_T * ) container ) -> nc4_info ; } else if ( container -> sort == NCVAR ) { zatt -> common . file = ( ( NC_VAR_INFO_T * ) container ) -> container -> nc4_info ; } else abort ( ) ; att -> container = container ; att -> format_att_info = zatt ; att -> nc_typeid = typeid ; att -> len = len ; att -> data = clone ; clone = NULL ; att -> dirty = NC_TRUE ; if ( attp ) { * attp = att ; att = NULL ; } done : nullfree ( clone ) ; if ( stat ) { if ( att ) nc4_att_list_del ( attlist , att ) ; nullfree ( zatt ) ; } return THROW ( stat ) ; }
Create an attribute; This is an abbreviated form
of ncz_put_att above
Create an attribute ; This is an abbreviated form of ncz_put_att above
/* Duplicate the values */ /* Fill in the attribute's type and value  */