VirtualBox

source: kBuild/vendor/gnumake/2005-05-16/vmsfunctions.c

Last change on this file was 280, checked in by bird, 20 years ago

Current make snaphot, 2005-05-16.

  • Property svn:eol-style set to native
File size: 5.6 KB
Line 
1/* vmsfunctions.c */
2
3#include "make.h"
4#include "debug.h"
5#include "job.h"
6
7#ifdef __DECC
8#include <starlet.h>
9#endif
10#include <descrip.h>
11#include <rms.h>
12#include <iodef.h>
13#include <atrdef.h>
14#include <fibdef.h>
15#include "vmsdir.h"
16
17#ifdef HAVE_VMSDIR_H
18
19DIR *
20opendir (char *dspec)
21{
22 struct DIR *dir = (struct DIR *)xmalloc (sizeof (struct DIR));
23 struct NAM *dnam = (struct NAM *)xmalloc (sizeof (struct NAM));
24 struct FAB *dfab = &dir->fab;
25 char *searchspec = (char *)xmalloc (MAXNAMLEN + 1);
26
27 memset (dir, 0, sizeof *dir);
28
29 *dfab = cc$rms_fab;
30 *dnam = cc$rms_nam;
31 sprintf (searchspec, "%s*.*;", dspec);
32
33 dfab->fab$l_fna = searchspec;
34 dfab->fab$b_fns = strlen (searchspec);
35 dfab->fab$l_nam = dnam;
36
37 *dnam = cc$rms_nam;
38 dnam->nam$l_esa = searchspec;
39 dnam->nam$b_ess = MAXNAMLEN;
40
41 if (! (sys$parse (dfab) & 1))
42 {
43 free (dir);
44 free (dnam);
45 free (searchspec);
46 return (NULL);
47 }
48
49 return dir;
50}
51
52#define uppercasify(str) \
53 do \
54 { \
55 char *tmp; \
56 for (tmp = (str); *tmp != '\0'; tmp++) \
57 if (islower ((unsigned char)*tmp)) \
58 *tmp = toupper ((unsigned char)*tmp); \
59 } \
60 while (0)
61
62struct direct *
63readdir (DIR *dir)
64{
65 struct FAB *dfab = &dir->fab;
66 struct NAM *dnam = (struct NAM *)(dfab->fab$l_nam);
67 struct direct *dentry = &dir->dir;
68 int i;
69
70 memset (dentry, 0, sizeof *dentry);
71
72 dnam->nam$l_rsa = dir->d_result;
73 dnam->nam$b_rss = MAXNAMLEN;
74
75 DB (DB_VERBOSE, ("."));
76
77 if (!((i = sys$search (dfab)) & 1))
78 {
79 DB (DB_VERBOSE, (_("sys$search failed with %d\n"), i));
80 return (NULL);
81 }
82
83 dentry->d_off = 0;
84 if (dnam->nam$w_fid == 0)
85 dentry->d_fileno = 1;
86 else
87 dentry->d_fileno = dnam->nam$w_fid[0] + (dnam->nam$w_fid[1] << 16);
88
89 dentry->d_reclen = sizeof (struct direct);
90 dentry->d_namlen = dnam->nam$b_name + dnam->nam$b_type;
91 strncpy (dentry->d_name, dnam->nam$l_name, dentry->d_namlen);
92 dentry->d_name[dentry->d_namlen] = '\0';
93 uppercasify (dentry->d_name);
94
95 return (dentry);
96}
97
98int
99closedir (DIR *dir)
100{
101 if (dir != NULL)
102 {
103 struct FAB *dfab = &dir->fab;
104 struct NAM *dnam = (struct NAM *)(dfab->fab$l_nam);
105 if (dnam != NULL)
106 free (dnam->nam$l_esa);
107 free (dnam);
108 free (dir);
109 }
110
111 return 0;
112}
113#endif /* compiled for OpenVMS prior to V7.x */
114
115char *
116getwd (char *cwd)
117{
118 static char buf[512];
119
120 if (cwd)
121 return (getcwd (cwd, 512));
122 else
123 return (getcwd (buf, 512));
124}
125
126int
127vms_stat (char *name, struct stat *buf)
128{
129 int status;
130 int i;
131
132 static struct FAB Fab;
133 static struct NAM Nam;
134 static struct fibdef Fib; /* short fib */
135 static struct dsc$descriptor FibDesc =
136 { sizeof (Fib), DSC$K_DTYPE_Z, DSC$K_CLASS_S, (char *) &Fib };
137 static struct dsc$descriptor_s DevDesc =
138 { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, &Nam.nam$t_dvi[1] };
139 static char EName[NAM$C_MAXRSS];
140 static char RName[NAM$C_MAXRSS];
141 static struct dsc$descriptor_s FileName =
142 { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0 };
143 static struct dsc$descriptor_s string =
144 { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0 };
145 static unsigned long Rdate[2];
146 static unsigned long Cdate[2];
147 static struct atrdef Atr[] =
148 {
149#if defined(VAX)
150 /* Revision date */
151 { sizeof (Rdate), ATR$C_REVDATE, (unsigned int) &Rdate[0] },
152 /* Creation date */
153 { sizeof (Cdate), ATR$C_CREDATE, (unsigned int) &Cdate[0] },
154#else
155 /* Revision date */
156 { sizeof (Rdate), ATR$C_REVDATE, &Rdate[0] },
157 /* Creation date */
158 { sizeof (Cdate), ATR$C_CREDATE, &Cdate[0]},
159#endif
160 { 0, 0, 0 }
161 };
162 static short int DevChan;
163 static short int iosb[4];
164
165 name = vmsify (name, 0);
166
167 /* initialize RMS structures, we need a NAM to retrieve the FID */
168 Fab = cc$rms_fab;
169 Fab.fab$l_fna = name; /* name of file */
170 Fab.fab$b_fns = strlen (name);
171 Fab.fab$l_nam = &Nam; /* FAB has an associated NAM */
172
173 Nam = cc$rms_nam;
174 Nam.nam$l_esa = EName; /* expanded filename */
175 Nam.nam$b_ess = sizeof (EName);
176 Nam.nam$l_rsa = RName; /* resultant filename */
177 Nam.nam$b_rss = sizeof (RName);
178
179 /* do $PARSE and $SEARCH here */
180 status = sys$parse (&Fab);
181 if (!(status & 1))
182 return -1;
183
184 DevDesc.dsc$w_length = Nam.nam$t_dvi[0];
185 status = sys$assign (&DevDesc, &DevChan, 0, 0);
186 if (!(status & 1))
187 return -1;
188
189 FileName.dsc$a_pointer = Nam.nam$l_name;
190 FileName.dsc$w_length = Nam.nam$b_name + Nam.nam$b_type + Nam.nam$b_ver;
191
192 /* Initialize the FIB */
193 for (i = 0; i < 3; i++)
194 {
195#ifndef __VAXC
196 Fib.fib$w_fid[i] = Nam.nam$w_fid[i];
197 Fib.fib$w_did[i] = Nam.nam$w_did[i];
198#else
199 Fib.fib$r_fid_overlay.fib$w_fid[i] = Nam.nam$w_fid[i];
200 Fib.fib$r_did_overlay.fib$w_did[i] = Nam.nam$w_did[i];
201#endif
202 }
203
204 status = sys$qiow (0, DevChan, IO$_ACCESS, &iosb, 0, 0,
205 &FibDesc, &FileName, 0, 0, &Atr, 0);
206 sys$dassgn (DevChan);
207 if (!(status & 1))
208 return -1;
209 status = iosb[0];
210 if (!(status & 1))
211 return -1;
212
213 status = stat (name, buf);
214 if (status)
215 return -1;
216
217 buf->st_mtime = ((Rdate[0] >> 24) & 0xff) + ((Rdate[1] << 8) & 0xffffff00);
218 buf->st_ctime = ((Cdate[0] >> 24) & 0xff) + ((Cdate[1] << 8) & 0xffffff00);
219
220 return 0;
221}
222
223char *
224cvt_time (unsigned long tval)
225{
226 static long int date[2];
227 static char str[27];
228 static struct dsc$descriptor date_str =
229 { 26, DSC$K_DTYPE_T, DSC$K_CLASS_S, str };
230
231 date[0] = (tval & 0xff) << 24;
232 date[1] = ((tval >> 8) & 0xffffff);
233
234 if ((date[0] == 0) && (date[1] == 0))
235 return ("never");
236
237 sys$asctim (0, &date_str, date, 0);
238 str[26] = '\0';
239
240 return (str);
241}
242
243int
244strcmpi (const char *s1, const char *s2)
245{
246 while (*s1 != '\0' && toupper(*s1) == toupper(*s2))
247 {
248 s1++;
249 s2++;
250 }
251
252 return toupper(*(unsigned char *) s1) - toupper(*(unsigned char *) s2);
253}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette