[aspect-devel] mktemp failure

Eric Heien emheien at ucdavis.edu
Thu May 3 08:21:53 PDT 2012


Thanks Timo, I'll try that.  We can check the $TMPDIR environment variable and use /tmp if it's not set - this is what the current code does and what tmpfile() does.

-Eric

On May 3, 2012, at 8:18 AM, Timo Heister wrote:

> The following code seems to work and does not delete the file. Is
> using /tmp/ always a good idea, though?
> 
> #include <stdlib.h>
> #include <stdio.h>
> #include <string.h>
> 
> int main()
> {
>  char pattern[256];
>  strcpy(pattern, "/tmp/XXXXXX");
> 
>  int fd=mkstemp(pattern);
>  if (fd==-1)
>    {
>      printf("mkstemp failed\n");
>      return -1;
>    }
> 
>  FILE *f=fdopen(fd, "w+");
> 
>  printf("%s\n",pattern);
> 
> 
>  fprintf(f,"hi\n");
> 
> // to delete:  unlink(pattern);
> 
>  fclose(f);
> }
> 
> 
> 
> 
> On Thu, May 3, 2012 at 9:19 AM, Wolfgang Bangerth
> <bangerth at math.tamu.edu> wrote:
>> On 05/03/2012 10:13 AM, Eric Heien wrote:
>>> I'm not sure it's consistent among all platforms, but on the ones
>>> I've checked it doesn't say mkstemp() deletes the file, rather
>>> tmpfile() does (which actually doesn't delete but unlinks).  I'll try
>>> rewriting that section with mkstemp() today and see if it works.
>> 
>> Great, thanks. Let us know what you find!
>> W.
>> 
>> ------------------------------------------------------------------------
>> Wolfgang Bangerth               email:            bangerth at math.tamu.edu
>>                                 www: http://www.math.tamu.edu/~bangerth/
>> 
>> _______________________________________________
>> Aspect-devel mailing list
>> Aspect-devel at geodynamics.org
>> http://geodynamics.org/cgi-bin/mailman/listinfo/aspect-devel
> 
> 
> 
> -- 
> Timo Heister
> http://www.math.tamu.edu/~heister/
> _______________________________________________
> Aspect-devel mailing list
> Aspect-devel at geodynamics.org
> http://geodynamics.org/cgi-bin/mailman/listinfo/aspect-devel



More information about the Aspect-devel mailing list