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);
26 memset (dir
, 0, sizeof *dir
);
30 sprintf (searchspec
, "%s*.*;", dspec
);
32 dfab
->fab$l_fna
= searchspec
;
33 dfab
->fab$b_fns
= strlen (searchspec
);
34 dfab
->fab$l_nam
= dnam
;
37 dnam
->nam$l_esa
= searchspec
;
38 dnam
->nam$b_ess
= MAXNAMLEN
;
40 if (! (sys$
parse (dfab
) & 1))
51 #define uppercasify(str) \
55 for (tmp = (str); *tmp != '\0'; tmp++) \
56 if (islower ((unsigned char)*tmp)) \
57 *tmp = toupper ((unsigned char)*tmp); \
64 struct FAB
*dfab
= &dir
->fab
;
65 struct NAM
*dnam
= (struct NAM
*)(dfab
->fab$l_nam
);
66 struct direct
*dentry
= &dir
->dir
;
69 memset (dentry
, 0, sizeof *dentry
);
71 dnam
->nam$l_rsa
= dir
->d_result
;
72 dnam
->nam$b_rss
= MAXNAMLEN
;
74 DB (DB_VERBOSE
, ("."));
76 if (!((i
= sys$
search (dfab
)) & 1))
78 DB (DB_VERBOSE
, (_("sys$search failed with %d\n"), i
));
83 if (dnam
->nam$w_fid
== 0)
86 dentry
->d_fileno
= dnam
->nam$w_fid
[0] + (dnam
->nam$w_fid
[1] << 16);
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
);
102 struct FAB
*dfab
= &dir
->fab
;
103 struct NAM
*dnam
= (struct NAM
*)(dfab
->fab$l_nam
);
105 free (dnam
->nam$l_esa
);
112 #endif /* compiled for OpenVMS prior to V7.x */
117 static char buf
[512];
120 return (getcwd (cwd
, 512));
122 return (getcwd (buf
, 512));
126 vms_stat (char *name
, struct stat
*buf
)
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
[] =
150 { sizeof (Rdate
), ATR$C_REVDATE
, (unsigned int) &Rdate
[0] },
152 { sizeof (Cdate
), ATR$C_CREDATE
, (unsigned int) &Cdate
[0] },
155 { sizeof (Rdate
), ATR$C_REVDATE
, &Rdate
[0] },
157 { sizeof (Cdate
), ATR$C_CREDATE
, &Cdate
[0]},
161 static short int DevChan
;
162 static short int iosb
[4];
164 name
= vmsify (name
, 0);
166 /* initialize RMS structures, we need a NAM to retrieve the FID */
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 */
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
);
178 /* do $PARSE and $SEARCH here */
179 status
= sys$
parse (&Fab
);
183 DevDesc
.dsc$w_length
= Nam
.nam$t_dvi
[0];
184 status
= sys$
assign (&DevDesc
, &DevChan
, 0, 0);
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
;
191 /* Initialize the FIB */
192 for (i
= 0; i
< 3; i
++)
195 Fib
.fib$w_fid
[i
] = Nam
.nam$w_fid
[i
];
196 Fib
.fib$w_did
[i
] = Nam
.nam$w_did
[i
];
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
];
203 status
= sys$
qiow (0, DevChan
, IO$_ACCESS
, &iosb
, 0, 0,
204 &FibDesc
, &FileName
, 0, 0, &Atr
, 0);
205 sys$
dassgn (DevChan
);
212 status
= stat (name
, buf
);
216 buf
->st_mtime
= ((Rdate
[0] >> 24) & 0xff) + ((Rdate
[1] << 8) & 0xffffff00);
217 buf
->st_ctime
= ((Cdate
[0] >> 24) & 0xff) + ((Cdate
[1] << 8) & 0xffffff00);
223 cvt_time (unsigned long tval
)
225 static long int date
[2];
227 static struct dsc$descriptor date_str
=
228 { 26, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, str
};
230 date
[0] = (tval
& 0xff) << 24;
231 date
[1] = ((tval
>> 8) & 0xffffff);
233 if ((date
[0] == 0) && (date
[1] == 0))
236 sys$
asctim (0, &date_str
, date
, 0);
243 strcmpi (const char *s1
, const char *s2
)
245 while (*s1
!= '\0' && toupper(*s1
) == toupper(*s2
))
251 return toupper(*(unsigned char *) s1
) - toupper(*(unsigned char *) s2
);