9base

revived minimalist port of Plan 9 userland to Unix
git clone git://git.suckless.org/9base
Log | Files | Refs | README | LICENSE

priv.c (377B)


      1 #include <u.h>
      2 #include <libc.h>
      3 #include "9proc.h"
      4 
      5 static Lock privlock;
      6 static ulong privmap;
      7 
      8 int
      9 privalloc(void)
     10 {
     11 	int i;
     12 
     13 	lock(&privlock);
     14 	for(i=0; i<NPRIV; i++)
     15 		if((privmap&(1<<i)) == 0){
     16 			privmap |= (1<<i);
     17 			unlock(&privlock);
     18 			return i;
     19 		}
     20 	unlock(&privlock);
     21 	return -1;
     22 }
     23 
     24 void**
     25 privmem(int i)
     26 {
     27 	Uproc *up;
     28 
     29 	up = _p9uproc(0);
     30 	return &up->priv[i];
     31 }
     32