|
From: Petr M. <mi...@ph...> - 2006-03-03 10:25:18
|
>> What do you think about adding function
>> fileexist("a.dat")
>> that would return 1 or 0 if file exists or does not exist?
>>
>> I have already needed that several times ... solution via `test` is
>> not portable ...
>
> Is access() really that much more portable than test?
>
>> The code is as easy as
>> return (access(filename, F_OK) != 0))
>> see the attachment.
> That's not terribly portable, then. Access() is POSIX, but that doesn't
> help us much on Windows, OS/2 and others.
Then OS/2 is OK, also GNU compilers under windows (mingw, cygwin). Cannot
say about others ... #ifdef HAVE_UNISTD_H should suffice.
> If we want to be portable, the only real option is to ry to fopen() the
> file and see if it works.
> man 2 access
> [...]
> RESTRICTIONS
> access may not work correctly on NFS file systems with UID
> mapping enabled, because UID mapping is done on the server
> and hidden from the client, which checks permissions.
>
> If your test doesn't work across NFS-mounted volumes, that's
> not very portable!
So you recommend to use fopen() even for unices, and thus get rid of
access()? No problem, I will change the patch.
> Can you give an example of why such a thing is needed?
Example 1:
plot 'measure.dat'
if fileexist('fit.dat') replot 'fit.dat'
pause 5
reread
Example 2:
Execution of commands passed via pipes between gnuplot and octave (for
example) takes some time and it's hard to stop/wait without breaking the
script (error message). The above solution is fine for some cases.
Actually, what some users ask for real-time plotting, is something like
pause untilfileexist "next.dat"
pause untilfilechanged "next.dat"
---
PM
|