source: trunk/essentials/sys-apps/gawk/vms/gawkmisc.vms

Last change on this file was 3076, checked in by bird, 18 years ago

gawk 3.1.5

File size: 3.4 KB
Line 
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
26char quote = '\'';
27char *defpath = DEFPATH;
28char envsep = ',';
29
30/* gawk_name --- pull out the "gawk" part from how the OS called us */
31
32char *
33gawk_name(filespec)
34const 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
53void
54os_arg_fixup(argcp, argvp)
55int *argcp;
56char ***argvp;
57{
58 (void) vms_arg_fixup(argcp, argvp);
59}
60
61/* os_devopen --- open special per-OS devices */
62
63int
64os_devopen(name, flag)
65const char *name;
66int flag;
67{
68 return vms_devopen(name, flag);
69}
70
71/* optimal_bufsize --- determine optimal buffer size */
72
73size_t
74optimal_bufsize(fd, stb)
75int fd;
76struct 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
96int
97ispath(file)
98const 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
114int
115isdirpunct(c)
116int c;
117{
118 return (strchr(":]>/", c) != NULL);
119}
120
121/* os_close_on_exec --- set close on exec flag, print warning if fails */
122
123void
124os_close_on_exec(fd, name, what, dir)
125int fd;
126const 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
137int
138os_isdir(fd)
139int 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
148int
149os_is_setuid()
150{
151 return 0;
152}
153
154/* os_setbinmode --- set binary mode on file */
155
156int
157os_setbinmode (fd, mode)
158int fd, mode;
159{
160 return 0;
161}
162
163/* os_restore_mode --- restore the original mode of the console device */
164
165void
166os_restore_mode (fd)
167int fd;
168{
169 /* no-op */
170 return;
171}
Note: See TracBrowser for help on using the repository browser.