/* omflibap.c (emx+gcc) */

/* Add a PUBDEF record to an OMFLIB.

Copyright (c) 1993 Eberhard Mattes

This file is part of the emx OMFLIB library.  This library is free
software; you can redistribute it and/or modify it under the terms of
the GNU Library General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.  This library is distributed in the hope
that it will be useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

As a special exception, programs written by Eberhard Mattes can use
this library without restrictions unless changed by someone else. */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "omflib0.h"
#include "omflib.h"

int omflib_add_pub (struct omflib *p, const char *name, word page, char *error)
{
  int i;

  if (p->pub_count >= p->pub_alloc)
    {
      p->pub_alloc += 32;
      p->pub_tab = realloc (p->pub_tab,
                            p->pub_alloc * sizeof (struct pubsym));
      if (p->pub_tab == NULL)
        {
          strcpy (error, strerror (errno));
          p->pub_alloc = 0;
          p->pub_count = 0;
          return (-1);
        }
    }
  i = p->pub_count;
  if ((p->pub_tab[i].name = strdup (name)) == NULL)
    return (omflib_set_error (error));
  p->pub_tab[i].page = page;
  ++p->pub_count;
  return (0);
}
