]>
git.zerfleddert.de Git - micropolis/blob - src/tcl/compat/opendir.c
4 * This file provides dirent-style directory-reading procedures
5 * for V7 Unix systems that don't have such procedures. The
6 * origin of this code is unclear, but it seems to have come
7 * originally from Larry Wall.
16 ((sizeof (struct dirent) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
29 myname
= ((*name
== '\0') ? "." : name
);
30 if ((fd
= open(myname
, 0, 0)) == -1)
32 if ((dirp
= (DIR *)ckalloc(sizeof(DIR))) == NULL
) {
42 * read an old style directory entry and present it as a new one
49 char od_name
[ODIRSIZ
];
51 #else /* a Pyramid in the ATT universe */
56 short od_fill1
, od_fill2
;
57 char od_name
[ODIRSIZ
];
62 * get next entry in a directory.
68 register struct olddirect
*dp
;
69 static struct dirent dir
;
72 if (dirp
->dd_loc
== 0) {
73 dirp
->dd_size
= read(dirp
->dd_fd
, dirp
->dd_buf
,
75 if (dirp
->dd_size
<= 0)
78 if (dirp
->dd_loc
>= dirp
->dd_size
) {
82 dp
= (struct olddirect
*)(dirp
->dd_buf
+ dirp
->dd_loc
);
83 dirp
->dd_loc
+= sizeof(struct olddirect
);
86 dir
.d_ino
= dp
->od_ino
;
87 strncpy(dir
.d_name
, dp
->od_name
, ODIRSIZ
);
88 dir
.d_name
[ODIRSIZ
] = '\0'; /* insure null termination */
89 dir
.d_namlen
= strlen(dir
.d_name
);
90 dir
.d_reclen
= DIRSIZ(&dir
);
105 ckfree((char *) dirp
);