[aspect-devel] mktemp failure

Timo Heister heister at math.tamu.edu
Thu May 3 08:18:35 PDT 2012


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/


More information about the Aspect-devel mailing list