pwuid.py 335 B

1234567891011121314
  1. from cffi import FFI
  2. ffi = FFI()
  3. ffi.cdef(""" // some declarations from the man page
  4. struct passwd {
  5. char *pw_name;
  6. ...;
  7. };
  8. struct passwd *getpwuid(int uid);
  9. """)
  10. C = ffi.verify(""" // passed to the real C compiler
  11. #include <sys/types.h>
  12. #include <pwd.h>
  13. """)
  14. print ffi.string(C.getpwuid(0).pw_name)