- Fix broken handling of order-only prereqs in secondary expansion
[make.git] / vmsfunctions.c
blob2c87cb72cd4c4173c2dd264e157573bdf9068a06
1 /* VMS functions
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
3 2007 Free Software Foundation, Inc.
4 This file is part of GNU Make.
6 GNU Make is free software; you can redistribute it and/or modify it under the
7 terms of the GNU General Public License as published by the Free Software
8 Foundation; either version 3 of the License, or (at your option) any later
9 version.
11 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along with
16 this program. If not, see <http://www.gnu.org/licenses/>. */
18 #include "make.h"
19 #include "debug.h"
20 #include "job.h"
22 #ifdef __DECC
23 #include <starlet.h>
24 #endif
25 #include <descrip.h>
26 #include <rms.h>
27 #include <iodef.h>
28 #include <atrdef.h>
29 #include <fibdef.h>
30 #include "vmsdir.h"
32 #ifdef HAVE_VMSDIR_H
34 DIR *
35 opendir (char *dspec)
37 struct DIR *dir = xcalloc (sizeof (struct DIR));
38 struct NAM *dnam = xmalloc (sizeof (struct NAM));
39 struct FAB *dfab = &dir->fab;
40 char *searchspec = xmalloc (MAXNAMLEN + 1);
42 *dfab = cc$rms_fab;
43 *dnam = cc$rms_nam;
44 sprintf (searchspec, "%s*.*;", dspec);
46 dfab->fab$l_fna = searchspec;
47 dfab->fab$b_fns = strlen (searchspec);
48 dfab->fab$l_nam = dnam;
50 *dnam = cc$rms_nam;
51 dnam->nam$l_esa = searchspec;
52 dnam->nam$b_ess = MAXNAMLEN;
54 if (! (sys$parse (dfab) & 1))
56 free (dir);
57 free (dnam);
58 free (searchspec);
59 return (NULL);
62 return dir;
65 #define uppercasify(str) \
66 do \
67 { \
68 char *tmp; \
69 for (tmp = (str); *tmp != '\0'; tmp++) \
70 if (islower ((unsigned char)*tmp)) \
71 *tmp = toupper ((unsigned char)*tmp); \
72 } \
73 while (0)
75 struct direct *
76 readdir (DIR *dir)
78 struct FAB *dfab = &dir->fab;
79 struct NAM *dnam = (struct NAM *)(dfab->fab$l_nam);
80 struct direct *dentry = &dir->dir;
81 int i;
83 memset (dentry, 0, sizeof *dentry);
85 dnam->nam$l_rsa = dir->d_result;
86 dnam->nam$b_rss = MAXNAMLEN;
88 DB (DB_VERBOSE, ("."));
90 if (!((i = sys$search (dfab)) & 1))
92 DB (DB_VERBOSE, (_("sys$search() failed with %d\n"), i));
93 return (NULL);
96 dentry->d_off = 0;
97 if (dnam->nam$w_fid == 0)
98 dentry->d_fileno = 1;
99 else
100 dentry->d_fileno = dnam->nam$w_fid[0] + (dnam->nam$w_fid[1] << 16);
102 dentry->d_reclen = sizeof (struct direct);
103 dentry->d_namlen = dnam->nam$b_name + dnam->nam$b_type;
104 strncpy (dentry->d_name, dnam->nam$l_name, dentry->d_namlen);
105 dentry->d_name[dentry->d_namlen] = '\0';
107 #ifdef HAVE_CASE_INSENSITIVE_FS
108 uppercasify (dentry->d_name);
109 #endif
111 return (dentry);
115 closedir (DIR *dir)
117 if (dir != NULL)
119 struct FAB *dfab = &dir->fab;
120 struct NAM *dnam = (struct NAM *)(dfab->fab$l_nam);
121 if (dnam != NULL)
122 free (dnam->nam$l_esa);
123 free (dnam);
124 free (dir);
127 return 0;
129 #endif /* compiled for OpenVMS prior to V7.x */
131 char *
132 getwd (char *cwd)
134 static char buf[512];
136 if (cwd)
137 return (getcwd (cwd, 512));
138 else
139 return (getcwd (buf, 512));
143 vms_stat (char *name, struct stat *buf)
145 int status;
146 int i;
148 static struct FAB Fab;
149 static struct NAM Nam;
150 static struct fibdef Fib; /* short fib */
151 static struct dsc$descriptor FibDesc =
152 { sizeof (Fib), DSC$K_DTYPE_Z, DSC$K_CLASS_S, (char *) &Fib };
153 static struct dsc$descriptor_s DevDesc =
154 { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, &Nam.nam$t_dvi[1] };
155 static char EName[NAM$C_MAXRSS];
156 static char RName[NAM$C_MAXRSS];
157 static struct dsc$descriptor_s FileName =
158 { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0 };
159 static struct dsc$descriptor_s string =
160 { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0 };
161 static unsigned long Rdate[2];
162 static unsigned long Cdate[2];
163 static struct atrdef Atr[] =
165 #if defined(VAX)
166 /* Revision date */
167 { sizeof (Rdate), ATR$C_REVDATE, (unsigned int) &Rdate[0] },
168 /* Creation date */
169 { sizeof (Cdate), ATR$C_CREDATE, (unsigned int) &Cdate[0] },
170 #else
171 /* Revision date */
172 { sizeof (Rdate), ATR$C_REVDATE, &Rdate[0] },
173 /* Creation date */
174 { sizeof (Cdate), ATR$C_CREDATE, &Cdate[0]},
175 #endif
176 { 0, 0, 0 }
178 static short int DevChan;
179 static short int iosb[4];
181 name = vmsify (name, 0);
183 /* initialize RMS structures, we need a NAM to retrieve the FID */
184 Fab = cc$rms_fab;
185 Fab.fab$l_fna = name; /* name of file */
186 Fab.fab$b_fns = strlen (name);
187 Fab.fab$l_nam = &Nam; /* FAB has an associated NAM */
189 Nam = cc$rms_nam;
190 Nam.nam$l_esa = EName; /* expanded filename */
191 Nam.nam$b_ess = sizeof (EName);
192 Nam.nam$l_rsa = RName; /* resultant filename */
193 Nam.nam$b_rss = sizeof (RName);
195 /* do $PARSE and $SEARCH here */
196 status = sys$parse (&Fab);
197 if (!(status & 1))
198 return -1;
200 DevDesc.dsc$w_length = Nam.nam$t_dvi[0];
201 status = sys$assign (&DevDesc, &DevChan, 0, 0);
202 if (!(status & 1))
203 return -1;
205 FileName.dsc$a_pointer = Nam.nam$l_name;
206 FileName.dsc$w_length = Nam.nam$b_name + Nam.nam$b_type + Nam.nam$b_ver;
208 /* Initialize the FIB */
209 for (i = 0; i < 3; i++)
211 #ifndef __VAXC
212 Fib.fib$w_fid[i] = Nam.nam$w_fid[i];
213 Fib.fib$w_did[i] = Nam.nam$w_did[i];
214 #else
215 Fib.fib$r_fid_overlay.fib$w_fid[i] = Nam.nam$w_fid[i];
216 Fib.fib$r_did_overlay.fib$w_did[i] = Nam.nam$w_did[i];
217 #endif
220 status = sys$qiow (0, DevChan, IO$_ACCESS, &iosb, 0, 0,
221 &FibDesc, &FileName, 0, 0, &Atr, 0);
222 sys$dassgn (DevChan);
223 if (!(status & 1))
224 return -1;
225 status = iosb[0];
226 if (!(status & 1))
227 return -1;
229 status = stat (name, buf);
230 if (status)
231 return -1;
233 buf->st_mtime = ((Rdate[0] >> 24) & 0xff) + ((Rdate[1] << 8) & 0xffffff00);
234 buf->st_ctime = ((Cdate[0] >> 24) & 0xff) + ((Cdate[1] << 8) & 0xffffff00);
236 return 0;
239 char *
240 cvt_time (unsigned long tval)
242 static long int date[2];
243 static char str[27];
244 static struct dsc$descriptor date_str =
245 { 26, DSC$K_DTYPE_T, DSC$K_CLASS_S, str };
247 date[0] = (tval & 0xff) << 24;
248 date[1] = ((tval >> 8) & 0xffffff);
250 if ((date[0] == 0) && (date[1] == 0))
251 return ("never");
253 sys$asctim (0, &date_str, date, 0);
254 str[26] = '\0';
256 return (str);