This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
typo fix
[perl5.git] / beos / beos.c
CommitLineData
d1c9dd79 1#include "beos/beosish.h"
30410c71 2
efca5cc6 3#undef waitpid
dbc1d986 4#undef kill
e56d2c04 5#undef sigaction
efca5cc6 6
dbc1d986
IW
7#include <errno.h>
8#include <signal.h>
9#include <stdio.h>
10#include <stdlib.h>
11#include <unistd.h>
efca5cc6
JH
12#include <sys/wait.h>
13
dbc1d986
IW
14#include <OS.h>
15
efca5cc6 16/* In BeOS 5.0 the waitpid() seems to misbehave in that the status
dff18f87 17 * has the upper and lower bytes swapped compared with the usual
ed0436dc 18 * POSIX/UNIX implementations. To undo the surprise effect to the
dff18f87
JH
19 * rest of Perl we need this wrapper. (The rest of BeOS might be
20 * surprised because of this, though.) */
efca5cc6
JH
21
22pid_t beos_waitpid(pid_t process_id, int *status_location, int options) {
30410c71 23 pid_t got = waitpid(process_id, status_location, options);
7b9cd8f0 24 if (status_location)
dff18f87
JH
25 *status_location =
26 (*status_location & 0x00FF) << 8 |
27 (*status_location & 0xFF00) >> 8;
efca5cc6
JH
28 return got;
29}
dbc1d986 30
dbc1d986
IW
31
32/* BeOS kill() doesn't like the combination of the pseudo-signal 0 and
33 * specifying a process group (i.e. pid < -1 || pid == 0). We work around
34 * by changing pid to the respective process group leader. That should work
35 * well enough in most cases. */
36
37int beos_kill(pid_t pid, int sig)
38{
39 if (sig == 0) {
40 if (pid == 0) {
41 /* it's our process group */
42 pid = getpgrp();
43 } else if (pid < -1) {
44 /* just address the process group leader */
45 pid = -pid;
46 }
47 }
48
49 return kill(pid, sig);
50}
e56d2c04
IW
51
52/* sigaction() should fail, if trying to ignore or install a signal handler
53 * for a signal that cannot be caught or ignored. The BeOS R5 sigaction()
54 * doesn't return an error, though. */
55int beos_sigaction(int sig, const struct sigaction *act,
56 struct sigaction *oact)
57{
58 int result = sigaction(sig, act, oact);
59
60 if (result == 0 && act && act->sa_handler != SIG_DFL
61 && act->sa_handler != SIG_ERR && (sig == SIGKILL || sig == SIGSTOP)) {
62 result = -1;
63 errno = EINVAL;
64 }
65
66 return result;
67}