[rtmpdump] rtmpsuck duplicate filename patch

Andy Goth andrew.m.goth at gmail.com
Mon Apr 2 16:47:26 CEST 2012


On 4/1/2012 4:12 PM, Andy Goth wrote:
> On 4/1/2012 3:44 PM, Andy Goth wrote:
>> On 4/1/2012 10:47 AM, Howard Chu wrote:
>>> The patch probably addresses a real problem, but the patch is not
>>> portable enough; it won't work on Win32.
>>
>> What part is nonportable? Is it the readdir() stuff? I do have access
>> to a MinGW environment on Windows; I could try implementing an
>> alternative, if MinGW is your Win32 target.
>
> Instead of readdir() and friends, if I could specify the O_EXCL option
> to fopen()

I suppose I could also try opening the file for reading.  If that
succeeds, I know the file exists, so I should pick a different name.
That should be portable, also more efficient than scanning the whole
directory looking for a particular name.  If the file exists but isn't
readable due to permissions, fopen() for read will fail, but fopen() for
write will fail too, and (this is current behavior) rtmpsuck will abort.

Are there any other portable ways to check for a file's existence?
stat(), for instance?

There's a race condition between checking if it exists and creating it,
but that was true for the readdir() approach as well; only O_EXCL avoids
that problem, and even then only when not using old NFS and Linux.

-- 
Andy Goth | <andrew.m.goth/at/gmail/dot/com>


More information about the rtmpdump mailing list