tools/include/nolibc/dirent.h
Source file repositories/reference/linux-study-clean/tools/include/nolibc/dirent.h
File Facts
- System
- Linux kernel
- Corpus path
tools/include/nolibc/dirent.h- Extension
.h- Size
- 1890 bytes
- Lines
- 101
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
nolibc.hcompiler.hstdint.htypes.hfcntl.hlinux/limits.h
Detected Declarations
struct direntfunction __attribute__function __attribute__function __attribute__function __attribute__
Annotated Snippet
struct dirent {
ino_t d_ino;
char d_name[NAME_MAX + 1];
};
/* See comment of FILE in stdio.h */
typedef struct {
char dummy[1];
} DIR;
static __attribute__((unused))
DIR *fdopendir(int fd)
{
if (fd < 0) {
SET_ERRNO(EBADF);
return NULL;
}
return (DIR *)(intptr_t)~fd;
}
static __attribute__((unused))
DIR *opendir(const char *name)
{
int fd;
fd = open(name, O_RDONLY);
if (fd == -1)
return NULL;
return fdopendir(fd);
}
static __attribute__((unused))
int closedir(DIR *dirp)
{
intptr_t i = (intptr_t)dirp;
if (i >= 0) {
SET_ERRNO(EBADF);
return -1;
}
return close(~i);
}
static __attribute__((unused))
int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
{
char buf[sizeof(struct linux_dirent64) + NAME_MAX + 1] __nolibc_aligned_as(struct linux_dirent64);
struct linux_dirent64 *ldir = (void *)buf;
intptr_t i = (intptr_t)dirp;
int fd, ret;
if (i >= 0)
return EBADF;
fd = ~i;
ret = _sys_getdents64(fd, ldir, sizeof(buf));
if (ret < 0)
return -ret;
if (ret == 0) {
*result = NULL;
return 0;
}
/*
* getdents64() returns as many entries as fit the buffer.
* readdir() can only return one entry at a time.
* Make sure the non-returned ones are not skipped.
*/
ret = _sys_lseek(fd, ldir->d_off, SEEK_SET);
if (ret < 0)
return -ret;
entry->d_ino = ldir->d_ino;
/* the destination should always be big enough */
strlcpy(entry->d_name, ldir->d_name, sizeof(entry->d_name));
*result = entry;
return 0;
}
#endif /* _NOLIBC_DIRENT_H */
Annotation
- Immediate include surface: `nolibc.h`, `compiler.h`, `stdint.h`, `types.h`, `fcntl.h`, `linux/limits.h`.
- Detected declarations: `struct dirent`, `function __attribute__`, `function __attribute__`, `function __attribute__`, `function __attribute__`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.