Exemple #1
0
/*
 * Formerly
NC_new_attr(name,type,count,value)
 */
static NC_attr *
new_NC_attr(
        const char *uname,
        nc_type type,
        size_t nelems)
{
        NC_string *strp;
        NC_attr *attrp;

        char *name = (char *)utf8proc_NFC((const unsigned char *)uname);
        if(name == NULL)
            return NULL;
        assert(name != NULL && *name != 0);

        strp = new_NC_string(strlen(name), name);
        free(name);
        if(strp == NULL)
                return NULL;

        attrp = new_x_NC_attr(strp, type, nelems);
        if(attrp == NULL)
        {
                free_NC_string(strp);
                return NULL;
        }

        return(attrp);
}
Exemple #2
0
/*
 * Formerly
NC_new_attr(name,type,count,value)
 */
static NC_attr *
new_NC_attr(
	const char *uname,
	nc_type type,
	size_t nelems)
{
	NC_string *strp;
	NC_attr *attrp;
	char *name;
	int stat;

	stat = nc_utf8_normalize((const unsigned char *)uname,(unsigned char**)&name);
	if(stat != NC_NOERR)
	    return NULL;
	assert(name != NULL && *name != 0);

	strp = new_NC_string(strlen(name), name);
	free(name);
	if(strp == NULL)
		return NULL;

	attrp = new_x_NC_attr(strp, type, nelems);
	if(attrp == NULL)
	{
		free_NC_string(strp);
		return NULL;
	}

	return(attrp);
}
Exemple #3
0
/* Read a NC_attr from the header */
static int
v1h_get_NC_attr(v1hs *gsp, NC_attr **attrpp)
{
	NC_string *strp;
	int status;
	nc_type type;
	size_t nelems;
	NC_attr *attrp;

	status = v1h_get_NC_string(gsp, &strp);
	if(status != ENOERR)
		return status;

	status = v1h_get_nc_type(gsp, &type);
	if(status != ENOERR)
		goto unwind_name;

	status = v1h_get_size_t(gsp, &nelems);
	if(status != ENOERR)
		goto unwind_name;

	attrp = new_x_NC_attr(strp, type, nelems);
	if(attrp == NULL)
	{
		status = NC_ENOMEM;
		goto unwind_name;
	}
	
	status = v1h_get_NC_attrV(gsp, attrp);
	if(status != ENOERR)
	{
		free_NC_attr(attrp); /* frees strp */
		return status;
	}

	*attrpp = attrp;

	return ENOERR;

unwind_name:
	free_NC_string(strp);
	return status;
}
/*
 * Formerly
NC_new_attr(name,type,count,value)
 */
static NC_attr *
new_NC_attr(
  const char *name,
  nc_type type,
  size_t nelems)
{
  NC_string *strp;
  NC_attr *attrp;

  assert(name != NULL && *name != 0);

  strp = new_NC_string(strlen(name), name);
  if(strp == NULL)
    return NULL;
  
  attrp = new_x_NC_attr(strp, type, nelems);
  if(attrp == NULL)
  {
    free_NC_string(strp);
    return NULL;
  }

  return(attrp);
}