uid.c 520 B

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