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.
···597597PCE_ENABLE_READLINE
598598PCE_ENABLE_TUN
599599PCE_ENABLE_CHAR_TIOS
600600+PCE_ENABLE_CHAR_POSIX
600601PCE_BUILD_SIMARM
601602PCE_BUILD_SIMS32
602603PCE_BUILD_SIM6502
···704705enable_sim6502
705706enable_sims32
706707enable_simarm
708708+enable_char_posix
707709enable_char_termios
708710enable_tun
709711enable_readline
···13421344 --enable-sim6502 Enable the 6502 simulator
13431345 --enable-sims32 Enable the sparc32 simulator
13441346 --enable-simarm Enable the arm simulator
13471347+ --enable-char-posix Enable the posix file character driver
13451348 --enable-char-termios Enable the termios character driver
13461349 --enable-tun Enable tun networking
13471350 --enable-readline Enable readline
···39473950 fcntl.h \
39483951 linux/if_tun.h \
39493952 limits.h \
39533953+ poll.h \
39503954 sys/ioctl.h \
39513955 sys/poll.h \
39523956 sys/socket.h \
···46144618fi
461546194616462046214621+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable the posix file character driver" >&5
46224622+$as_echo_n "checking whether to enable the posix file character driver... " >&6; }
46234623+# Check whether --enable-char-posix was given.
46244624+if test "${enable_char_posix+set}" = set; then :
46254625+ enableval=$enable_char_posix;
46264626+ if test "x$enableval" = "xyes" ; then
46274627+ PCE_ENABLE_CHAR_POSIX=1
46284628+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
46294629+$as_echo "yes" >&6; }
46304630+ else
46314631+ PCE_ENABLE_CHAR_POSIX=0
46324632+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
46334633+$as_echo "no" >&6; }
46344634+ fi
46354635+46364636+else
46374637+46384638+ PCE_ENABLE_CHAR_POSIX=1
46394639+ test "x$ac_cv_header_fcntl_h" = "xyes" || PCE_ENABLE_CHAR_POSIX=0
46404640+ test "x$ac_cv_header_poll_h" = "xyes" || PCE_ENABLE_CHAR_POSIX=0
46414641+ test "x$ac_cv_header_sys_stat_h" = "xyes" || PCE_ENABLE_CHAR_POSIX=0
46424642+ test "x$ac_cv_header_unistd_h" = "xyes" || PCE_ENABLE_CHAR_POSIX=0
46434643+ if test "x$PCE_ENABLE_CHAR_PTY" = "x1" ; then
46444644+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes (guess)" >&5
46454645+$as_echo "yes (guess)" >&6; }
46464646+ else
46474647+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no (guess)" >&5
46484648+$as_echo "no (guess)" >&6; }
46494649+ fi
46504650+46514651+46524652+fi
46534653+46544654+46554655+if test "x$PCE_ENABLE_CHAR_POSIX" = "x1" ; then
46564656+ $as_echo "#define PCE_ENABLE_CHAR_POSIX 1" >>confdefs.h
46574657+46584658+fi
46594659+46604660+46174661{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable the termios character driver" >&5
46184662$as_echo_n "checking whether to enable the termios character driver... " >&6; }
46194663# Check whether --enable-char-termios was given.
···49544998char1=" null stdio"
49554999char2=""
4956500050015001+if test "x$PCE_ENABLE_CHAR_POSIX" = "x1" ; then
50025002+ char1="$char1 posix"
50035003+else
50045004+ char2="$char2 posix"
50055005+fi
50065006+49575007if test "x$PCE_ENABLE_CHAR_TIOS" = "x1" ; then
49585008 char1="$char1 termios"
49595009else
49605010 char2="$char2 termios"
49615011fi
50125012+4962501349635014option1=""
49645015option2=""
+38
configure.in
···197197 fcntl.h \
198198 linux/if_tun.h \
199199 limits.h \
200200+ poll.h \
200201 sys/ioctl.h \
201202 sys/poll.h \
202203 sys/socket.h \
···493494fi
494495495496497497+AC_MSG_CHECKING([whether to enable the posix file character driver])
498498+AC_ARG_ENABLE(char-posix,
499499+ AC_HELP_STRING([--enable-char-posix], [Enable the posix file character driver]),
500500+ [
501501+ if test "x$enableval" = "xyes" ; then
502502+ PCE_ENABLE_CHAR_POSIX=1
503503+ AC_MSG_RESULT([yes])
504504+ else
505505+ PCE_ENABLE_CHAR_POSIX=0
506506+ AC_MSG_RESULT([no])
507507+ fi
508508+ ],[
509509+ PCE_ENABLE_CHAR_POSIX=1
510510+ test "x$ac_cv_header_fcntl_h" = "xyes" || PCE_ENABLE_CHAR_POSIX=0
511511+ test "x$ac_cv_header_poll_h" = "xyes" || PCE_ENABLE_CHAR_POSIX=0
512512+ test "x$ac_cv_header_sys_stat_h" = "xyes" || PCE_ENABLE_CHAR_POSIX=0
513513+ test "x$ac_cv_header_unistd_h" = "xyes" || PCE_ENABLE_CHAR_POSIX=0
514514+ if test "x$PCE_ENABLE_CHAR_PTY" = "x1" ; then
515515+ AC_MSG_RESULT([yes (guess)])
516516+ else
517517+ AC_MSG_RESULT([no (guess)])
518518+ fi
519519+ ]
520520+)
521521+AC_SUBST(PCE_ENABLE_CHAR_POSIX)
522522+if test "x$PCE_ENABLE_CHAR_POSIX" = "x1" ; then
523523+ AC_DEFINE(PCE_ENABLE_CHAR_POSIX)
524524+fi
525525+526526+496527AC_MSG_CHECKING([whether to enable the termios character driver])
497528AC_ARG_ENABLE(char-termios,
498529 AC_HELP_STRING([--enable-char-termios], [Enable the termios character driver]),
···675706char1=" null stdio"
676707char2=""
677708709709+if test "x$PCE_ENABLE_CHAR_POSIX" = "x1" ; then
710710+ char1="$char1 posix"
711711+else
712712+ char2="$char2 posix"
713713+fi
714714+678715if test "x$PCE_ENABLE_CHAR_TIOS" = "x1" ; then
679716 char1="$char1 termios"
680717else
681718 char2="$char2 termios"
682719fi
720720+683721684722option1=""
685723option2=""
+1
src/arch/ibmpc/ibmpc.cfg.in
···328328 # Not all character drivers are supported on
329329 # all platforms.
330330 #driver = "null"
331331+ #driver = "posix:file=serport1.out"
331332 driver = "stdio:file=serport1.out"
332333 #driver = "tios:file=/dev/ttyS0"
333334
+1
src/arch/macplus/macplus.cfg.in
···178178 # Not all character drivers are supported on
179179 # all platforms.
180180 #driver = "null"
181181+ #driver = "posix:file=ser_a.out"
181182 driver = "stdio:file=ser_a.out"
182183 #driver = "tios:file=/dev/ttyS0"
183184 }
···11+/*****************************************************************************
22+ * pce *
33+ *****************************************************************************/
44+55+/*****************************************************************************
66+ * File name: src/drivers/char/char-posix.c *
77+ * Created: 2009-03-10 by Hampa Hug <hampa@hampa.ch> *
88+ * Copyright: (C) 2009 Hampa Hug <hampa@hampa.ch> *
99+ *****************************************************************************/
1010+1111+/*****************************************************************************
1212+ * This program is free software. You can redistribute it and / or modify it *
1313+ * under the terms of the GNU General Public License version 2 as published *
1414+ * by the Free Software Foundation. *
1515+ * *
1616+ * This program is distributed in the hope that it will be useful, but *
1717+ * WITHOUT ANY WARRANTY, without even the implied warranty of *
1818+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
1919+ * Public License for more details. *
2020+ *****************************************************************************/
2121+2222+2323+#include <stdlib.h>
2424+#include <stdio.h>
2525+#include <string.h>
2626+#include <limits.h>
2727+2828+#include <fcntl.h>
2929+#include <poll.h>
3030+#include <sys/stat.h>
3131+#include <unistd.h>
3232+3333+#include <drivers/char/char.h>
3434+#include <drivers/char/char-posix.h>
3535+3636+3737+static
3838+int chr_posix_check_fd (int fd, int rd, int wr)
3939+{
4040+ int r;
4141+ struct pollfd pfd[1];
4242+4343+ if (fd < 0) {
4444+ return (1);
4545+ }
4646+4747+ pfd[0].fd = fd;
4848+ pfd[0].events = (rd ? POLLIN : 0) | (wr ? POLLOUT : 0);
4949+5050+ r = poll (pfd, 1, 0);
5151+5252+ if (r < 0) {
5353+ return (1);
5454+ }
5555+5656+ if ((pfd[0].revents & (POLLIN | POLLOUT)) == 0) {
5757+ return (1);
5858+ }
5959+6060+ return (0);
6161+}
6262+6363+static
6464+void chr_posix_close (char_drv_t *cdrv)
6565+{
6666+ char_posix_t *drv;
6767+6868+ drv = cdrv->ext;
6969+7070+ if (drv->fd_write > 2) {
7171+ close (drv->fd_write);
7272+ }
7373+7474+ if ((drv->fd_read > 2) && (drv->fd_read != drv->fd_write)) {
7575+ close (drv->fd_read);
7676+ }
7777+7878+ if (drv->name_write != NULL) {
7979+ free (drv->name_write);
8080+ }
8181+8282+ if (drv->name_read != NULL) {
8383+ free (drv->name_read);
8484+ }
8585+8686+ if (drv->name != NULL) {
8787+ free (drv->name);
8888+ }
8989+9090+ free (drv);
9191+}
9292+9393+static
9494+unsigned chr_posix_read (char_drv_t *cdrv, void *buf, unsigned cnt)
9595+{
9696+ char_posix_t *drv;
9797+ ssize_t r;
9898+9999+ drv = cdrv->ext;
100100+101101+ if (drv->fd_read < 0) {
102102+ return (0);
103103+ }
104104+105105+ if (chr_posix_check_fd (drv->fd_read, 1, 0)) {
106106+ return (0);
107107+ }
108108+109109+ if (cnt > SSIZE_MAX) {
110110+ cnt = SSIZE_MAX;
111111+ }
112112+113113+ r = read (drv->fd_read, buf, cnt);
114114+115115+ if (r <= 0) {
116116+ return (0);
117117+ }
118118+119119+ return (r);
120120+}
121121+122122+static
123123+unsigned chr_posix_write (char_drv_t *cdrv, const void *buf, unsigned cnt)
124124+{
125125+ char_posix_t *drv;
126126+ ssize_t r;
127127+128128+ drv = cdrv->ext;
129129+130130+ if (drv->fd_write < 0) {
131131+ return (cnt);
132132+ }
133133+134134+ if (chr_posix_check_fd (drv->fd_write, 0, 1)) {
135135+ return (0);
136136+ }
137137+138138+ if (cnt > SSIZE_MAX) {
139139+ cnt = SSIZE_MAX;
140140+ }
141141+142142+ r = write (drv->fd_write, buf, cnt);
143143+144144+ if (r <= 0) {
145145+ return (0);
146146+ }
147147+148148+ return (r);
149149+}
150150+151151+static
152152+int chr_posix_init (char_posix_t *drv, const char *name)
153153+{
154154+ chr_init (&drv->cdrv, drv);
155155+156156+ drv->cdrv.close = chr_posix_close;
157157+ drv->cdrv.read = chr_posix_read;
158158+ drv->cdrv.write = chr_posix_write;
159159+160160+ drv->name = NULL;
161161+ drv->name_read = NULL;
162162+ drv->name_write = NULL;
163163+164164+ drv->fd_read = -1;
165165+ drv->fd_write = -1;
166166+167167+ drv->name = chr_get_option (name, "file", 1);
168168+169169+ if (drv->name == NULL) {
170170+ drv->name_read = chr_get_option (name, "read", 1);
171171+ drv->name_write = chr_get_option (name, "write", 2);
172172+ }
173173+174174+ if (drv->name != NULL) {
175175+ if (strcmp (drv->name, "-") == 0) {
176176+ drv->fd_read = 0;
177177+ drv->fd_write = 1;
178178+ }
179179+ else if (strcmp (drv->name, "--") == 0) {
180180+ drv->fd_read = 0;
181181+ drv->fd_write = 2;
182182+ }
183183+ else {
184184+ drv->fd_read = open (drv->name,
185185+ O_RDWR | O_CREAT | O_NOCTTY | O_TRUNC,
186186+ S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
187187+ );
188188+189189+ if (drv->fd_read < 0) {
190190+ return (1);
191191+ }
192192+193193+ drv->fd_write = drv->fd_read;
194194+ }
195195+ }
196196+ else if ((drv->name_read != NULL) || (drv->name_write != NULL)) {
197197+ if (drv->name_read != NULL) {
198198+ if (strcmp (drv->name_read, "-") == 0) {
199199+ drv->fd_read = 0;
200200+ }
201201+ else {
202202+ drv->fd_read = open (drv->name_read,
203203+ O_RDONLY | O_NOCTTY, 0
204204+ );
205205+206206+ if (drv->fd_read < 0) {
207207+ return (1);
208208+ }
209209+ }
210210+ }
211211+212212+ if (drv->name_write != NULL) {
213213+ if (strcmp (drv->name_write, "-") == 0) {
214214+ drv->fd_write = 1;
215215+ }
216216+ else if (strcmp (drv->name_write, "--") == 0) {
217217+ drv->fd_write = 2;
218218+ }
219219+ else {
220220+ drv->fd_write = open (drv->name_write,
221221+ O_WRONLY | O_CREAT | O_NOCTTY | O_TRUNC,
222222+ S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
223223+ );
224224+225225+ if (drv->fd_write < 0) {
226226+ return (1);
227227+ }
228228+ }
229229+ }
230230+ }
231231+ else {
232232+ if (strncmp (name, "sercon", 6) == 0) {
233233+ drv->fd_read = 0;
234234+ drv->fd_write = 1;
235235+ }
236236+ }
237237+238238+ return (0);
239239+}
240240+241241+char_drv_t *chr_posix_open (const char *name)
242242+{
243243+ char_posix_t *drv;
244244+245245+ drv = malloc (sizeof (char_posix_t));
246246+247247+ if (drv == NULL) {
248248+ return (NULL);
249249+ }
250250+251251+ if (chr_posix_init (drv, name)) {
252252+ chr_posix_close (&drv->cdrv);
253253+ return (NULL);
254254+ }
255255+256256+ return (&drv->cdrv);
257257+}
+44
src/drivers/char/char-posix.h
···11+/*****************************************************************************
22+ * pce *
33+ *****************************************************************************/
44+55+/*****************************************************************************
66+ * File name: src/drivers/char/char-posix.h *
77+ * Created: 2009-03-10 by Hampa Hug <hampa@hampa.ch> *
88+ * Copyright: (C) 2009 Hampa Hug <hampa@hampa.ch> *
99+ *****************************************************************************/
1010+1111+/*****************************************************************************
1212+ * This program is free software. You can redistribute it and / or modify it *
1313+ * under the terms of the GNU General Public License version 2 as published *
1414+ * by the Free Software Foundation. *
1515+ * *
1616+ * This program is distributed in the hope that it will be useful, but *
1717+ * WITHOUT ANY WARRANTY, without even the implied warranty of *
1818+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
1919+ * Public License for more details. *
2020+ *****************************************************************************/
2121+2222+2323+#ifndef PCE_DRIVERS_CHAR_POSIX_H
2424+#define PCE_DRIVERS_CHAR_POSIX_H 1
2525+2626+2727+#include <stdio.h>
2828+2929+#include <drivers/char/char.h>
3030+3131+3232+typedef struct {
3333+ char_drv_t cdrv;
3434+3535+ char *name;
3636+ char *name_read;
3737+ char *name_write;
3838+3939+ int fd_read;
4040+ int fd_write;
4141+} char_posix_t;
4242+4343+4444+#endif