OSDN Git Service

Last portion of libc_hidden_proto removal.
[uclinux-h8/uClibc.git] / libc / sysdeps / linux / common / waitid.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * Copyright (C) 2007 Erik Andersen <andersen@uclibc.org>
4  *
5  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
6  */
7
8 #include <features.h>
9
10 #if defined __USE_SVID || defined __USE_XOPEN
11 # include <sys/types.h>
12 # include <sys/wait.h>
13 # include <sys/syscall.h>
14 # ifdef __NR_waitid
15 _syscall4(int, waitid, idtype_t, idtype, id_t, id, siginfo_t*, infop, int, options)
16 # else
17 #  include <string.h>
18 /* libc_hidden_proto(waitpid) */
19 int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options)
20 {
21         switch (idtype) {
22                 case P_PID:
23                         if (id <= 0)
24                                 goto invalid;
25                         break;
26                 case P_PGID:
27                         if (id < 0 || id == 1)
28                                 goto invalid;
29                         id = -id;
30                         break;
31                 case P_ALL:
32                         id = -1;
33                         break;
34                 default:
35                 invalid:
36                         __set_errno(EINVAL);
37                         return -1;
38         }
39
40         memset(infop, 0, sizeof *infop);
41         infop->si_pid = waitpid(id, &infop->si_status, options
42 #  ifdef WEXITED
43                                            &~ WEXITED
44 #  endif
45                                           );
46         if (infop->si_pid < 0)
47                 return infop->si_pid;
48         return 0;
49 }
50 # endif
51 #endif