Subscribe: darwin-userlevel Mailing List
Added By: Feedage Forager Feedage Grade B rated
Language: English
acirc  call  darwin userlevel  darwin  directory  einval  errno  jens  loop  mailing list  man page  man  page  readdir  userlevel mailing 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: darwin-userlevel Mailing List

darwin-userlevel Mailing List

darwin-userlevel Mailing List

Published: 2016-09-25T01:35:02-08:00


Why would readdir() fail with EINVAL?
From: Jens Alfke
Reply to list
I’m running into an unexpected error while iterating a directory using the typical opendir / readdir / closedir loop. In a particular repeatable case, iterating a specific directory with 3 ordinary files in it, _after_ reading the last file, the next call to readdir sets errno to EINVAL instead of 0 or ENOENT.

EINVAL seems like a weird result since the only parameter to readdir is the DIR struct, which is still valid and was accepted without error on the previous iterations of the loop.

Also, the man page says that when readdir fails, "errno may be set to any of the values documented for the getdirentries(2) system call”, but that man page only specifies the errors EBADF, EFAULT or EIO.

This is on macOS 10.12. And I’ve been using this iteration code for weeks now without trouble, but it suddenly started failing on this one directory. (Even stranger, that directory gets created anew every time I run, as part of the unit tests.)