public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* TMP and TMPDIR mapping
@ 2023-01-25  7:57 john daintree
  2023-01-27  7:44 ` Andrey Repin
  0 siblings, 1 reply; 4+ messages in thread
From: john daintree @ 2023-01-25  7:57 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 351 bytes --]

Hi

 

My understanding is that Cygwin maps $TMP and $TMPDIR (and probably others)
to a Windows form (/cygdrive/c/tmp  -> C:\tmp) when calling a WIN32 program
(e.g. cmd.exe). Is it possible, from bash or from Cygwin startup , to add
additional environment variable names so that they  are also automatically
mapped in the same way?

 

Thanks

/John


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: TMP and TMPDIR mapping
  2023-01-25  7:57 TMP and TMPDIR mapping john daintree
@ 2023-01-27  7:44 ` Andrey Repin
  2023-01-27  9:08   ` john daintree
  0 siblings, 1 reply; 4+ messages in thread
From: Andrey Repin @ 2023-01-27  7:44 UTC (permalink / raw)
  To: john daintree, cygwin

Greetings, john daintree!

> My understanding is that Cygwin maps $TMP and $TMPDIR (and probably others)
> to a Windows form (/cygdrive/c/tmp  -> C:\tmp)

Nop. The actual mapping depends on your settings, but defaults to /tmp which
is inside Cygwin installation root.
Another option is to mount /tmp with 'usertemp' option, which would then
redirect it to the user's %TEMP%.

> when calling a WIN32 program
> (e.g. cmd.exe). Is it possible, from bash or from Cygwin startup , to add
> additional environment variable names so that they  are also automatically
> mapped in the same way?

What is your question, exactly?
What you want to achieve and what your actual observation compared to expected
behavior?


-- 
With best regards,
Andrey Repin
Friday, January 27, 2023 10:41:46

Sorry for my terrible english...


^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: TMP and TMPDIR mapping
  2023-01-27  7:44 ` Andrey Repin
@ 2023-01-27  9:08   ` john daintree
  2023-01-27 11:32     ` Corinna Vinschen
  0 siblings, 1 reply; 4+ messages in thread
From: john daintree @ 2023-01-27  9:08 UTC (permalink / raw)
  To: cygwin

Hi Audrey.

Here's an example of what's going on:

>>: export TMPDIR=/cygdrive/c/tmp/jd
>>: export TMPDIR2=/cygdrive/c/tmp/jd2
>>: cmd.exe
Microsoft Windows [Version 10.0.22621.1105]
(c) Microsoft Corporation. All rights reserved.

C:\>echo %TMPDIR%
C:\tmp\jd

C:\>echo %TMPDIR2%
/cygdrive/c/tmp/jd2

So, if I set TMPDIR and TMPDIR2 in bash, and then call cmd.exe then TMPDIR
is changed to c:\tmp\jd but TMPDIR2 is left as /cygdrive/c/tmp/jd2

I was hoping that there's something I can do to get the following in
cmd.exe:

C:\>echo %TMPDIR2%
C:\tmp\jd2                                              # TMPDIR2 "mapped"
to c:\.... in the same way that TMPDIR is

I hope that's a clearer example.

Note that the actual use case is calling other Win32 programs, and the
environment variable name is different, but the above example is an attempt
to simplify the repro.
$PATH is mapped in  a similar way. So I assume that there is a list of names
which are mapped. I'd like to be able to add my own names to that list.

Thanks.
John.



-----Original Message-----
From: Andrey Repin <anrdaemon@yandex.ru> 
Sent: 27 January 2023 07:45
To: john daintree <johnd@dyalog.com>; cygwin@cygwin.com
Subject: Re: TMP and TMPDIR mapping

Greetings, john daintree!

> My understanding is that Cygwin maps $TMP and $TMPDIR (and probably
others)
> to a Windows form (/cygdrive/c/tmp  -> C:\tmp)

Nop. The actual mapping depends on your settings, but defaults to /tmp which
is inside Cygwin installation root.
Another option is to mount /tmp with 'usertemp' option, which would then
redirect it to the user's %TEMP%.

> when calling a WIN32 program
> (e.g. cmd.exe). Is it possible, from bash or from Cygwin startup , to
add
> additional environment variable names so that they  are also
automatically
> mapped in the same way?

What is your question, exactly?
What you want to achieve and what your actual observation compared to
expected behavior?


--
With best regards,
Andrey Repin
Friday, January 27, 2023 10:41:46

Sorry for my terrible english...



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: TMP and TMPDIR mapping
  2023-01-27  9:08   ` john daintree
@ 2023-01-27 11:32     ` Corinna Vinschen
  0 siblings, 0 replies; 4+ messages in thread
From: Corinna Vinschen @ 2023-01-27 11:32 UTC (permalink / raw)
  To: cygwin; +Cc: john daintree

On Jan 27 09:08, john daintree via Cygwin wrote:
> Hi Audrey.
> 
> Here's an example of what's going on:
> 
> >>: export TMPDIR=/cygdrive/c/tmp/jd
> >>: export TMPDIR2=/cygdrive/c/tmp/jd2
> >>: cmd.exe
> Microsoft Windows [Version 10.0.22621.1105]
> (c) Microsoft Corporation. All rights reserved.
> 
> C:\>echo %TMPDIR%
> C:\tmp\jd
> 
> C:\>echo %TMPDIR2%
> /cygdrive/c/tmp/jd2
> 
> So, if I set TMPDIR and TMPDIR2 in bash, and then call cmd.exe then TMPDIR
> is changed to c:\tmp\jd but TMPDIR2 is left as /cygdrive/c/tmp/jd2
> 
> I was hoping that there's something I can do to get the following in
> cmd.exe:
> 
> C:\>echo %TMPDIR2%
> C:\tmp\jd2                                              # TMPDIR2 "mapped"
> to c:\.... in the same way that TMPDIR is
> 
> I hope that's a clearer example.
> 
> Note that the actual use case is calling other Win32 programs, and the
> environment variable name is different, but the above example is an attempt
> to simplify the repro.
> $PATH is mapped in  a similar way. So I assume that there is a list of names
> which are mapped. I'd like to be able to add my own names to that list.

Easy: Don't call the affected Win32 executable directly.  Call it
through a child process.

Two scenarios:

- Starting the nativ executable from a shell or a Makefile:

  Create a wrapper script which calls

    TMPDIR2="$(cygpath -wa ${TMPDIR2})
      
  before calling your native app.

- Starting the nativ executable from your own process:

  After fork(), call

    const char *tmpdir2_old;
    char *tmpdir2_new;

    tmpdir2_old = getenv ("TMPDIR2");
    tmpdir2_new = (char *) cygwin_create_path (CCP_POSIX_TO_WIN_A,
                                               tmpdir2_old);
    setenv ("TMPDIR2", tmpdir2_new, 1);
    free (tmpdir2_new);

  Then call execve or friends.  Alternatively you can construct the
  new environment like the above for any exec call taking an
  environment as argument, i.e, execve, execle, execvpe.


Corinna

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-01-27 11:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-25  7:57 TMP and TMPDIR mapping john daintree
2023-01-27  7:44 ` Andrey Repin
2023-01-27  9:08   ` john daintree
2023-01-27 11:32     ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).