[BACK]Return to dev.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / sndiod

Diff for /src/usr.bin/sndiod/dev.c between version 1.51 and 1.52

version 1.51, 2019/07/10 14:24:42 version 1.52, 2019/07/10 14:28:44
Line 1532 
Line 1532 
 {  {
         char *p;          char *p;
         char name[SLOT_NAMEMAX];          char name[SLOT_NAMEMAX];
         unsigned int i, unit, umap = 0;          unsigned int i, ser, bestser, bestidx;
         unsigned int ser, bestser, bestidx;          struct slot *unit[DEV_NSLOT];
         struct slot *s;          struct slot *s;
   
         /*          /*
Line 1552 
Line 1552 
                 strlcpy(name, "noname", SLOT_NAMEMAX);                  strlcpy(name, "noname", SLOT_NAMEMAX);
   
         /*          /*
          * find the first unused "unit" number for this name           * build a unit-to-slot map for this name
          */           */
         for (i = 0, s = d->slot; i < DEV_NSLOT; i++, s++) {          for (i = 0; i < DEV_NSLOT; i++)
                 if (s->ops == NULL)                  unit[i] = NULL;
                         continue;          for (i = 0; i < DEV_NSLOT; i++) {
                   s = d->slot + i;
                 if (strcmp(s->name, name) == 0)                  if (strcmp(s->name, name) == 0)
                         umap |= (1 << s->unit);                          unit[s->unit] = s;
         }          }
         for (unit = 0; ; unit++) {  
                 if ((umap & (1 << unit)) == 0)  
                         break;  
         }  
   
         /*          /*
          * find a free controller slot with the same name/unit           * find the free slot with the least unit number
          */           */
         for (i = 0, s = d->slot; i < DEV_NSLOT; i++, s++) {          for (i = 0; i < DEV_NSLOT; i++) {
                 if (s->ops == NULL &&                  s = unit[i];
                     strcmp(s->name, name) == 0 &&                  if (s != NULL && s->ops == NULL) {
                     s->unit == unit) {  
 #ifdef DEBUG  #ifdef DEBUG
                         if (log_level >= 3) {                          if (log_level >= 3) {
                                 log_puts(name);                                  log_puts(s->name);
                                 log_putu(unit);                                  log_putu(s->unit);
                                 log_puts(": reused\n");                                  log_puts(": reused\n");
                         }                          }
 #endif  #endif
Line 1603 
Line 1599 
                 s->vol = MIDI_MAXCTL;                  s->vol = MIDI_MAXCTL;
                 strlcpy(s->name, name, SLOT_NAMEMAX);                  strlcpy(s->name, name, SLOT_NAMEMAX);
                 s->serial = d->serial++;                  s->serial = d->serial++;
                 s->unit = unit;                  for (i = 0; unit[i] != NULL; i++)
                           ; /* nothing */
                   s->unit = i;
 #ifdef DEBUG  #ifdef DEBUG
                 if (log_level >= 3) {                  if (log_level >= 3) {
                         log_puts(name);                          log_puts(s->name);
                         log_putu(unit);                          log_putu(s->unit);
                         log_puts(": overwritten slot ");                          log_puts(": overwritten slot ");
                         log_putu(bestidx);                          log_putu(bestidx);
                         log_puts("\n");                          log_puts("\n");
Line 1617 
Line 1615 
         }          }
         if (log_level >= 1) {          if (log_level >= 1) {
                 log_puts(name);                  log_puts(name);
                 log_putu(unit);  
                 log_puts(": out of sub-device slots\n");                  log_puts(": out of sub-device slots\n");
         }          }
         return NULL;          return NULL;

Legend:
Removed from v.1.51  
changed lines
  Added in v.1.52