[SSSD] Something to share about fmemopen()

Dmitri Pal dpal at redhat.com
Thu Oct 10 04:27:46 UTC 2013


Hello,

I came across an interesting behavior that is IMO worth sharing with
other developers.
It turns out that fmemopen() fails with error 22 EINVAL if the buffer
passed in is of length 0.

Imagine situation: I have a file in the directory of 0 length.
I open it with fopen() or with open() and then fdopen() in "r" mode and
I can read it with getline(). Of cause the first read will return EOF
and I will be done. But if I open file with open() in binary mode, and
mirror it into a buffer and the file is of length 0 then the buffer will
be of length 0 too but attemt to use fmemopen() would fail.
So mirroring in becomes non transparent operation you have to special
case the situation when original file in NULL.

So question is what should I do with it? File a bug or just ask to
document it? Man page does not say anything about it.
Advises welcome.

-- 
Thank you,
Dmitri Pal

Sr. Engineering Manager for IdM portfolio
Red Hat Inc.


-------------------------------
Looking to carve out IT costs?
www.redhat.com/carveoutcosts/






More information about the sssd-devel mailing list