1 | /*
|
---|
2 | * gawkmisc.vms --- miscellanious gawk routines that are OS specific.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 1986, 1988, 1989, 1991-1996, 2003 the Free Software Foundation, Inc.
|
---|
7 | *
|
---|
8 | * This file is part of GAWK, the GNU implementation of the
|
---|
9 | * AWK Progamming Language.
|
---|
10 | *
|
---|
11 | * GAWK is free software; you can redistribute it and/or modify
|
---|
12 | * it under the terms of the GNU General Public License as published by
|
---|
13 | * the Free Software Foundation; either version 2 of the License, or
|
---|
14 | * (at your option) any later version.
|
---|
15 | *
|
---|
16 | * GAWK is distributed in the hope that it will be useful,
|
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | * GNU General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with this program; if not, write to the Free Software
|
---|
23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
---|
24 | */
|
---|
25 |
|
---|
26 | char quote = '\'';
|
---|
27 | char *defpath = DEFPATH;
|
---|
28 | char envsep = ',';
|
---|
29 |
|
---|
30 | /* gawk_name --- pull out the "gawk" part from how the OS called us */
|
---|
31 |
|
---|
32 | char *
|
---|
33 | gawk_name(filespec)
|
---|
34 | const char *filespec;
|
---|
35 | {
|
---|
36 | char *p, *q;
|
---|
37 |
|
---|
38 | /* "device:[root.][directory.subdir]GAWK.EXE;n" -> "GAWK" */
|
---|
39 | p = strrchr(filespec, ']'); /* directory punctuation */
|
---|
40 | q = strrchr(filespec, '>'); /* alternate <international> punct */
|
---|
41 |
|
---|
42 | if (p == NULL || q > p)
|
---|
43 | p = q;
|
---|
44 | p = strdup(p == NULL ? filespec : (p + 1));
|
---|
45 | if ((q = strrchr(p, '.')) != NULL)
|
---|
46 | *q = '\0'; /* strip .typ;vers */
|
---|
47 |
|
---|
48 | return p;
|
---|
49 | }
|
---|
50 |
|
---|
51 | /* os_arg_fixup --- fixup the command line */
|
---|
52 |
|
---|
53 | void
|
---|
54 | os_arg_fixup(argcp, argvp)
|
---|
55 | int *argcp;
|
---|
56 | char ***argvp;
|
---|
57 | {
|
---|
58 | (void) vms_arg_fixup(argcp, argvp);
|
---|
59 | }
|
---|
60 |
|
---|
61 | /* os_devopen --- open special per-OS devices */
|
---|
62 |
|
---|
63 | int
|
---|
64 | os_devopen(name, flag)
|
---|
65 | const char *name;
|
---|
66 | int flag;
|
---|
67 | {
|
---|
68 | return vms_devopen(name, flag);
|
---|
69 | }
|
---|
70 |
|
---|
71 | /* optimal_bufsize --- determine optimal buffer size */
|
---|
72 |
|
---|
73 | size_t
|
---|
74 | optimal_bufsize(fd, stb)
|
---|
75 | int fd;
|
---|
76 | struct stat *stb;
|
---|
77 | {
|
---|
78 |
|
---|
79 | /* force all members to zero in case OS doesn't use all of them. */
|
---|
80 | memset(stb, '\0', sizeof(struct stat));
|
---|
81 |
|
---|
82 | /*
|
---|
83 | * These values correspond with the RMS multi-block count used by
|
---|
84 | * vms_open() in vms/vms_misc.c.
|
---|
85 | */
|
---|
86 | if (isatty(fd) > 0)
|
---|
87 | return BUFSIZ;
|
---|
88 | else if (fstat(fd, stb) < 0)
|
---|
89 | return 8*512; /* conservative in case of DECnet access */
|
---|
90 | else
|
---|
91 | return 32*512;
|
---|
92 | }
|
---|
93 |
|
---|
94 | /* ispath --- return true if path has directory components */
|
---|
95 |
|
---|
96 | int
|
---|
97 | ispath(file)
|
---|
98 | const char *file;
|
---|
99 | {
|
---|
100 | for (; *file; file++) {
|
---|
101 | switch (*file) {
|
---|
102 | case ':':
|
---|
103 | case ']':
|
---|
104 | case '>':
|
---|
105 | case '/':
|
---|
106 | return 1;
|
---|
107 | }
|
---|
108 | }
|
---|
109 | return 0;
|
---|
110 | }
|
---|
111 |
|
---|
112 | /* isdirpunct --- return true if char is a directory separator */
|
---|
113 |
|
---|
114 | int
|
---|
115 | isdirpunct(c)
|
---|
116 | int c;
|
---|
117 | {
|
---|
118 | return (strchr(":]>/", c) != NULL);
|
---|
119 | }
|
---|
120 |
|
---|
121 | /* os_close_on_exec --- set close on exec flag, print warning if fails */
|
---|
122 |
|
---|
123 | void
|
---|
124 | os_close_on_exec(fd, name, what, dir)
|
---|
125 | int fd;
|
---|
126 | const char *name, *what, *dir;
|
---|
127 | {
|
---|
128 | /* no-op */
|
---|
129 | }
|
---|
130 |
|
---|
131 | /* os_isdir --- is this an fd on a directory? */
|
---|
132 |
|
---|
133 | #if ! defined(S_ISDIR) && defined(S_IFDIR)
|
---|
134 | #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
---|
135 | #endif
|
---|
136 |
|
---|
137 | int
|
---|
138 | os_isdir(fd)
|
---|
139 | int fd;
|
---|
140 | {
|
---|
141 | struct stat sbuf;
|
---|
142 |
|
---|
143 | return (fstat(fd, &sbuf) == 0 && S_ISDIR(sbuf.st_mode));
|
---|
144 | }
|
---|
145 |
|
---|
146 | /* os_is_setuid --- true if running setuid root */
|
---|
147 |
|
---|
148 | int
|
---|
149 | os_is_setuid()
|
---|
150 | {
|
---|
151 | return 0;
|
---|
152 | }
|
---|
153 |
|
---|
154 | /* os_setbinmode --- set binary mode on file */
|
---|
155 |
|
---|
156 | int
|
---|
157 | os_setbinmode (fd, mode)
|
---|
158 | int fd, mode;
|
---|
159 | {
|
---|
160 | return 0;
|
---|
161 | }
|
---|
162 |
|
---|
163 | /* os_restore_mode --- restore the original mode of the console device */
|
---|
164 |
|
---|
165 | void
|
---|
166 | os_restore_mode (fd)
|
---|
167 | int fd;
|
---|
168 | {
|
---|
169 | /* no-op */
|
---|
170 | return;
|
---|
171 | }
|
---|