Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#213 Temp file issues building on cygwin without GUI

closed
Holger Vogt
None
5
2012-11-21
2012-09-20
Ian Rees
No

Needed to build ngspice for a windows 7 machine using cygwin, and without the GUI as ngspice is being run from a python script. Ran into a few issues before I could get it working, the included patch (against the latest version from git) seems to fix those.

* Added "AM_PROG_AR" to configure.ac let autogen.sh work. I'm not sure what exactly this does, took a guess based on the errors autogen spat out and it worked...

* Once the program would configure and build, there were errors relating to a temp file not being created. Traced this back to the #ifdefs in main.c around line 1170 - the original call to tmpfile() was failing, but since HAS_WINDOWS wasn't defined (didn't want the GUI built), the alternative smktemp() and fopen() weren't getting built.

* Adjusting some #ifdefs and #defines to get smktemp() to produce a valid windows temp file name, which got ngspice to create temp files and run as desired.

* Unfortunately, this smktemp() + fopen() mechanism didn't delete the temp files after ngspice closed, so added a call to remove() to get rid of them.

I haven't tested this beyond one windows 7 machine (at work), but it does appear to work just fine for my purposes.

Discussion

1 2 3 > >> (Page 1 of 3)
  • Ian Rees
    Ian Rees
    2012-09-20

    Proposed fix

     
  • Holger Vogt
    Holger Vogt
    2012-09-20

    • assigned_to: nobody --> h_vogt
     
  • Holger Vogt
    Holger Vogt
    2012-09-20

    Ian,

    thanks for the input.

    To be honest, I have not used CYGWIN for some time now.

    If possible, use the console application (no GUI) created with MINGW. I will check the CYGWIN issue nevertheless.

    Holger

     
  • Holger Vogt
    Holger Vogt
    2012-09-22

    Why is tmpfile() failing?

     
  • Holger Vogt
    Holger Vogt
    2012-09-22

    In my setup I am using a directory c:\cygwin\tmp which is used (automatically) to store the temporary file. When I remove this directory, ngspice fails with error message
    tmpfile(): No such file or directory.

    Please check, if possible, if this will allow to run ngspice without your patch.

    Holger

     
  • Ian Rees
    Ian Rees
    2012-09-22

    Hi Holger,

    Thanks for the quick response! Sorry I was not clear in the first post that we needed the ngspice executable to run from windows, rather than from the cygwin terminal. That dependency comes from the python script, which has some other problems if it's run from within cygwin. Mingw is probably the right tool for the job as you suggested, I just had cygwin handy and was in a hurry.

    I have replicated your experiment with current git sources on a new windows 7 + cygwin install, and found that the executable made in cygwin works fine within cygwin (and fails when c:\cygwin\tmp is missing). When run from a windows prompt though, it gives "tmpfile(): No such file or directory".

    Looking at this again, I wonder whether some of the "#if define..."s in main.c are required, eg:

    FILE *tempfile = tmpfile();

    #if defined(HAS_WINDOWS) || defined(BUILDING_ON_WINDOWS)
    char *dname = NULL; /* input file*/
    char *tpf = NULL; /* temporary file */

    Maybe it is OK to leave the fopen() alternative if tmpfile() fails for all platforms?

    Apologies for the poor quality patch and post! -Ian-

     
  • Robert Larice
    Robert Larice
    2012-09-23

    Hello Ian

    > and found that the executable made in cygwin works fine
    > within cygwin (and fails when c:\cygwin\tmp is missing). When run from a
    > windows prompt though, it gives "tmpfile(): No such file or directory".

    please start a cygwin shell and examine the output of the command
    env
    is there some environment variable named like TEMP or TMP or somesuch ?
    then try to find out which environment variables are defined if you start
    a process from a windows prompt.
    is the TEMP or TMP or whatever missing there ?
    if so try to set it, and repeat our experiment.

    thanks,
    Robert

     
  • Ian Rees
    Ian Rees
    2012-09-23

    Hi Robert,

    cygwin:
    TEMP=/tmp
    temp=C:\Users\ian\AppData\Local\Temp
    tmp=C:\Users\ian\AppData\Local\Temp
    TMP=/tmp

    windows terminal:
    TMP=C:\Users\ian\AppData\Local\Temp
    TEMP=C:\Users\ian\AppData\Local\Temp

    It seems cygwin copies the temp variable names from windows and re-uses them with their names changed to lower case. Other environment variables in windows get replicated in cygwin with case preserved. So, there must be something special going on in the case of TEMP and TMP? Thanks! -Ian-

     
  • Robert Larice
    Robert Larice
    2012-09-23

    Hello Ian, Holger,

    googling a bit around it seems to me the tmpfile() implementation which is used here in Ian's cygwin might be
    http://cygwin.com/cgi-bin/cvsweb.cgi/src/newlib/libc/stdio/tmpfile.c?cvsroot=src
    and this boils down to _tmpnam_r() in
    http://cygwin.com/cgi-bin/cvsweb.cgi/src/newlib/libc/stdio/tmpnam.c?cvsroot=src
    which doesn't use any environment variable but just uses
    P_tmpdir,
    which presumably is "/tmp"

    this means, if you run the program from within cygwin, "/tmp" will be translated
    per cygwin services to something like c:\cygwin\tmp
    which obviously exists in your case.

    and if you run it outside, "/tmp" will we interpreted as something like
    c:\tmp
    where the /->\ translation is done in windows itself, and the c: is
    coming from thin air, being your "current working drive"

    -----
    please create c:\tmp make it world writeable, and tell me
    whether tmpfile() is working then.

    Robert

     
  • Ian Rees
    Ian Rees
    2012-09-23

    Hi Robert,

    I've created c:\tmp and c:\temp with everyone allowed write access, but still get the same issue with tmpfile() not working when ngspice is run from the windows prompt. I think the issue there is that tmpfile is trying to use a '/' in the temp file name, but windows doesn't like that. That's why my original patch had a modification in defines.h - smktemp() was generating file names that do not work in windows.

    If I make a simple test program that just calls fopen("/tmp/somefile.txt", "w"), it works fine in a cygwin terminal, but fails (fopen() returns 0) in a windows terminal. If I change it to "\\tmp\\somefile.txt" and run it in windows, then the files is created, but cygwin spits out a warning about "MS-DOS style path detected".

    Interestingly, the windows terminal works using / instead of \ at least in some cases. For example, I can do "echo hello > /tmp/file.txt" or "echo hello > \tmp\file.txt" and get equivalent results (text file c:\tmp\file.txt containing "hello").

    Thanks! -Ian-

     
1 2 3 > >> (Page 1 of 3)