Re: RFC: Fixing fallback tempdir location on Win32

[email protected] (Jan Dubois)
Newsgroups perl.cpan.workers
Message-ID <CAD-TLz-G7=pv-yD5ncKZvUmyEbm8AZ0BCksPq70vN-0rz6-A4w@mail.gmail.com>
On Thu, May 21, 2015 at 1:14 PM, David Golden <[email protected]> wrote:
> First, I'd want someone to check if it returns %USERPROFILE% exactly or some
> path under it.

Only tested on Win7; is seems to append a backslash to it:

Z:\>type gettemppath.pl
use strict;
use warnings;

use Win32::API;

print "$_=$ENV{$_}\n" for qw(TMP TEMP USERPROFILE);
delete $ENV{$_} for qw(TMP TEMP);
my $GetTempPath = new Win32::API('kernel32', 'GetTempPath', 'NP', 'N') or die;
my $buffer = " " x 280;
my $len = $GetTempPath->Call(length $buffer, $buffer);
print substr($buffer, 0, $len), "\n";

Z:\>perl gettemppath.pl
TMP=C:\Users\gecko\AppData\Local\Temp
TEMP=C:\Users\gecko\AppData\Local\Temp
USERPROFILE=C:\Users\gecko
C:\Users\gecko\

And tested separately, it will normalize forward slashes to backslashes as well.

Cheers,
-Jan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.