summaryrefslogtreecommitdiff
path: root/demo/pwuid.py
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2012-06-14 18:35:51 +0200
committerArmin Rigo <arigo@tunes.org>2012-06-14 18:35:51 +0200
commitfb10d3a3c13904fd3f5f36423ddcba95af8dbb2f (patch)
tree0ce2efae08cb77c1b250466096fc75ac191ed96d /demo/pwuid.py
parent5ef91bc1a83a612212c1ddb1cc26c404aed758ae (diff)
downloadcffi-fb10d3a3c13904fd3f5f36423ddcba95af8dbb2f.tar.gz
Add this example from README.md.
Diffstat (limited to 'demo/pwuid.py')
-rw-r--r--demo/pwuid.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/demo/pwuid.py b/demo/pwuid.py
new file mode 100644
index 0000000..5ed704e
--- /dev/null
+++ b/demo/pwuid.py
@@ -0,0 +1,14 @@
+from cffi import FFI
+ffi = FFI()
+ffi.cdef(""" // some declarations from the man page
+ struct passwd {
+ char *pw_name;
+ ...;
+ };
+ struct passwd *getpwuid(int uid);
+""")
+C = ffi.verify(""" // passed to the real C compiler
+#include <sys/types.h>
+#include <pwd.h>
+""")
+print str(C.getpwuid(0).pw_name)