Skip to content

Commit

Permalink
Fix mkstemp to properly fail on nonexclusive open
Browse files Browse the repository at this point in the history
  • Loading branch information
oriansj committed Nov 24, 2021
1 parent b9d2edf commit 222726e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions stdlib.c
Expand Up @@ -112,9 +112,10 @@ int mkstemp(char *template)
count = count - 1;
}

int F = -1;
int fd = -1;
count = -1;
while(-1 == F)
/* open will return -17 or other values */
while(0 > fd)
{
/* Just give up after the planet has blown up */
if(9000 < count) return -1;
Expand All @@ -124,9 +125,9 @@ int mkstemp(char *template)
__set_name(template+i+1, count);

/* Pray we can */
F = open(template, O_RDWR | O_CREAT | O_EXCL, 00600);
fd = open(template, O_RDWR | O_CREAT | O_EXCL, 00600);
}

/* well that only took count many tries */
return F;
return fd;
}

0 comments on commit 222726e

Please sign in to comment.