Stas Bekman <[EMAIL PROTECTED]> writes:
Any chance APR will handle a portable apr_get_temp_dir function? (which returns the existing writable temp path) which then could be used to create a template wanted by apr_file_mktemp().
Oh, man, would I like to see such a thing. Subversion has several instances of needing a temporary directory that's world-writable.
e.g. perl's CGI.pm which is used on many platforms uses this hardcoded array where it then searches for the first writable directory (at compile time)
$SL = $CGI::SL; $MAC = $CGI::OS eq 'MACINTOSH'; my ($vol) = $MAC ? MacPerl::Volumes() =~ /:(.*)/ : ""; @TEMP=("${SL}usr${SL}tmp","${SL}var${SL}tmp", "C:${SL}temp","${SL}tmp","${SL}temp", "${vol}${SL}Temporary Items", "${SL}WWW_ROOT", "${SL}SYS\$SCRATCH", "C:${SL}system${SL}temp"); unshift(@TEMP,$ENV{'TMPDIR'}) if exists $ENV{'TMPDIR'};
Wow, that's pretty cool. Hey, if it works...
I cannot guarantee that this works everywhere, all I can say that CGI.pm is a module used pretty much everywhere where perl runs. But wait, there is more:
I see that CPAN has TempDir module which says:
TempDir - Module to check the correct temporary directory in every OS supported by PERL
And I think Perl is running on the the same platforms as Apache does.
Also there is a core perl module File::Temp, which seems to do that and much more.
of course if we can use existing library functions that would be more portable I think.
POSIX systems has tmpnam(). BSD 4.3 has tempnam(). That's all I know.
I think these functions (at least tmpnam) are more about generating unique file -names- that won't clash with the other names generated by that function. Unfortunately they won't give you a full path in a writable location or anything like that.
This one actually tries hard to handle this for you if you supply NULL instead of dir.
char *tempnam(const char *dir, const char *pfx);
DESCRIPTION
The tempnam() function returns a pointer to a string that
is a valid filename, and such that a file with this name
did not exist when tempnam() checked. The filename suffix
of the pathname generated will start with pfx in case pfx
is a non-NULL string of at most five bytes. The directory
prefix part of the pathname generated is required to be
`appropriate' (often that at least implies writable).
Attempts to find an appropriate directory go through the
following steps: (i) In case the environment variable
TMPDIR exists and contains the name of an appropriate
directory, that is used. (ii) Otherwise, if the dir argu�
ment is non-NULL and appropriate, it is used. (iii) Oth�
erwise, P_tmpdir (as defined in <stdio.h>) is used when
appropriate. (iv) Finally an implementation-defined
directory may be used.
...
CONFORMING TO
SVID 2, BSD 4.3
--
__________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
