xref: /illumos-gate/usr/src/contrib/ast/src/cmd/ksh93/include/io.h (revision b30d193948be5a7794d7ae3ba0ed9c2f72c88e0f)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1982-2012 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                 Eclipse Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *          http://www.eclipse.org/org/documents/epl-v10.html           *
11 *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                  David Korn <dgk@research.att.com>                   *
18 *                                                                      *
19 ***********************************************************************/
20 #pragma prototyped
21 /*
22  *	UNIX shell
23  *	David Korn
24  *
25  */
26 /*
27  * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
28  */
29 
30 #include	<ast.h>
31 #include	<sfio.h>
32 
33 #ifndef IOBSIZE
34 #   define  IOBSIZE	(SF_BUFSIZE*sizeof(char*))
35 #endif /* IOBSIZE */
36 #define IOMAXTRY	20
37 
38 #ifndef SF_CLOSING
39 #define SF_CLOSING	SF_CLOSE
40 #endif
41 #ifndef SF_APPENDWR
42 #define SF_APPENDWR	SF_APPEND
43 #endif
44 
45 /* used for output of shell errors */
46 #define ERRIO		2
47 
48 #define IOREAD		001
49 #define IOWRITE		002
50 #define IODUP 		004
51 #define IOSEEK		010
52 #define IONOSEEK	020
53 #define IOTTY 		040
54 #define IOCLEX 		0100
55 #define IOCLOSE		(IOSEEK|IONOSEEK)
56 
57 #define IOSUBSHELL	0x8000	/* must be larger than any file descriptor */
58 #define IOPICKFD	0x10000 /* file descriptor number was selected automatically */
59 #define IOHERESTRING	0x20000 /* allow here documents to be string streams */
60 
61 /*
62  * The remainder of this file is only used when compiled with shell
63  */
64 
65 #if KSHELL
66 
67 #ifndef ARG_RAW
68     struct ionod;
69 #endif /* !ARG_RAW */
70 
71 extern int	sh_iocheckfd(Shell_t*,int);
72 extern void 	sh_ioinit(Shell_t*);
73 extern int 	sh_iomovefd(int);
74 extern int	sh_iorenumber(Shell_t*,int,int);
75 extern void 	sh_pclose(int[]);
76 extern int	sh_rpipe(int[]);
77 extern void 	sh_iorestore(Shell_t*,int,int);
78 #if defined(__EXPORT__) && defined(_BLD_DLL) && defined(_BLD_shell)
79    __EXPORT__
80 #endif
81 extern Sfio_t 	*sh_iostream(Shell_t*,int);
82 extern int	sh_redirect(Shell_t*,struct ionod*,int);
83 extern void 	sh_iosave(Shell_t *, int,int,char*);
84 extern int	sh_get_unused_fd(Shell_t* shp, int min_fd);
85 extern int 	sh_iovalidfd(Shell_t*, int);
86 extern int 	sh_inuse(Shell_t*, int);
87 extern void 	sh_iounsave(Shell_t*);
88 extern int	sh_chkopen(const char*);
89 extern int	sh_ioaccess(int,int);
90 extern int	sh_devtofd(const char*);
91 extern int	sh_isdevfd(const char*);
92 extern int	sh_source(Shell_t*, Sfio_t*, const char*);
93 
94 extern int	VALIDATE_FD(Shell_t *, int);
95 
96 #define	VALIDATE_FD(shp, fd) \
97 	(((fd) >= (shp)->gd->lim.open_max) ? sh_iovalidfd(shp, fd) : 1)
98 
99 
100 /* the following are readonly */
101 extern const char	e_pexists[];
102 extern const char	e_query[];
103 extern const char	e_history[];
104 extern const char	e_argtype[];
105 extern const char	e_create[];
106 extern const char	e_tmpcreate[];
107 extern const char	e_exists[];
108 extern const char	e_file[];
109 extern const char	e_redirect[];
110 extern const char	e_formspec[];
111 extern const char	e_badregexp[];
112 extern const char	e_open[];
113 extern const char	e_notseek[];
114 extern const char	e_noread[];
115 extern const char	e_badseek[];
116 extern const char	e_badwrite[];
117 extern const char	e_badpattern[];
118 extern const char	e_toomany[];
119 extern const char	e_pipe[];
120 extern const char	e_unknown[];
121 extern const char	e_devnull[];
122 extern const char	e_profile[];
123 extern const char	e_sysprofile[];
124 #if SHOPT_SYSRC
125 extern const char	e_sysrc[];
126 #endif
127 #if SHOPT_BASH
128 #if SHOPT_SYSRC
129 extern const char	e_bash_sysrc[];
130 #endif
131 extern const char	e_bash_rc[];
132 extern const char	e_bash_login[];
133 extern const char	e_bash_logout[];
134 extern const char	e_bash_profile[];
135 #endif
136 extern const char	e_stdprompt[];
137 extern const char	e_supprompt[];
138 extern const char	e_ambiguous[];
139 
140 #endif /* KSHELL */
141