xref: /plan9/sys/src/ape/lib/ap/plan9/lib.h (revision e44fe4caf8cb96c0069297b4860a31c955b8f9fd)
1 #include <sys/types.h>
2 #include <sys/limits.h>
3 #include <fcntl.h>
4 #include <ureg.h>
5 
6 typedef struct Ureg Ureg;
7 
8 /* mux buf for selecting (see _buf.c) */
9 enum {
10 	READMAX = 8192,			/* read at most this much with _READ */
11 	PERFDMAX = 2*READMAX,		/* stop _READing an fd when it has this much */
12 	INITBUFS = 4,			/* allow enough room for this many PERFDMAX */
13 };
14 
15 typedef struct Muxbuf {
16 	int n;				/* # unprocessed chars in buf */
17 	unsigned char*	putnext;	/* place for copy process to put next data */
18 	unsigned char*	getnext;	/* place for parent process to get next data */
19 	char		fd;		/* fd for which this is a buffer */
20 	unsigned char	eof;		/* true if eof after current data exhausted */
21 	unsigned char	roomwait;	/* true if copy process is waiting for room */
22 	unsigned char	datawait;	/* true if parent process is waiting for data */
23 	int		copypid;	/* pid of copyproc */
24 	unsigned char	data[PERFDMAX];
25 } Muxbuf;
26 
27 /* be sure to change _fdinfo[] init in _fdinfo if you change this */
28 typedef struct Fdinfo{
29 	unsigned long	flags;
30 	unsigned long	oflags;
31 	uid_t	uid;
32 	gid_t	gid;
33 	char		*name;
34 	/*
35 	 * the following is used if flags&FD_BUFFERED
36 	 */
37 	Muxbuf	*buf;	/* holds buffered data and state */
38 } Fdinfo;
39 
40 /* #define FD_CLOEXEC 1 is in fcntl.h */
41 
42 #define FD_ISOPEN	0x2
43 #define FD_BUFFERED	0x4
44 #define FD_BUFFEREDX	0x8
45 #define FD_ISTTY	0x20
46 
47 #define MAXSIG SIGUSR2
48 
49 extern Fdinfo	_fdinfo[];
50 
51 extern int	_finishing;
52 extern int	_sessleader;
53 extern void	(*_sighdlr[])(int, char*, Ureg*);
54 extern char	*_sigstring(int);
55 extern int	_stringsig(char *);
56 extern long	_psigblocked;
57 extern int	_startbuf(int);
58 extern int	_selbuf(int);
59 extern void	_closebuf(int);
60 extern int _readbuf(int, void*, int, int);
61 extern void	_detachbuf(void);
62 extern void	_finish(int, char *);
63 extern char	*_ultoa(char *, unsigned long);
64 extern int	_notehandler(void *, char *);
65 extern void	_notetramp(int, void (*)(int, char*, Ureg*), Ureg*);
66 extern void	_syserrno(void);
67 extern int	_getpw(int *, char **, char **);
68 extern int _isatty(int);
69 extern void _fdinit(char*, char*);
70 
71 
72 void checkbug(char *, int);
73