Esempio n. 1
0
int
WriteNativeFieldList(FieldList list,
                     FILE      *file)
{
   long    num_fields;          /* number of fields */
   long    i;                   /* loop index */

   if (file == NULL)
      {
         DebugMsg(1, "WriteNativeFieldList: NULL file pointer.");
         return FALSE;
      }

   num_fields = FieldListLength(list);

   if (fwrite(&num_fields, sizeof(long), 1, file) != 1)
      {
         DebugMsg(1, "WriteNativeFieldList: couldn't write number of fields.");
         return FALSE;
      }

   for (i = 0; i < num_fields; i++)
      if (!WriteNativeFieldSpec(list[i], file))
         {
            DebugMsg(2, "WriteNativeFieldList: couldn't write field spec.");
            return FALSE;
         }

   return TRUE;         /* Success. */
}
Esempio n. 2
0
int
AddField(FieldList   *list,	/* variable containing field list */
	 FieldSpec   *field)	/* specification of field */
{
    int		n;		/* length of list */
    FieldList	new_list;	/* new field list */

    /* Check for bad argument. */

    if (field == NULL || list == NULL)
	return FALSE;

    /* Extend list with 1 new pointer plus terminating NULL. */

    if (*list == NULL)
    {
	n = 0;
	new_list = (FieldList) malloc(2 * sizeof(**list));
    }
    else
    {
	n = FieldListLength(*list);
	new_list = (FieldList) realloc(*list, (n+2) * sizeof(**list));
    }

    if (new_list == NULL)	/* Allocation failure. */
	return FALSE;

    new_list[n] = field;
    new_list[n+1] = NULL;
    *list = new_list;

    return TRUE;
}