ape/mkstemp: better options
Use O_EXCL and make the file descriptor writeable. This is more usefull and it conforms to Single Unix and other specs.
This commit is contained in:
parent
370bfd26ce
commit
bf322dfbf3
|
@ -1,6 +1,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
mkstemp(char *template)
|
mkstemp(char *template)
|
||||||
|
@ -14,7 +15,7 @@ mkstemp(char *template)
|
||||||
for(i=0; i<20; i++){
|
for(i=0; i<20; i++){
|
||||||
strcpy(s, template);
|
strcpy(s, template);
|
||||||
mktemp(s);
|
mktemp(s);
|
||||||
if((fd = creat(s, 0666)) >= 0){
|
if((fd = open(s, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0){
|
||||||
strcpy(template, s);
|
strcpy(template, s);
|
||||||
free(s);
|
free(s);
|
||||||
return fd;
|
return fd;
|
||||||
|
|
Loading…
Reference in a new issue