1996-03-20 14:57:41 +00:00
|
|
|
/* vmsfunctions.c */
|
|
|
|
|
|
|
|
#include "make.h"
|
1999-11-22 06:15:35 +00:00
|
|
|
#include "debug.h"
|
|
|
|
|
1996-03-20 14:57:41 +00:00
|
|
|
#ifdef __DECC
|
|
|
|
#include <starlet.h>
|
|
|
|
#endif
|
|
|
|
#include <descrip.h>
|
|
|
|
#include <rms.h>
|
|
|
|
#include <iodef.h>
|
|
|
|
#include <atrdef.h>
|
|
|
|
#include <fibdef.h>
|
|
|
|
#include "vmsdir.h"
|
|
|
|
|
2000-01-22 05:59:28 +00:00
|
|
|
#ifdef HAVE_VMSDIR_H
|
1998-07-30 20:54:47 +00:00
|
|
|
|
|
|
|
DIR *
|
|
|
|
opendir (dspec)
|
|
|
|
char *dspec;
|
1996-03-20 14:57:41 +00:00
|
|
|
{
|
2000-01-22 05:43:03 +00:00
|
|
|
struct DIR *dir = (struct DIR *)xmalloc (sizeof (struct DIR));
|
|
|
|
struct NAM *dnam = (struct NAM *)xmalloc (sizeof (struct NAM));
|
|
|
|
struct FAB *dfab = &dir->fab;
|
|
|
|
char *searchspec = (char *)xmalloc (MAXNAMLEN + 1);
|
1998-07-30 20:54:47 +00:00
|
|
|
|
2000-01-22 05:43:03 +00:00
|
|
|
memset (dir, 0, sizeof *dir);
|
1998-07-30 20:54:47 +00:00
|
|
|
|
2000-01-22 05:43:03 +00:00
|
|
|
*dfab = cc$rms_fab;
|
|
|
|
*dnam = cc$rms_nam;
|
1998-07-30 20:54:47 +00:00
|
|
|
sprintf (searchspec, "%s*.*;", dspec);
|
1996-03-20 14:57:41 +00:00
|
|
|
|
|
|
|
dfab->fab$l_fna = searchspec;
|
1998-07-30 20:54:47 +00:00
|
|
|
dfab->fab$b_fns = strlen (searchspec);
|
1996-03-20 14:57:41 +00:00
|
|
|
dfab->fab$l_nam = dnam;
|
|
|
|
|
|
|
|
*dnam = cc$rms_nam;
|
|
|
|
dnam->nam$l_esa = searchspec;
|
|
|
|
dnam->nam$b_ess = MAXNAMLEN;
|
|
|
|
|
1998-07-30 20:54:47 +00:00
|
|
|
if (! (sys$parse (dfab) & 1))
|
|
|
|
{
|
2000-01-22 05:43:03 +00:00
|
|
|
free (dir);
|
1998-07-30 20:54:47 +00:00
|
|
|
free (dnam);
|
|
|
|
free (searchspec);
|
|
|
|
return (NULL);
|
|
|
|
}
|
1996-03-20 14:57:41 +00:00
|
|
|
|
2000-01-22 05:43:03 +00:00
|
|
|
return dir;
|
1996-03-20 14:57:41 +00:00
|
|
|
}
|
|
|
|
|
1998-07-30 20:54:47 +00:00
|
|
|
#define uppercasify(str) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
char *tmp; \
|
|
|
|
for (tmp = (str); *tmp != '\0'; tmp++) \
|
1999-10-15 07:00:58 +00:00
|
|
|
if (islower ((unsigned char)*tmp)) \
|
|
|
|
*tmp = toupper ((unsigned char)*tmp); \
|
1998-07-30 20:54:47 +00:00
|
|
|
} \
|
|
|
|
while (0)
|
|
|
|
|
|
|
|
struct direct *
|
2000-01-22 05:43:03 +00:00
|
|
|
readdir (dir)
|
|
|
|
DIR * dir;
|
1996-03-20 14:57:41 +00:00
|
|
|
{
|
2000-01-22 05:43:03 +00:00
|
|
|
struct FAB *dfab = &dir->fab;
|
|
|
|
struct NAM *dnam = (struct NAM *)(dfab->fab$l_nam);
|
|
|
|
struct direct *dentry = &dir->dir;
|
1996-03-20 14:57:41 +00:00
|
|
|
int i;
|
|
|
|
|
2000-01-22 05:43:03 +00:00
|
|
|
memset (dentry, 0, sizeof *dentry);
|
1996-03-20 14:57:41 +00:00
|
|
|
|
2000-01-22 05:43:03 +00:00
|
|
|
dnam->nam$l_rsa = dir->d_result;
|
|
|
|
dnam->nam$b_rss = MAXNAMLEN;
|
1996-03-20 14:57:41 +00:00
|
|
|
|
2000-02-05 07:50:47 +00:00
|
|
|
DB (DB_VERBOSE, ("."));
|
1996-03-20 14:57:41 +00:00
|
|
|
|
2000-01-22 05:43:03 +00:00
|
|
|
if (!((i = sys$search (dfab)) & 1))
|
1998-07-30 20:54:47 +00:00
|
|
|
{
|
2000-02-05 07:50:47 +00:00
|
|
|
DB (DB_VERBOSE, (_("sys$search failed with %d\n"), i));
|
1998-07-30 20:54:47 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
1996-03-20 14:57:41 +00:00
|
|
|
|
|
|
|
dentry->d_off = 0;
|
2000-01-22 05:43:03 +00:00
|
|
|
if (dnam->nam$w_fid == 0)
|
1996-03-20 14:57:41 +00:00
|
|
|
dentry->d_fileno = 1;
|
1998-07-30 20:54:47 +00:00
|
|
|
else
|
2000-01-22 05:43:03 +00:00
|
|
|
dentry->d_fileno = dnam->nam$w_fid[0] + (dnam->nam$w_fid[1] << 16);
|
|
|
|
|
1996-03-20 14:57:41 +00:00
|
|
|
dentry->d_reclen = sizeof (struct direct);
|
2000-01-22 05:43:03 +00:00
|
|
|
dentry->d_namlen = dnam->nam$b_name + dnam->nam$b_type;
|
|
|
|
strncpy (dentry->d_name, dnam->nam$l_name, dentry->d_namlen);
|
1996-03-20 14:57:41 +00:00
|
|
|
dentry->d_name[dentry->d_namlen] = '\0';
|
1998-07-30 20:54:47 +00:00
|
|
|
uppercasify (dentry->d_name);
|
1996-03-20 14:57:41 +00:00
|
|
|
|
1998-07-30 20:54:47 +00:00
|
|
|
return (dentry);
|
1996-03-20 14:57:41 +00:00
|
|
|
}
|
|
|
|
|
2000-01-22 05:43:03 +00:00
|
|
|
int
|
|
|
|
closedir (dir)
|
|
|
|
DIR *dir;
|
1996-03-20 14:57:41 +00:00
|
|
|
{
|
2000-01-22 05:43:03 +00:00
|
|
|
if (dir != NULL)
|
1998-07-30 20:54:47 +00:00
|
|
|
{
|
2000-01-22 05:43:03 +00:00
|
|
|
struct FAB *dfab = &dir->fab;
|
|
|
|
struct NAM *dnam = (struct NAM *)(dfab->fab$l_nam);
|
|
|
|
if (dnam != NULL)
|
|
|
|
free (dnam->nam$l_esa);
|
|
|
|
free (dnam);
|
|
|
|
free (dir);
|
1998-07-30 20:54:47 +00:00
|
|
|
}
|
2000-01-22 05:43:03 +00:00
|
|
|
|
|
|
|
return 0;
|
1996-03-20 14:57:41 +00:00
|
|
|
}
|
1998-07-30 20:54:47 +00:00
|
|
|
#endif /* compiled for OpenVMS prior to V7.x */
|
1996-03-20 14:57:41 +00:00
|
|
|
|
1998-07-30 20:54:47 +00:00
|
|
|
char *
|
|
|
|
getwd (cwd)
|
|
|
|
char *cwd;
|
1996-03-20 14:57:41 +00:00
|
|
|
{
|
|
|
|
static char buf[512];
|
|
|
|
|
1998-07-30 20:54:47 +00:00
|
|
|
if (cwd)
|
|
|
|
return (getcwd (cwd, 512));
|
|
|
|
else
|
|
|
|
return (getcwd (buf, 512));
|
1996-03-20 14:57:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
vms_stat (name, buf)
|
|
|
|
char *name;
|
|
|
|
struct stat *buf;
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
static struct FAB Fab;
|
|
|
|
static struct NAM Nam;
|
1998-07-30 20:54:47 +00:00
|
|
|
static struct fibdef Fib; /* short fib */
|
1996-03-20 14:57:41 +00:00
|
|
|
static struct dsc$descriptor FibDesc =
|
1998-07-30 20:54:47 +00:00
|
|
|
{ sizeof (Fib), DSC$K_DTYPE_Z, DSC$K_CLASS_S, (char *) &Fib };
|
1996-03-20 14:57:41 +00:00
|
|
|
static struct dsc$descriptor_s DevDesc =
|
1998-07-30 20:54:47 +00:00
|
|
|
{ 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, &Nam.nam$t_dvi[1] };
|
1996-03-20 14:57:41 +00:00
|
|
|
static char EName[NAM$C_MAXRSS];
|
|
|
|
static char RName[NAM$C_MAXRSS];
|
|
|
|
static struct dsc$descriptor_s FileName =
|
1998-07-30 20:54:47 +00:00
|
|
|
{ 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0 };
|
1996-03-20 14:57:41 +00:00
|
|
|
static struct dsc$descriptor_s string =
|
1998-07-30 20:54:47 +00:00
|
|
|
{ 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0 };
|
1996-03-20 14:57:41 +00:00
|
|
|
static unsigned long Rdate[2];
|
|
|
|
static unsigned long Cdate[2];
|
1998-07-30 20:54:47 +00:00
|
|
|
static struct atrdef Atr[] =
|
|
|
|
{
|
|
|
|
#if defined(VAX)
|
|
|
|
/* Revision date */
|
|
|
|
{ sizeof (Rdate), ATR$C_REVDATE, (unsigned int) &Rdate[0] },
|
|
|
|
/* Creation date */
|
|
|
|
{ sizeof (Cdate), ATR$C_CREDATE, (unsigned int) &Cdate[0] },
|
|
|
|
#else
|
|
|
|
/* Revision date */
|
|
|
|
{ sizeof (Rdate), ATR$C_REVDATE, &Rdate[0] },
|
|
|
|
/* Creation date */
|
|
|
|
{ sizeof (Cdate), ATR$C_CREDATE, &Cdate[0]},
|
|
|
|
#endif
|
|
|
|
{ 0, 0, 0 }
|
1996-03-20 14:57:41 +00:00
|
|
|
};
|
|
|
|
static short int DevChan;
|
|
|
|
static short int iosb[4];
|
|
|
|
|
|
|
|
name = vmsify (name, 0);
|
|
|
|
|
|
|
|
/* initialize RMS structures, we need a NAM to retrieve the FID */
|
|
|
|
Fab = cc$rms_fab;
|
1998-07-30 20:54:47 +00:00
|
|
|
Fab.fab$l_fna = name; /* name of file */
|
|
|
|
Fab.fab$b_fns = strlen (name);
|
|
|
|
Fab.fab$l_nam = &Nam; /* FAB has an associated NAM */
|
|
|
|
|
1996-03-20 14:57:41 +00:00
|
|
|
Nam = cc$rms_nam;
|
1998-07-30 20:54:47 +00:00
|
|
|
Nam.nam$l_esa = EName; /* expanded filename */
|
|
|
|
Nam.nam$b_ess = sizeof (EName);
|
|
|
|
Nam.nam$l_rsa = RName; /* resultant filename */
|
|
|
|
Nam.nam$b_rss = sizeof (RName);
|
1996-03-20 14:57:41 +00:00
|
|
|
|
|
|
|
/* do $PARSE and $SEARCH here */
|
1998-07-30 20:54:47 +00:00
|
|
|
status = sys$parse (&Fab);
|
1996-03-20 14:57:41 +00:00
|
|
|
if (!(status & 1))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
DevDesc.dsc$w_length = Nam.nam$t_dvi[0];
|
1998-07-30 20:54:47 +00:00
|
|
|
status = sys$assign (&DevDesc, &DevChan, 0, 0);
|
1996-03-20 14:57:41 +00:00
|
|
|
if (!(status & 1))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
FileName.dsc$a_pointer = Nam.nam$l_name;
|
1998-07-30 20:54:47 +00:00
|
|
|
FileName.dsc$w_length = Nam.nam$b_name + Nam.nam$b_type + Nam.nam$b_ver;
|
|
|
|
|
1996-03-20 14:57:41 +00:00
|
|
|
/* Initialize the FIB */
|
1998-07-30 20:54:47 +00:00
|
|
|
for (i = 0; i < 3; i++)
|
1996-03-20 14:57:41 +00:00
|
|
|
{
|
2000-01-22 05:43:03 +00:00
|
|
|
#ifndef __VAXC
|
1998-07-30 20:54:47 +00:00
|
|
|
Fib.fib$w_fid[i] = Nam.nam$w_fid[i];
|
|
|
|
Fib.fib$w_did[i] = Nam.nam$w_did[i];
|
1996-03-20 14:57:41 +00:00
|
|
|
#else
|
1998-07-30 20:54:47 +00:00
|
|
|
Fib.fib$r_fid_overlay.fib$w_fid[i] = Nam.nam$w_fid[i];
|
|
|
|
Fib.fib$r_did_overlay.fib$w_did[i] = Nam.nam$w_did[i];
|
1996-03-20 14:57:41 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1998-07-30 20:54:47 +00:00
|
|
|
status = sys$qiow (0, DevChan, IO$_ACCESS, &iosb, 0, 0,
|
|
|
|
&FibDesc, &FileName, 0, 0, &Atr, 0);
|
1996-07-26 00:05:34 +00:00
|
|
|
sys$dassgn (DevChan);
|
1996-03-20 14:57:41 +00:00
|
|
|
if (!(status & 1))
|
|
|
|
return -1;
|
|
|
|
status = iosb[0];
|
|
|
|
if (!(status & 1))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
status = stat (name, buf);
|
|
|
|
if (status)
|
|
|
|
return -1;
|
|
|
|
|
1998-07-30 20:54:47 +00:00
|
|
|
buf->st_mtime = ((Rdate[0] >> 24) & 0xff) + ((Rdate[1] << 8) & 0xffffff00);
|
|
|
|
buf->st_ctime = ((Cdate[0] >> 24) & 0xff) + ((Cdate[1] << 8) & 0xffffff00);
|
|
|
|
|
1996-03-20 14:57:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
1998-07-30 20:54:47 +00:00
|
|
|
cvt_time (tval)
|
|
|
|
unsigned long tval;
|
1996-03-20 14:57:41 +00:00
|
|
|
{
|
|
|
|
static long int date[2];
|
|
|
|
static char str[27];
|
|
|
|
static struct dsc$descriptor date_str =
|
1998-07-30 20:54:47 +00:00
|
|
|
{ 26, DSC$K_DTYPE_T, DSC$K_CLASS_S, str };
|
1996-03-20 14:57:41 +00:00
|
|
|
|
|
|
|
date[0] = (tval & 0xff) << 24;
|
1998-07-30 20:54:47 +00:00
|
|
|
date[1] = ((tval >> 8) & 0xffffff);
|
|
|
|
|
|
|
|
if ((date[0] == 0) && (date[1] == 0))
|
|
|
|
return ("never");
|
1996-03-20 14:57:41 +00:00
|
|
|
|
1998-07-30 20:54:47 +00:00
|
|
|
sys$asctim (0, &date_str, date, 0);
|
|
|
|
str[26] = '\0';
|
1996-03-20 14:57:41 +00:00
|
|
|
|
1998-07-30 20:54:47 +00:00
|
|
|
return (str);
|
1996-03-20 14:57:41 +00:00
|
|
|
}
|
2000-01-22 05:43:03 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
strcmpi (s1, s2)
|
|
|
|
const char *s1;
|
|
|
|
const char *s2;
|
|
|
|
{
|
|
|
|
while (*s1 != '\0' && toupper(*s1) == toupper(*s2))
|
|
|
|
{
|
|
|
|
s1++;
|
|
|
|
s2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return toupper(*(unsigned char *) s1) - toupper(*(unsigned char *) s2);
|
|
|
|
}
|