X-Recipient: archive-cygwin@delorie.com
X-Spam-Check-By: sourceware.org
Date: Tue, 5 Aug 2008 19:15:33 -0500 (CDT)
From: Tim McDaniel <tmcd@panix.com>
cc: cygwin@cygwin.com
Subject: Re: environment variables derived from TMPDIR
In-Reply-To: <loom.20080805T232430-609@post.gmane.org>
Message-ID: <Pine.NEB.4.64.0808051910070.17429@panix3.panix.com>
References: <18584.12950.943391.75971@gepard2.akutech-local.de>  <loom.20080805T232430-609@post.gmane.org>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
X-IsSubscribed: yes
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
Precedence: bulk
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie.com@cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

On Tue, 5 Aug 2008, Kurt Franke <Kurt-Franke@web.de> wrote:
> Ralf Fassel <ralfixx <at> gmx.de> writes:
>> In a SHELL script I prepare a temp file to pass to some non-cygwin
>> program:
>>
>>     # TMPDIR is set to c:/temp outside of cygwin
>>     # which translates to /cygdrive/c/temp inside cygwin
>>     # prepare input
>>     TMPFILE=$TMPDIR/foo.$$
>>     cat > "$TMPFILE" <<\EOF
>>     some stuff
>>     EOF
>>     # call program: error: no such file /cygdrive/c/temp/foo.1234
>>     # filename should be c:/temp/foo.1234
>>     external_program "$TMPFILE"
>>
>> Now TMPFILE is passed to the external program using POSIX path
>> notation which it does not understand.
>>
>> If possible I'd like to avoid using 'cygpath' in the script since it
>> should run on different platforms.
>
> you may check if the cygpath usage is valid before do it:
>
> is_CYGWIN=`uname | grep CYGWIN | wc -l`
> if [ $is_CYGWIN -gt 0 ]
> then
>  TMPDIR=`cygpath -w $TMPDIR`
> fi
> # continue with your code here

My notion is in the vicinity of "duck typing" and "EAFP" ("Easier to
Ask Forgiveness than Permission").  The best way to see whether
cygpath can do what you want is to call cygpath to do what you want

     # I use /bin/cygpath so that I don't have to depend on PATH being
     # set correctly.
     if new_TMPDIR=`/bin/cygpath -w "$TMPDIR" 2>/dev/null`; then
         TMPDIR="$new_TMPDIR"
     fi
     unset new_TMPDIR   # I like to explicitly kill dead variables

much like it's common advice that, when you want to know whether a
file is readable at the start of using it in your program, you should
simply try to open it for reading and catch the error or exception if
it's not.

-- 
Tim McDaniel, tmcd@panix.com

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

