home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / library / rcs / ix_config_vdevices.c,v < prev    next >
Encoding:
Text File  |  1992-07-04  |  1.2 KB  |  75 lines

  1. head    1.1;
  2. access;
  3. symbols
  4.     version39-41:1.1;
  5. locks;
  6. comment    @ *  @;
  7.  
  8.  
  9. 1.1
  10. date    92.05.14.19.55.40;    author mwild;    state Exp;
  11. branches;
  12. next    ;
  13.  
  14.  
  15. desc
  16. @provide virtual devices for ixemul.library
  17. @
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @#define KERNEL
  26. #include "ixemul.h"
  27.  
  28. #include "devices.h"
  29.  
  30. /* since this has library scope, not just process scope, it can be global */
  31. struct vdevice *vdevices = 0;
  32. int        num_vdev = 0;
  33.  
  34. int
  35. ix_config_vdevices (struct vdevice *devs)
  36. {
  37.   int num_dev;
  38.   struct vdevice *vd, *d;
  39.  
  40.   /* count the number of given devices */
  41.   for (vd = devs, num_dev = 0; vd->vd_name; vd++, num_dev++)
  42.     if (vd->vd_type > VDEV_TYPE_MAX)
  43.       {
  44.         errno = EINVAL;
  45.         return -1;
  46.       }
  47.  
  48.   d = (struct vdevice *) kmalloc (num_dev * sizeof (struct vdevice));
  49.   if (! d)
  50.     {
  51. outofmem:
  52.       errno = ENOMEM;
  53.       return -1;
  54.     }
  55.  
  56.   for (vd = d; devs->vd_name; devs++)
  57.     {
  58.       vd->vd_name = (char *) kmalloc (strlen (devs->vd_name) + 1);
  59.       if (! vd->vd_name)
  60.         goto outofmem;
  61.         
  62.       strcpy (vd->vd_name, devs->vd_name);
  63.       vd->vd_type = devs->vd_type;
  64.    }
  65.  
  66.   ix_lock_base ();
  67.   if (num_vdev) kfree (vdevices);
  68.   vdevices = d;
  69.   num_vdev = num_dev;
  70.   ix_unlock_base ();
  71.  
  72.   return 0;
  73. }
  74. @
  75.