VirtualBox

source: kBuild/vendor/gnumake/3.81-beta1/vmsfunctions.c

Last change on this file was 54, checked in by (none), 21 years ago

This commit was manufactured by cvs2svn to create branch 'GNU'.

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