|Pathologically Eclectic Rubbish Lister|
PerlIO, random write file access and O_CREATby vsespb (Hermit)
|on May 29, 2013 at 15:06 UTC||Need Help??|
vsespb has asked for the
wisdom of the Perl Monks concerning the following question:
I want to peform multiple writes to a file, from different processes, at the same time. Writes will be at different, non-overlapping positions. I want to use perlio for this (to avoid coding workarounds when syswrite is not writing all data). And the file to write data, might not exsit before write.
So, I found this is pretty complicated. Perl open modes maps to fopen() fopen
And it does not have mode with O_CREAT, but without O_TRUNC/O_APPEND
Obviously I cannot use O_TRUNC because it will destroy file content, and cannot use O_APPEND because I cannot use seek with it.
possible workaround is only use
This will create file if it's not exists, and will open it in read-write mode. (I assume there will be no race-conditions between close and second open, such race condition can be worked around if I check errno after last open and put it into while loop)Question: Am I missing something? It there easier way? Or maybe better avoid perl IO for such task (i.e. above code contain bugs) ?