mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 00:30:53 +00:00
Use mkstemp if available
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3634 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
205c020662
commit
a6e2199d65
4 changed files with 373 additions and 215 deletions
|
@ -500,7 +500,29 @@ failure:
|
|||
NSLog(@"Open (%s) attempt failed - bad path", theRealPath);
|
||||
return NO;
|
||||
}
|
||||
#ifdef HAVE_MKSTEMP
|
||||
if (useAuxiliaryFile)
|
||||
{
|
||||
int desc;
|
||||
|
||||
strcpy(thePath, theRealPath);
|
||||
strcat(thePath, "XXXXXX");
|
||||
if ((desc = mktemp(thePath)) < 0)
|
||||
{
|
||||
NSLog(@"mkstemp (%s) failed - %s", thePath, strerror(errno));
|
||||
goto failure;
|
||||
}
|
||||
if ((theFile = fdopen(desc, "w")) == 0)
|
||||
{
|
||||
close(desc);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(thePath, theRealPath);
|
||||
theFile = fopen(thePath, "w");
|
||||
}
|
||||
#else
|
||||
if (useAuxiliaryFile)
|
||||
{
|
||||
/* Use the path name of the destination file as a prefix for the
|
||||
|
@ -521,6 +543,7 @@ failure:
|
|||
|
||||
/* Open the file (whether temp or real) for writing. */
|
||||
theFile = fopen(thePath, "w");
|
||||
#endif
|
||||
|
||||
if (theFile == NULL) /* Something went wrong; we weren't
|
||||
* even able to open the file. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue