opendir, readdir, telldir: Use the correct types.

Use either size_t or off_t (as appropriate) instead of long.

Sponsored by:	Klara, Inc.
Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D51210
This commit is contained in:
Dag-Erling Smørgrav 2025-07-09 22:34:22 +02:00
parent dd81cc2bc5
commit 42e613018d
5 changed files with 13 additions and 11 deletions

View file

@ -43,8 +43,8 @@ struct pthread_mutex;
*/
struct _dirdesc {
int dd_fd; /* file descriptor associated with directory */
long dd_loc; /* offset in current buffer */
long dd_size; /* amount of data returned by getdirentries */
size_t dd_loc; /* offset in current buffer */
size_t dd_size; /* amount of data returned by getdirentries */
char *dd_buf; /* data buffer */
int dd_len; /* size of data buffer */
off_t dd_seek; /* magic cookie returned by getdirentries */

View file

@ -264,6 +264,7 @@ DIR *
__opendir_common(int fd, int flags, bool use_current_pos)
{
DIR *dirp;
ssize_t ret;
int incr;
int saved_errno;
bool unionstack;
@ -313,10 +314,11 @@ __opendir_common(int fd, int flags, bool use_current_pos)
* to prime dd_seek. This also checks if the
* fd passed to fdopendir() is a directory.
*/
dirp->dd_size = _getdirentries(dirp->dd_fd,
ret = _getdirentries(dirp->dd_fd,
dirp->dd_buf, dirp->dd_len, &dirp->dd_seek);
if (dirp->dd_size < 0)
if (ret < 0)
goto fail;
dirp->dd_size = (size_t)ret;
dirp->dd_flags |= __DTF_SKIPREAD;
} else {
dirp->dd_size = 0;

View file

@ -48,8 +48,8 @@ struct dirent *
_readdir_unlocked(DIR *dirp, int flags)
{
struct dirent *dp;
long initial_seek;
long initial_loc = 0;
off_t initial_seek;
size_t initial_loc = 0;
for (;;) {
if (dirp->dd_loc >= dirp->dd_size) {

View file

@ -118,7 +118,7 @@ _seekdir(DIR *dirp, long loc)
struct dirent *dp;
union ddloc_packed ddloc;
off_t loc_seek;
long loc_loc;
size_t loc_loc;
ddloc.l = loc;
@ -171,7 +171,7 @@ _seekdir(DIR *dirp, long loc)
* fetching a new block to fix any such telldir locations.
*/
void
_fixtelldir(DIR *dirp, long oldseek, long oldloc)
_fixtelldir(DIR *dirp, off_t oldseek, size_t oldloc)
{
struct ddloc_mem *lp;

View file

@ -46,9 +46,9 @@
*/
struct ddloc_mem {
LIST_ENTRY(ddloc_mem) loc_lqe; /* entry in list */
long loc_index; /* key associated with structure */
size_t loc_index; /* key associated with structure */
off_t loc_seek; /* magic cookie returned by getdirentries */
long loc_loc; /* offset of entry in buffer */
size_t loc_loc; /* offset of entry in buffer */
};
#ifdef __LP64__
@ -102,7 +102,7 @@ bool _filldir(DIR *, bool);
struct dirent *_readdir_unlocked(DIR *, int);
void _reclaim_telldir(DIR *);
void _seekdir(DIR *, long);
void _fixtelldir(DIR *dirp, long oldseek, long oldloc);
void _fixtelldir(DIR *dirp, off_t oldseek, size_t oldloc);
DIR *__opendir_common(int, int, bool);
#define RDU_SKIP 0x0001