public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin@cygwin.com
Cc: john daintree <johnd@dyalog.com>
Subject: Re: TMP and TMPDIR mapping
Date: Fri, 27 Jan 2023 12:32:40 +0100	[thread overview]
Message-ID: <Y9O2WLmxfyTi7BRk@calimero.vinschen.de> (raw)
In-Reply-To: <004501d9322e$effed500$cffc7f00$@dyalog.com>

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

      reply	other threads:[~2023-01-27 11:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-25  7:57 john daintree
2023-01-27  7:44 ` Andrey Repin
2023-01-27  9:08   ` john daintree
2023-01-27 11:32     ` Corinna Vinschen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y9O2WLmxfyTi7BRk@calimero.vinschen.de \
    --to=corinna-cygwin@cygwin.com \
    --cc=cygwin@cygwin.com \
    --cc=johnd@dyalog.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).