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);
27 memset (dir
, 0, sizeof *dir
);
31 sprintf (searchspec
, "%s*.*;", dspec
);
33 dfab
->fab$l_fna
= searchspec
;
34 dfab
->fab$b_fns
= strlen (searchspec
);
35 dfab
->fab$l_nam
= dnam
;
38 dnam
->nam$l_esa
= searchspec
;
39 dnam
->nam$b_ess
= MAXNAMLEN
;
41 if (! (sys$
parse (dfab
) & 1))
52 #define uppercasify(str) \
56 for (tmp = (str); *tmp != '\0'; tmp++) \
57 if (islower ((unsigned char)*tmp)) \
58 *tmp = toupper ((unsigned char)*tmp); \
65 struct FAB
*dfab
= &dir
->fab
;
66 struct NAM
*dnam
= (struct NAM
*)(dfab
->fab$l_nam
);
67 struct direct
*dentry
= &dir
->dir
;
70 memset (dentry
, 0, sizeof *dentry
);
72 dnam
->nam$l_rsa
= dir
->d_result
;
73 dnam
->nam$b_rss
= MAXNAMLEN
;
75 DB (DB_VERBOSE
, ("."));
77 if (!((i
= sys$
search (dfab
)) & 1))
79 DB (DB_VERBOSE
, (_("sys$search failed with %d\n"), i
));
84 if (dnam
->nam$w_fid
== 0)
87 dentry
->d_fileno
= dnam
->nam$w_fid
[0] + (dnam
->nam$w_fid
[1] << 16);
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
);
103 struct FAB
*dfab
= &dir
->fab
;
104 struct NAM
*dnam
= (struct NAM
*)(dfab
->fab$l_nam
);
106 free (dnam
->nam$l_esa
);
113 #endif /* compiled for OpenVMS prior to V7.x */
118 static char buf
[512];
121 return (getcwd (cwd
, 512));
123 return (getcwd (buf
, 512));
127 vms_stat (char *name
, struct stat
*buf
)
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
[] =
151 { sizeof (Rdate
), ATR$C_REVDATE
, (unsigned int) &Rdate
[0] },
153 { sizeof (Cdate
), ATR$C_CREDATE
, (unsigned int) &Cdate
[0] },
156 { sizeof (Rdate
), ATR$C_REVDATE
, &Rdate
[0] },
158 { sizeof (Cdate
), ATR$C_CREDATE
, &Cdate
[0]},
162 static short int DevChan
;
163 static short int iosb
[4];
165 name
= vmsify (name
, 0);
167 /* initialize RMS structures, we need a NAM to retrieve the FID */
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 */
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
);
179 /* do $PARSE and $SEARCH here */
180 status
= sys$
parse (&Fab
);
184 DevDesc
.dsc$w_length
= Nam
.nam$t_dvi
[0];
185 status
= sys$
assign (&DevDesc
, &DevChan
, 0, 0);
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
;
192 /* Initialize the FIB */
193 for (i
= 0; i
< 3; i
++)
196 Fib
.fib$w_fid
[i
] = Nam
.nam$w_fid
[i
];
197 Fib
.fib$w_did
[i
] = Nam
.nam$w_did
[i
];
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
];
204 status
= sys$
qiow (0, DevChan
, IO$_ACCESS
, &iosb
, 0, 0,
205 &FibDesc
, &FileName
, 0, 0, &Atr
, 0);
206 sys$
dassgn (DevChan
);
213 status
= stat (name
, buf
);
217 buf
->st_mtime
= ((Rdate
[0] >> 24) & 0xff) + ((Rdate
[1] << 8) & 0xffffff00);
218 buf
->st_ctime
= ((Cdate
[0] >> 24) & 0xff) + ((Cdate
[1] << 8) & 0xffffff00);
224 cvt_time (unsigned long tval
)
226 static long int date
[2];
228 static struct dsc$descriptor date_str
=
229 { 26, DSC$K_DTYPE_T
, DSC$K_CLASS_S
, str
};
231 date
[0] = (tval
& 0xff) << 24;
232 date
[1] = ((tval
>> 8) & 0xffffff);
234 if ((date
[0] == 0) && (date
[1] == 0))
237 sys$
asctim (0, &date_str
, date
, 0);
244 strcmpi (const char *s1
, const char *s2
)
246 while (*s1
!= '\0' && toupper(*s1
) == toupper(*s2
))
252 return toupper(*(unsigned char *) s1
) - toupper(*(unsigned char *) s2
);