/*
 *  This file is part of ixemul.library for the Amiga.
 *  Copyright (C) 1991, 1992  Markus M. Wild
 *
 *  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, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

#define KERNEL
#include "ixemul.h"
#include "kprintf.h"
#include "devices.h"

/* since this has library scope, not just process scope, it can be global */
struct vdevice *vdevices = 0;
int		num_vdev = 0;

int
ix_config_vdevices (struct vdevice *devs)
{
  int num_dev;
  struct vdevice *vd, *d;

  /* count the number of given devices */
  for (vd = devs, num_dev = 0; vd->vd_name; vd++, num_dev++)
    if (vd->vd_type > VDEV_TYPE_MAX)
      {
        errno = EINVAL;
	KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
        return -1;
      }

  d = (struct vdevice *) kmalloc (num_dev * sizeof (struct vdevice));
  if (! d)
    {
outofmem:
      errno = ENOMEM;
      KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
      return -1;
    }

  for (vd = d; devs->vd_name; devs++)
    {
      vd->vd_name = (char *) kmalloc (strlen (devs->vd_name) + 1);
      if (! vd->vd_name)
        goto outofmem;
        
      strcpy (vd->vd_name, devs->vd_name);
      vd->vd_type = devs->vd_type;
   }

  ix_lock_base ();
  if (num_vdev) kfree (vdevices);
  vdevices = d;
  num_vdev = num_dev;
  ix_unlock_base ();

  return 0;
}
