Reading from character devices on unix

Einar Karttunen <>
Fri Jun 4 00:00:37 CEST 2004


Hello

Reading from character devices seems to fail on unix with 
{error, eisdir}. Can be repeated with e.g.
file:open("/dev/zero", []). This seems to be caused by
erts/emulator/drivers/unix/unix_efile.c line 747:

    if (!ISREG(statbuf)) {
	close(fd);
	errno = EISDIR;
	return check_error(-1, errInfo);
    }

The ISREG checks whether the file is a normal file and thus 
fails on character devices. What should be used instead
when reading character devices?

Strace tells that the open succeeded:
2561  open("/dev/urandom", O_RDONLY)    = 5
2561  fstat64(5, {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 9), ...}) = 0
2561  close(5)                          = 0

- Einar Karttunen



More information about the erlang-questions mailing list