Damien Miller | 3174125 | 2003-05-19 00:13:38 +1000 | [diff] [blame] | 1 | /* XXX - author */ |
| 2 | |
Damien Miller | 3dfb0dd | 2000-09-30 09:49:08 +1100 | [diff] [blame] | 3 | /* |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 14 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 15 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 16 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 17 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 18 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 19 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 20 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 22 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 | */ |
| 24 | |
Damien Miller | 50f14f8 | 2000-09-01 14:14:37 +1100 | [diff] [blame] | 25 | #include "includes.h" |
Damien Miller | 0f91b4e | 2000-06-18 15:43:25 +1000 | [diff] [blame] | 26 | |
Damien Miller | 3174125 | 2003-05-19 00:13:38 +1000 | [diff] [blame] | 27 | RCSID("$Id: bsd-nextstep.c,v 1.5 2003/05/18 14:13:39 djm Exp $"); |
Damien Miller | e9cf357 | 2001-02-09 12:55:35 +1100 | [diff] [blame] | 28 | |
Damien Miller | 0f91b4e | 2000-06-18 15:43:25 +1000 | [diff] [blame] | 29 | #ifdef HAVE_NEXT |
Damien Miller | 0f91b4e | 2000-06-18 15:43:25 +1000 | [diff] [blame] | 30 | #include <errno.h> |
Damien Miller | 77aba9d | 2000-08-30 10:11:30 +1100 | [diff] [blame] | 31 | #include <sys/wait.h> |
Ben Lindstrom | 45cb293 | 2001-02-04 09:41:33 +0000 | [diff] [blame] | 32 | #include "bsd-nextstep.h" |
Damien Miller | 0f91b4e | 2000-06-18 15:43:25 +1000 | [diff] [blame] | 33 | |
Damien Miller | 77aba9d | 2000-08-30 10:11:30 +1100 | [diff] [blame] | 34 | pid_t |
| 35 | posix_wait(int *status) |
| 36 | { |
Damien Miller | 77aba9d | 2000-08-30 10:11:30 +1100 | [diff] [blame] | 37 | union wait statusp; |
| 38 | pid_t wait_pid; |
| 39 | |
Damien Miller | 3dfb0dd | 2000-09-30 09:49:08 +1100 | [diff] [blame] | 40 | #undef wait /* Use NeXT's wait() function */ |
Damien Miller | 77aba9d | 2000-08-30 10:11:30 +1100 | [diff] [blame] | 41 | wait_pid = wait(&statusp); |
Ben Lindstrom | 9531825 | 2001-03-26 05:35:33 +0000 | [diff] [blame] | 42 | if (status) |
| 43 | *status = (int) statusp.w_status; |
Damien Miller | 77aba9d | 2000-08-30 10:11:30 +1100 | [diff] [blame] | 44 | |
Damien Miller | 3174125 | 2003-05-19 00:13:38 +1000 | [diff] [blame] | 45 | return (wait_pid); |
Damien Miller | 77aba9d | 2000-08-30 10:11:30 +1100 | [diff] [blame] | 46 | } |
| 47 | |
Damien Miller | 0f91b4e | 2000-06-18 15:43:25 +1000 | [diff] [blame] | 48 | int |
| 49 | tcgetattr(int fd, struct termios *t) |
| 50 | { |
| 51 | return (ioctl(fd, TIOCGETA, t)); |
| 52 | } |
| 53 | |
| 54 | int |
| 55 | tcsetattr(int fd, int opt, const struct termios *t) |
| 56 | { |
| 57 | struct termios localterm; |
| 58 | |
| 59 | if (opt & TCSASOFT) { |
| 60 | localterm = *t; |
| 61 | localterm.c_cflag |= CIGNORE; |
| 62 | t = &localterm; |
| 63 | } |
| 64 | switch (opt & ~TCSASOFT) { |
| 65 | case TCSANOW: |
| 66 | return (ioctl(fd, TIOCSETA, t)); |
| 67 | case TCSADRAIN: |
| 68 | return (ioctl(fd, TIOCSETAW, t)); |
| 69 | case TCSAFLUSH: |
| 70 | return (ioctl(fd, TIOCSETAF, t)); |
| 71 | default: |
| 72 | errno = EINVAL; |
| 73 | return (-1); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | int tcsetpgrp(int fd, pid_t pgrp) |
| 78 | { |
Damien Miller | 3dfb0dd | 2000-09-30 09:49:08 +1100 | [diff] [blame] | 79 | return (ioctl(fd, TIOCSPGRP, &pgrp)); |
Damien Miller | 0f91b4e | 2000-06-18 15:43:25 +1000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | speed_t cfgetospeed(const struct termios *t) |
| 83 | { |
| 84 | return (t->c_ospeed); |
| 85 | } |
| 86 | |
| 87 | speed_t cfgetispeed(const struct termios *t) |
| 88 | { |
| 89 | return (t->c_ispeed); |
| 90 | } |
| 91 | |
| 92 | int |
| 93 | cfsetospeed(struct termios *t,int speed) |
| 94 | { |
| 95 | t->c_ospeed = speed; |
| 96 | return (0); |
| 97 | } |
| 98 | |
| 99 | int |
Damien Miller | 31abc9a | 2000-07-09 23:26:27 +1000 | [diff] [blame] | 100 | cfsetispeed(struct termios *t, int speed) |
Damien Miller | 0f91b4e | 2000-06-18 15:43:25 +1000 | [diff] [blame] | 101 | { |
| 102 | t->c_ispeed = speed; |
| 103 | return (0); |
| 104 | } |
Damien Miller | 0f91b4e | 2000-06-18 15:43:25 +1000 | [diff] [blame] | 105 | #endif /* HAVE_NEXT */ |