~ubuntu-branches/ubuntu/trusty/musl/trusty-proposed

« back to all changes in this revision

Viewing changes to src/stdio/tmpfile.c

  • Committer: Package Import Robot
  • Author(s): Kevin Bortis
  • Date: 2013-09-20 20:54:14 UTC
  • Revision ID: package-import@ubuntu.com-20130920205414-5b61trtmma18w58o
Tags: upstream-0.9.13
ImportĀ upstreamĀ versionĀ 0.9.13

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <fcntl.h>
 
3
#include <unistd.h>
 
4
#include "stdio_impl.h"
 
5
 
 
6
#define MAXTRIES 100
 
7
 
 
8
FILE *tmpfile(void)
 
9
{
 
10
        char buf[L_tmpnam], *s;
 
11
        int fd;
 
12
        FILE *f;
 
13
        int try;
 
14
        for (try=0; try<MAXTRIES; try++) {
 
15
                s = tmpnam(buf);
 
16
                if (!s) return 0;
 
17
                fd = syscall(SYS_open, s, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600);
 
18
                if (fd >= 0) {
 
19
                        f = __fdopen(fd, "w+");
 
20
                        __syscall(SYS_unlink, s);
 
21
                        return f;
 
22
                }
 
23
        }
 
24
        return 0;
 
25
}
 
26
 
 
27
LFS64(tmpfile);