1 /* $NetBSD: compat_readdir.c,v 1.3 2012/02/08 12:10:17 mbalmer Exp $ */
3 #define __LIBC12_SOURCE__
10 #include <compat/include/dirent.h>
13 __weak_alias(readdir
,_readdir
)
14 __weak_alias(readdir_r
,_readdir_r
)
17 #ifdef __warn_references
18 __warn_references(readdir
,
19 "warning: reference to compatibility readdir(); include <dirent.h> for correct reference")
20 __warn_references(readdir_r
,
21 "warning: reference to compatibility readdir_r(); include <dirent.h> for correct reference")
24 static struct dirent12
*
25 direnttodirent12(struct dirent12
*d12
, const struct dirent
*d
)
30 if (d
->d_fileno
> UINT_MAX
|| d
->d_namlen
>= sizeof(d12
->d_name
)) {
34 d12
->d_fileno
= (uint32_t)d
->d_fileno
;
35 d12
->d_reclen
= (uint16_t)d
->d_reclen
;
36 d12
->d_namlen
= (uint8_t)MIN(d
->d_namlen
, sizeof(d
->d_name
) - 1);
37 d12
->d_type
= (uint8_t)d
->d_type
;
38 memcpy(d12
->d_name
, d
->d_name
, (size_t)d12
->d_namlen
);
39 d12
->d_name
[d12
->d_namlen
] = '\0';
46 static struct dirent12 d12
;
47 return direnttodirent12(&d12
, __readdir30(dirp
));
51 readdir_r(DIR *dirp
, struct dirent12
*entry
, struct dirent12
**result
)
56 if ((error
= __readdir_r30(dirp
, &e
, &ep
)) != 0)
60 (void)direnttodirent12(entry
, &e
);