plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

uid.c (520B)


      1 #include <u.h>
      2 #include <libc.h>
      3 
      4 /*
      5  * /adm/users is
      6  *	id:user/group:head member:other members
      7  *
      8  * /etc/{passwd,group}
      9  *	name:x:nn:other stuff
     10  */
     11 
     12 static int isnumber(char *s);
     13 
     14 sniff(Biobuf *b)
     15 {
     16 	read first line of file into p;
     17 
     18 	nf = getfields(p, f, nelem(f), ":");
     19 	if(nf < 4)
     20 		return nil;
     21 
     22 	if(isnumber(f[0]) && !isnumber(f[2]))
     23 		return _plan9;
     24 
     25 	if(!isnumber(f[0]) && isnumber(f[2]))
     26 		return _unix;
     27 
     28 	return nil;
     29 }
     30 
     31 
     32 int
     33 isnumber(char *s)
     34 {
     35 	char *q;
     36 
     37 	strtol(s, &q, 10);
     38 	return *q == '\0';
     39 }
     40 
     41 /* EOF */