fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

char: Add new posix file character driver

The posix file character driver reads from and writes to files using
the read() and write() functions. Unlike the stdio character driver
it can be used to provide input, for example using a named pipe.

Hampa Hug 06f368d3 e1507ce8

+412 -1
+4
Makefile.dep
··· 1847 1847 src/drivers/char/char-null.h \ 1848 1848 src/drivers/char/char.h 1849 1849 1850 + src/drivers/char/char-posix.o: src/drivers/char/char-posix.c \ 1851 + src/drivers/char/char-posix.h \ 1852 + src/drivers/char/char.h 1853 + 1850 1854 src/drivers/char/char-stdio.o: src/drivers/char/char-stdio.c \ 1851 1855 src/drivers/char/char-stdio.h \ 1852 1856 src/drivers/char/char.h
+2 -1
Makefile.inc.in
··· 77 77 78 78 PCE_ENABLE_TUN := @PCE_ENABLE_TUN@ 79 79 80 - PCE_ENABLE_CHAR_TIOS := @PCE_ENABLE_CHAR_TIOS@ 80 + PCE_ENABLE_CHAR_POSIX := @PCE_ENABLE_CHAR_POSIX@ 81 + PCE_ENABLE_CHAR_TIOS := @PCE_ENABLE_CHAR_TIOS@ 81 82 82 83 distdir := pce-$(PCE_VERSION_STR) 83 84
+51
configure
··· 597 597 PCE_ENABLE_READLINE 598 598 PCE_ENABLE_TUN 599 599 PCE_ENABLE_CHAR_TIOS 600 + PCE_ENABLE_CHAR_POSIX 600 601 PCE_BUILD_SIMARM 601 602 PCE_BUILD_SIMS32 602 603 PCE_BUILD_SIM6502 ··· 704 705 enable_sim6502 705 706 enable_sims32 706 707 enable_simarm 708 + enable_char_posix 707 709 enable_char_termios 708 710 enable_tun 709 711 enable_readline ··· 1342 1344 --enable-sim6502 Enable the 6502 simulator 1343 1345 --enable-sims32 Enable the sparc32 simulator 1344 1346 --enable-simarm Enable the arm simulator 1347 + --enable-char-posix Enable the posix file character driver 1345 1348 --enable-char-termios Enable the termios character driver 1346 1349 --enable-tun Enable tun networking 1347 1350 --enable-readline Enable readline ··· 3947 3950 fcntl.h \ 3948 3951 linux/if_tun.h \ 3949 3952 limits.h \ 3953 + poll.h \ 3950 3954 sys/ioctl.h \ 3951 3955 sys/poll.h \ 3952 3956 sys/socket.h \ ··· 4614 4618 fi 4615 4619 4616 4620 4621 + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable the posix file character driver" >&5 4622 + $as_echo_n "checking whether to enable the posix file character driver... " >&6; } 4623 + # Check whether --enable-char-posix was given. 4624 + if test "${enable_char_posix+set}" = set; then : 4625 + enableval=$enable_char_posix; 4626 + if test "x$enableval" = "xyes" ; then 4627 + PCE_ENABLE_CHAR_POSIX=1 4628 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 4629 + $as_echo "yes" >&6; } 4630 + else 4631 + PCE_ENABLE_CHAR_POSIX=0 4632 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 4633 + $as_echo "no" >&6; } 4634 + fi 4635 + 4636 + else 4637 + 4638 + PCE_ENABLE_CHAR_POSIX=1 4639 + test "x$ac_cv_header_fcntl_h" = "xyes" || PCE_ENABLE_CHAR_POSIX=0 4640 + test "x$ac_cv_header_poll_h" = "xyes" || PCE_ENABLE_CHAR_POSIX=0 4641 + test "x$ac_cv_header_sys_stat_h" = "xyes" || PCE_ENABLE_CHAR_POSIX=0 4642 + test "x$ac_cv_header_unistd_h" = "xyes" || PCE_ENABLE_CHAR_POSIX=0 4643 + if test "x$PCE_ENABLE_CHAR_PTY" = "x1" ; then 4644 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes (guess)" >&5 4645 + $as_echo "yes (guess)" >&6; } 4646 + else 4647 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no (guess)" >&5 4648 + $as_echo "no (guess)" >&6; } 4649 + fi 4650 + 4651 + 4652 + fi 4653 + 4654 + 4655 + if test "x$PCE_ENABLE_CHAR_POSIX" = "x1" ; then 4656 + $as_echo "#define PCE_ENABLE_CHAR_POSIX 1" >>confdefs.h 4657 + 4658 + fi 4659 + 4660 + 4617 4661 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable the termios character driver" >&5 4618 4662 $as_echo_n "checking whether to enable the termios character driver... " >&6; } 4619 4663 # Check whether --enable-char-termios was given. ··· 4954 4998 char1=" null stdio" 4955 4999 char2="" 4956 5000 5001 + if test "x$PCE_ENABLE_CHAR_POSIX" = "x1" ; then 5002 + char1="$char1 posix" 5003 + else 5004 + char2="$char2 posix" 5005 + fi 5006 + 4957 5007 if test "x$PCE_ENABLE_CHAR_TIOS" = "x1" ; then 4958 5008 char1="$char1 termios" 4959 5009 else 4960 5010 char2="$char2 termios" 4961 5011 fi 5012 + 4962 5013 4963 5014 option1="" 4964 5015 option2=""
+38
configure.in
··· 197 197 fcntl.h \ 198 198 linux/if_tun.h \ 199 199 limits.h \ 200 + poll.h \ 200 201 sys/ioctl.h \ 201 202 sys/poll.h \ 202 203 sys/socket.h \ ··· 493 494 fi 494 495 495 496 497 + AC_MSG_CHECKING([whether to enable the posix file character driver]) 498 + AC_ARG_ENABLE(char-posix, 499 + AC_HELP_STRING([--enable-char-posix], [Enable the posix file character driver]), 500 + [ 501 + if test "x$enableval" = "xyes" ; then 502 + PCE_ENABLE_CHAR_POSIX=1 503 + AC_MSG_RESULT([yes]) 504 + else 505 + PCE_ENABLE_CHAR_POSIX=0 506 + AC_MSG_RESULT([no]) 507 + fi 508 + ],[ 509 + PCE_ENABLE_CHAR_POSIX=1 510 + test "x$ac_cv_header_fcntl_h" = "xyes" || PCE_ENABLE_CHAR_POSIX=0 511 + test "x$ac_cv_header_poll_h" = "xyes" || PCE_ENABLE_CHAR_POSIX=0 512 + test "x$ac_cv_header_sys_stat_h" = "xyes" || PCE_ENABLE_CHAR_POSIX=0 513 + test "x$ac_cv_header_unistd_h" = "xyes" || PCE_ENABLE_CHAR_POSIX=0 514 + if test "x$PCE_ENABLE_CHAR_PTY" = "x1" ; then 515 + AC_MSG_RESULT([yes (guess)]) 516 + else 517 + AC_MSG_RESULT([no (guess)]) 518 + fi 519 + ] 520 + ) 521 + AC_SUBST(PCE_ENABLE_CHAR_POSIX) 522 + if test "x$PCE_ENABLE_CHAR_POSIX" = "x1" ; then 523 + AC_DEFINE(PCE_ENABLE_CHAR_POSIX) 524 + fi 525 + 526 + 496 527 AC_MSG_CHECKING([whether to enable the termios character driver]) 497 528 AC_ARG_ENABLE(char-termios, 498 529 AC_HELP_STRING([--enable-char-termios], [Enable the termios character driver]), ··· 675 706 char1=" null stdio" 676 707 char2="" 677 708 709 + if test "x$PCE_ENABLE_CHAR_POSIX" = "x1" ; then 710 + char1="$char1 posix" 711 + else 712 + char2="$char2 posix" 713 + fi 714 + 678 715 if test "x$PCE_ENABLE_CHAR_TIOS" = "x1" ; then 679 716 char1="$char1 termios" 680 717 else 681 718 char2="$char2 termios" 682 719 fi 720 + 683 721 684 722 option1="" 685 723 option2=""
+1
src/arch/ibmpc/ibmpc.cfg.in
··· 328 328 # Not all character drivers are supported on 329 329 # all platforms. 330 330 #driver = "null" 331 + #driver = "posix:file=serport1.out" 331 332 driver = "stdio:file=serport1.out" 332 333 #driver = "tios:file=/dev/ttyS0" 333 334
+1
src/arch/macplus/macplus.cfg.in
··· 178 178 # Not all character drivers are supported on 179 179 # all platforms. 180 180 #driver = "null" 181 + #driver = "posix:file=ser_a.out" 181 182 driver = "stdio:file=ser_a.out" 182 183 #driver = "tios:file=/dev/ttyS0" 183 184 }
+2
src/config.h.in
··· 47 47 #undef HAVE_INTTYPES_H 48 48 #undef HAVE_LINUX_IF_TUN_H 49 49 #undef HAVE_LIMITS_H 50 + #undef HAVE_POLL_H 50 51 #undef HAVE_STDINT_H 51 52 #undef HAVE_SYS_IOCTL_H 52 53 #undef HAVE_SYS_POLL_H ··· 89 90 90 91 #undef PCE_ENABLE_TUN 91 92 93 + #undef PCE_ENABLE_CHAR_POSIX 92 94 #undef PCE_ENABLE_CHAR_TIOS 93 95 94 96 /* directory separator */
+7
src/drivers/char/Makefile.inc
··· 8 8 DRV_CHR_BAS := char char-null char-stdio 9 9 DRV_CHR_NBAS := 10 10 11 + ifeq "$(PCE_ENABLE_CHAR_POSIX)" "1" 12 + DRV_CHR_BAS += char-posix 13 + else 14 + DRV_CHR_NBAS += char-posix 15 + endif 16 + 11 17 ifeq "$(PCE_ENABLE_CHAR_TIOS)" "1" 12 18 DRV_CHR_BAS += char-tios 13 19 else ··· 27 33 28 34 $(rel)/char.o: $(rel)/char.c 29 35 $(rel)/char-null.o: $(rel)/char-null.c 36 + $(rel)/char-posix.o: $(rel)/char-posix.c 30 37 $(rel)/char-stdio.o: $(rel)/char-stdio.c 31 38 $(rel)/char-tios.o: $(rel)/char-tios.c 32 39
+257
src/drivers/char/char-posix.c
··· 1 + /***************************************************************************** 2 + * pce * 3 + *****************************************************************************/ 4 + 5 + /***************************************************************************** 6 + * File name: src/drivers/char/char-posix.c * 7 + * Created: 2009-03-10 by Hampa Hug <hampa@hampa.ch> * 8 + * Copyright: (C) 2009 Hampa Hug <hampa@hampa.ch> * 9 + *****************************************************************************/ 10 + 11 + /***************************************************************************** 12 + * This program is free software. You can redistribute it and / or modify it * 13 + * under the terms of the GNU General Public License version 2 as published * 14 + * by the Free Software Foundation. * 15 + * * 16 + * This program is distributed in the hope that it will be useful, but * 17 + * WITHOUT ANY WARRANTY, without even the implied warranty of * 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 19 + * Public License for more details. * 20 + *****************************************************************************/ 21 + 22 + 23 + #include <stdlib.h> 24 + #include <stdio.h> 25 + #include <string.h> 26 + #include <limits.h> 27 + 28 + #include <fcntl.h> 29 + #include <poll.h> 30 + #include <sys/stat.h> 31 + #include <unistd.h> 32 + 33 + #include <drivers/char/char.h> 34 + #include <drivers/char/char-posix.h> 35 + 36 + 37 + static 38 + int chr_posix_check_fd (int fd, int rd, int wr) 39 + { 40 + int r; 41 + struct pollfd pfd[1]; 42 + 43 + if (fd < 0) { 44 + return (1); 45 + } 46 + 47 + pfd[0].fd = fd; 48 + pfd[0].events = (rd ? POLLIN : 0) | (wr ? POLLOUT : 0); 49 + 50 + r = poll (pfd, 1, 0); 51 + 52 + if (r < 0) { 53 + return (1); 54 + } 55 + 56 + if ((pfd[0].revents & (POLLIN | POLLOUT)) == 0) { 57 + return (1); 58 + } 59 + 60 + return (0); 61 + } 62 + 63 + static 64 + void chr_posix_close (char_drv_t *cdrv) 65 + { 66 + char_posix_t *drv; 67 + 68 + drv = cdrv->ext; 69 + 70 + if (drv->fd_write > 2) { 71 + close (drv->fd_write); 72 + } 73 + 74 + if ((drv->fd_read > 2) && (drv->fd_read != drv->fd_write)) { 75 + close (drv->fd_read); 76 + } 77 + 78 + if (drv->name_write != NULL) { 79 + free (drv->name_write); 80 + } 81 + 82 + if (drv->name_read != NULL) { 83 + free (drv->name_read); 84 + } 85 + 86 + if (drv->name != NULL) { 87 + free (drv->name); 88 + } 89 + 90 + free (drv); 91 + } 92 + 93 + static 94 + unsigned chr_posix_read (char_drv_t *cdrv, void *buf, unsigned cnt) 95 + { 96 + char_posix_t *drv; 97 + ssize_t r; 98 + 99 + drv = cdrv->ext; 100 + 101 + if (drv->fd_read < 0) { 102 + return (0); 103 + } 104 + 105 + if (chr_posix_check_fd (drv->fd_read, 1, 0)) { 106 + return (0); 107 + } 108 + 109 + if (cnt > SSIZE_MAX) { 110 + cnt = SSIZE_MAX; 111 + } 112 + 113 + r = read (drv->fd_read, buf, cnt); 114 + 115 + if (r <= 0) { 116 + return (0); 117 + } 118 + 119 + return (r); 120 + } 121 + 122 + static 123 + unsigned chr_posix_write (char_drv_t *cdrv, const void *buf, unsigned cnt) 124 + { 125 + char_posix_t *drv; 126 + ssize_t r; 127 + 128 + drv = cdrv->ext; 129 + 130 + if (drv->fd_write < 0) { 131 + return (cnt); 132 + } 133 + 134 + if (chr_posix_check_fd (drv->fd_write, 0, 1)) { 135 + return (0); 136 + } 137 + 138 + if (cnt > SSIZE_MAX) { 139 + cnt = SSIZE_MAX; 140 + } 141 + 142 + r = write (drv->fd_write, buf, cnt); 143 + 144 + if (r <= 0) { 145 + return (0); 146 + } 147 + 148 + return (r); 149 + } 150 + 151 + static 152 + int chr_posix_init (char_posix_t *drv, const char *name) 153 + { 154 + chr_init (&drv->cdrv, drv); 155 + 156 + drv->cdrv.close = chr_posix_close; 157 + drv->cdrv.read = chr_posix_read; 158 + drv->cdrv.write = chr_posix_write; 159 + 160 + drv->name = NULL; 161 + drv->name_read = NULL; 162 + drv->name_write = NULL; 163 + 164 + drv->fd_read = -1; 165 + drv->fd_write = -1; 166 + 167 + drv->name = chr_get_option (name, "file", 1); 168 + 169 + if (drv->name == NULL) { 170 + drv->name_read = chr_get_option (name, "read", 1); 171 + drv->name_write = chr_get_option (name, "write", 2); 172 + } 173 + 174 + if (drv->name != NULL) { 175 + if (strcmp (drv->name, "-") == 0) { 176 + drv->fd_read = 0; 177 + drv->fd_write = 1; 178 + } 179 + else if (strcmp (drv->name, "--") == 0) { 180 + drv->fd_read = 0; 181 + drv->fd_write = 2; 182 + } 183 + else { 184 + drv->fd_read = open (drv->name, 185 + O_RDWR | O_CREAT | O_NOCTTY | O_TRUNC, 186 + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH 187 + ); 188 + 189 + if (drv->fd_read < 0) { 190 + return (1); 191 + } 192 + 193 + drv->fd_write = drv->fd_read; 194 + } 195 + } 196 + else if ((drv->name_read != NULL) || (drv->name_write != NULL)) { 197 + if (drv->name_read != NULL) { 198 + if (strcmp (drv->name_read, "-") == 0) { 199 + drv->fd_read = 0; 200 + } 201 + else { 202 + drv->fd_read = open (drv->name_read, 203 + O_RDONLY | O_NOCTTY, 0 204 + ); 205 + 206 + if (drv->fd_read < 0) { 207 + return (1); 208 + } 209 + } 210 + } 211 + 212 + if (drv->name_write != NULL) { 213 + if (strcmp (drv->name_write, "-") == 0) { 214 + drv->fd_write = 1; 215 + } 216 + else if (strcmp (drv->name_write, "--") == 0) { 217 + drv->fd_write = 2; 218 + } 219 + else { 220 + drv->fd_write = open (drv->name_write, 221 + O_WRONLY | O_CREAT | O_NOCTTY | O_TRUNC, 222 + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH 223 + ); 224 + 225 + if (drv->fd_write < 0) { 226 + return (1); 227 + } 228 + } 229 + } 230 + } 231 + else { 232 + if (strncmp (name, "sercon", 6) == 0) { 233 + drv->fd_read = 0; 234 + drv->fd_write = 1; 235 + } 236 + } 237 + 238 + return (0); 239 + } 240 + 241 + char_drv_t *chr_posix_open (const char *name) 242 + { 243 + char_posix_t *drv; 244 + 245 + drv = malloc (sizeof (char_posix_t)); 246 + 247 + if (drv == NULL) { 248 + return (NULL); 249 + } 250 + 251 + if (chr_posix_init (drv, name)) { 252 + chr_posix_close (&drv->cdrv); 253 + return (NULL); 254 + } 255 + 256 + return (&drv->cdrv); 257 + }
+44
src/drivers/char/char-posix.h
··· 1 + /***************************************************************************** 2 + * pce * 3 + *****************************************************************************/ 4 + 5 + /***************************************************************************** 6 + * File name: src/drivers/char/char-posix.h * 7 + * Created: 2009-03-10 by Hampa Hug <hampa@hampa.ch> * 8 + * Copyright: (C) 2009 Hampa Hug <hampa@hampa.ch> * 9 + *****************************************************************************/ 10 + 11 + /***************************************************************************** 12 + * This program is free software. You can redistribute it and / or modify it * 13 + * under the terms of the GNU General Public License version 2 as published * 14 + * by the Free Software Foundation. * 15 + * * 16 + * This program is distributed in the hope that it will be useful, but * 17 + * WITHOUT ANY WARRANTY, without even the implied warranty of * 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 19 + * Public License for more details. * 20 + *****************************************************************************/ 21 + 22 + 23 + #ifndef PCE_DRIVERS_CHAR_POSIX_H 24 + #define PCE_DRIVERS_CHAR_POSIX_H 1 25 + 26 + 27 + #include <stdio.h> 28 + 29 + #include <drivers/char/char.h> 30 + 31 + 32 + typedef struct { 33 + char_drv_t cdrv; 34 + 35 + char *name; 36 + char *name_read; 37 + char *name_write; 38 + 39 + int fd_read; 40 + int fd_write; 41 + } char_posix_t; 42 + 43 + 44 + #endif
+4
src/drivers/char/char.c
··· 35 35 36 36 struct chr_drv_list drvtab[] = { 37 37 { "null", chr_null_open }, 38 + #ifdef PCE_ENABLE_CHAR_POSIX 39 + { "posix", chr_posix_open }, 40 + { "sercon", chr_posix_open }, 41 + #endif 38 42 { "stdio", chr_stdio_open }, 39 43 #ifdef PCE_ENABLE_CHAR_TIOS 40 44 { "tios", chr_tios_open },
+1
src/drivers/char/char.h
··· 89 89 90 90 char_drv_t *chr_open (const char *name); 91 91 char_drv_t *chr_null_open (const char *name); 92 + char_drv_t *chr_posix_open (const char *name); 92 93 char_drv_t *chr_stdio_open (const char *name); 93 94 char_drv_t *chr_tios_open (const char *name); 94 95