]>
Dogcows Code - chaz/tar/blob - src/msd_dir.c
2 * @(#)msd_dir.c 1.4 87/11/06 Public Domain.
4 * A public domain implementation of BSD directory routines for
5 * MS-DOS. Written by Michael Rendell ({uunet,utai}michael@garfield),
25 # define MAXPATHLEN 255
26 #endif /* MAXPATHLEN */
34 #define A_ARCHIVE 0x20
37 #define DOSI_FINDF 0x4e
38 #define DOSI_FINDN 0x4f
39 #define DOSI_SDTA 0x1a
41 #define Newisnull(a, t) ((a = (t *) malloc(sizeof(t))) == (t *) NULL)
42 /* #define ATTRIBUTES (A_DIR | A_HIDDEN | A_SYSTEM) */
43 #define ATTRIBUTES (A_RONLY | A_SYSTEM | A_DIR)
45 /* what find first/next calls look use */
49 unsigned short d_time
;
50 unsigned short d_date
;
55 static char *getdirent();
56 static void mysetdta();
57 static void free_dircontents();
59 static Dta_buf dtabuf
;
60 static Dta_buf
*dtapnt
= &dtabuf
;
61 static union REGS reg
, nreg
;
64 static struct SREGS sreg
;
75 struct _dircontents
*dp
;
76 char nbuf
[MAXPATHLEN
+ 1];
78 if (stat(name
, &statb
) < 0 || (statb
.st_mode
& S_IFMT
) != S_IFDIR
)
80 if (Newisnull(dirp
, DIR))
82 if (*name
&& (c
= name
[strlen(name
) - 1]) != '\\' && c
!= '/')
83 (void) strcat(strcpy(nbuf
, name
), "\\*.*");
85 (void) strcat(strcpy(nbuf
, name
), "*.*");
88 dirp
->dd_contents
= dirp
->dd_cp
= (struct _dircontents
*) NULL
;
89 if ((s
= getdirent(nbuf
)) == (char *) NULL
)
92 if (Newisnull(dp
, struct _dircontents
) || (dp
->_d_entry
=
93 malloc((unsigned) (strlen(s
) + 1))) == (char *) NULL
)
97 free_dircontents(dirp
->dd_contents
);
100 if (dirp
->dd_contents
)
101 dirp
->dd_cp
= dirp
->dd_cp
->_d_next
= dp
;
103 dirp
->dd_contents
= dirp
->dd_cp
= dp
;
104 (void) strcpy(dp
->_d_entry
, s
);
105 dp
->_d_next
= (struct _dircontents
*) NULL
;
106 } while ((s
= getdirent((char *) NULL
)) != (char *) NULL
);
107 dirp
->dd_cp
= dirp
->dd_contents
;
116 free_dircontents(dirp
->dd_contents
);
124 static struct dirent dp
;
126 if (dirp
->dd_cp
== (struct _dircontents
*) NULL
)
127 return (struct dirent
*) NULL
;
128 dp
.d_namlen
= dp
.d_reclen
=
129 strlen(strcpy(dp
.d_name
, dirp
->dd_cp
->_d_entry
));
130 strlwr(dp
.d_name
); /* JF */
132 dirp
->dd_cp
= dirp
->dd_cp
->_d_next
;
144 struct _dircontents
*dp
;
148 for (dp
= dirp
->dd_contents
; --i
>= 0 && dp
; dp
= dp
->_d_next
)
150 dirp
->dd_loc
= off
- (i
+ 1);
163 struct _dircontents
*dp
;
165 struct _dircontents
*odp
;
170 dp
= (odp
= dp
)->_d_next
;
179 if (dir
!= (char *) NULL
) { /* get first entry */
180 reg
.h
.ah
= DOSI_FINDF
;
181 reg
.h
.cl
= ATTRIBUTES
;
183 reg
.x
.dx
= FP_OFF(dir
);
184 sreg
.ds
= FP_SEG(dir
);
186 reg
.x
.dx
= (unsigned) dir
;
188 } else { /* get next entry */
189 reg
.h
.ah
= DOSI_FINDN
;
191 reg
.x
.dx
= FP_OFF(dtapnt
);
192 sreg
.ds
= FP_SEG(dtapnt
);
194 reg
.x
.dx
= (unsigned) dtapnt
;
198 intdosx(®
, &nreg
, &sreg
);
203 return (char *) NULL
;
205 return dtabuf
.d_name
;
211 reg
.h
.ah
= DOSI_SDTA
;
213 reg
.x
.dx
= FP_OFF(dtapnt
);
214 sreg
.ds
= FP_SEG(dtapnt
);
215 intdosx(®
, &nreg
, &sreg
);
217 reg
.x
.dx
= (int) dtapnt
;
This page took 0.045014 seconds and 5 git commands to generate.