2 * DIRECTORY.C - VMS emulation routines for UNIX Directory
5 * Author: Patrick L. Mahan
7 * Date: 19-November-1991
9 * Purpose: Provides emulation of the BSD directory routines
10 * which are used by some of the X11 R4 release
13 * Side effects: This is only a partial emulation. Not all of
14 * the required information is passed to the user.
16 * Modification History
18 * Date | Who | Version | History
19 * ------------+-----------+---------------+----------------------------
20 * 19-Nov-1991 | PLM | 1.0 | First Write
21 * 20-Apr-1992 | PLM | 1.1 | Added validation check for
22 * | | | for the directory
30 #include <lib$routines.h>
31 #include "vms_dirent.h"
33 #define NOWILD 0x00000001
34 #define MULTIPLE 0x00000002
36 static unsigned long context
= 0;
38 static struct dsc$descriptor_s
*create_descriptor ( name
)
41 struct dsc$descriptor_s
*retdescrip
;
43 retdescrip
= (struct dsc$descriptor_s
*)calloc(1, sizeof(struct dsc$descriptor_s
));
45 if (retdescrip
== NULL
) return ((struct dsc$descriptor_s
*)NULL
);
47 retdescrip
->dsc$b_dtype
= DSC$K_DTYPE_T
;
48 retdescrip
->dsc$b_class
= DSC$K_CLASS_S
;
49 retdescrip
->dsc$w_length
= strlen(name
);
50 retdescrip
->dsc$a_pointer
= name
;
55 static int Check_Directory( dirname
)
58 static char *tmpdir
, *cp
;
64 tmpdir
= calloc(strlen(dirname
)+15,sizeof(char));
66 strcpy(tmpdir
, dirname
);
68 cp
= strrchr(tmpdir
, '.');
72 cp
= strrchr(tmpdir
, ']');
74 strcat(tmpdir
, "dir");
78 tmp1
= calloc(strlen(dirname
)+1,sizeof(char));
79 cp
= strchr(tmpdir
, '[');
82 cp
= strrchr(tmp1
, ']');
84 cp
= strchr(tmpdir
, '[');
87 strcat(tmpdir
, "000000]");
89 strcat(tmpdir
, ".dir");
92 tfp
= fopen(tmpdir
, "r");
94 if (tfp
== NULL
) status
= 0;
101 DIR *opendir( dirname
)
105 struct dsc$descriptor_s filedescriptor
;
108 retdir
= (DIR *) calloc(1, sizeof(DIR));
110 if (retdir
== NULL
) return ((DIR *)NULL
);
112 if (!Check_Directory(dirname
)) return ((DIR *)NULL
);
114 filepathname
= (char *)calloc(256, sizeof(char));
116 strcpy(filepathname
, dirname
);
117 strcat(filepathname
, "*.*.*");
119 retdir
->dd_fd
= (unsigned long) create_descriptor(filepathname
);
121 retdir
->dd_size
= strlen(filepathname
);
122 retdir
->dd_bsize
= 0;
124 retdir
->dd_buf
= filepathname
;
129 struct dirent
*readdir( dirp
)
132 static struct dirent
*retdirent
;
133 struct dsc$descriptor_s retfilenamedesc
;
134 struct dsc$descriptor_s searchpathdesc
= *((struct dsc$descriptor_s
*)dirp
->dd_fd
);
135 char retfilename
[256];
137 unsigned long istatus
;
138 unsigned long rms_status
;
141 retdirent
= (struct dirent
*)NULL
;
145 retfilenamedesc
.dsc$b_dtype
= DSC$K_DTYPE_T
;
146 retfilenamedesc
.dsc$b_class
= DSC$K_CLASS_S
;
147 retfilenamedesc
.dsc$w_length
= 255;
148 retfilenamedesc
.dsc$a_pointer
= retfilename
;
150 istatus
= lib$
find_file (&searchpathdesc
,
157 if (!(istatus
& 1) && (istatus
!= RMS$_NMF
) && (istatus
!= RMS$_FNF
))
159 lib$
signal (istatus
);
162 else if ((istatus
== RMS$_NMF
) || (istatus
== RMS$_FNF
))
165 retfilename
[retfilenamedesc
.dsc$w_length
] = '\0';
167 sp
= strchr(retfilename
, ' ');
168 if (sp
!= NULL
) *sp
= '\0';
170 sp
= strrchr(retfilename
, ']');
176 retdirent
= (struct dirent
*)calloc(1, sizeof(struct dirent
));
178 strcpy(retdirent
->d_name
, sp
);
179 retdirent
->d_namlen
= strlen(sp
);
180 retdirent
->d_fileno
= 0;
181 retdirent
->d_off
= 0;
182 retdirent
->d_reclen
= DIRSIZ(retdirent
);
193 void seekdir( dirp
, loc
)
200 void rewinddir( dirp
)
203 lib$
find_file_end (&dirp
->dd_loc
);
206 void closedir( dirp
)
209 lib$
find_file_end (&dirp
->dd_loc
);
211 cfree ((void *) dirp
->dd_fd
);
212 cfree (dirp
->dd_buf
);