Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

No point of using _open_r

I read about reentrant function versions and I was goint to use them (in fact I have them already converted in my code). During the debugging I entered accidently into the _read_r function and I have seen its body:

ssize_t

_DEFUN (_read_r, (ptr, fd, buf, cnt),

struct _reent *ptr _AND

int fd _AND

_PTR buf _AND

size_t cnt)

{

_ssize_t ret;

errno = 0;

if ((ret = (_ssize_t)_read (fd, buf, cnt)) == -1 && errno != 0)

ptr->_errno = errno;

return ret;

}

Looking at this source code I find this function NOT REENTRANT!

Nothing stops an interrupt to arrive between seting global errno and copying its value to a struct _reent. Such intterupt would cause reschedule in MicroC/OS and the other task can use global errno variable for its own and modify its value before the scheduler returns control to the previous task.

I see no point of using these functions - am I correct thinking they do not do any good ?
No RepliesBe the first to reply