xref: /minix3/minix/lib/libc/sys/getppid.c (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1*433d6423SLionel Sambuc #include <sys/cdefs.h>
2*433d6423SLionel Sambuc #include "namespace.h"
3*433d6423SLionel Sambuc #include <lib.h>
4*433d6423SLionel Sambuc 
5*433d6423SLionel Sambuc #include <string.h>
6*433d6423SLionel Sambuc #include <unistd.h>
7*433d6423SLionel Sambuc 
getppid(void)8*433d6423SLionel Sambuc pid_t getppid(void)
9*433d6423SLionel Sambuc {
10*433d6423SLionel Sambuc   message m;
11*433d6423SLionel Sambuc 
12*433d6423SLionel Sambuc   memset(&m, 0, sizeof(m));
13*433d6423SLionel Sambuc   /* POSIX says that this function is always successful and that no
14*433d6423SLionel Sambuc    * return value is reserved to indicate an error.  Minix syscalls
15*433d6423SLionel Sambuc    * are not always successful and Minix returns the reserved value
16*433d6423SLionel Sambuc    * (pid_t) -1 when there is an error.
17*433d6423SLionel Sambuc    */
18*433d6423SLionel Sambuc   if (_syscall(PM_PROC_NR, PM_GETPID, &m) < 0) return(-1);
19*433d6423SLionel Sambuc   return(m.m_pm_lc_getpid.parent_pid);
20*433d6423SLionel Sambuc }
21