summaryrefslogtreecommitdiff
path: root/sys/src/ape/lib/ap/plan9/getppid.c
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/ape/lib/ap/plan9/getppid.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/ape/lib/ap/plan9/getppid.c')
-rwxr-xr-xsys/src/ape/lib/ap/plan9/getppid.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/sys/src/ape/lib/ap/plan9/getppid.c b/sys/src/ape/lib/ap/plan9/getppid.c
new file mode 100755
index 000000000..01759221b
--- /dev/null
+++ b/sys/src/ape/lib/ap/plan9/getppid.c
@@ -0,0 +1,23 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include "sys9.h"
+
+pid_t
+getppid(void)
+{
+ int n, f;
+ char ppidbuf[15];
+
+ f = open("#c/ppid", 0);
+ n = read(f, ppidbuf, sizeof ppidbuf);
+ if(n < 0)
+ errno = EINVAL;
+ else
+ n = atoi(ppidbuf);
+ close(f);
+ return n;
+}