mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Add tmpfile(3).
This commit is contained in:
parent
8b7dad7d4d
commit
8cc4c6cb03
3 changed files with 41 additions and 1 deletions
|
@ -325,6 +325,7 @@ sys/socket/socketpair.o \
|
||||||
system.o \
|
system.o \
|
||||||
tfork.o \
|
tfork.o \
|
||||||
time.o \
|
time.o \
|
||||||
|
tmpfile.o \
|
||||||
truncateat.o \
|
truncateat.o \
|
||||||
truncate.o \
|
truncate.o \
|
||||||
ttyname.o \
|
ttyname.o \
|
||||||
|
|
|
@ -117,6 +117,7 @@ extern int sortix_puts(const char* str);
|
||||||
extern int sprintf(char* restrict s, const char* restrict format, ...);
|
extern int sprintf(char* restrict s, const char* restrict format, ...);
|
||||||
extern int scanf(const char* restrict format, ...);
|
extern int scanf(const char* restrict format, ...);
|
||||||
extern int sscanf(const char* restrict s, const char* restrict format, ...);
|
extern int sscanf(const char* restrict s, const char* restrict format, ...);
|
||||||
|
extern FILE* tmpfile(void);
|
||||||
extern int ungetc(int c, FILE* stream);
|
extern int ungetc(int c, FILE* stream);
|
||||||
extern int vfprintf(FILE* restrict stream, const char* restrict format, __gnuc_va_list ap);
|
extern int vfprintf(FILE* restrict stream, const char* restrict format, __gnuc_va_list ap);
|
||||||
extern int vfscanf(FILE* restrict stream, const char* restrict format, __gnuc_va_list arg);
|
extern int vfscanf(FILE* restrict stream, const char* restrict format, __gnuc_va_list arg);
|
||||||
|
@ -131,7 +132,6 @@ extern int vsscanf(const char* restrict s, const char* restrict format, __gnuc_v
|
||||||
extern char* ctermid(char* s);
|
extern char* ctermid(char* s);
|
||||||
extern FILE *fmemopen(void* restrict buf, size_t size, const char* restrict mode);
|
extern FILE *fmemopen(void* restrict buf, size_t size, const char* restrict mode);
|
||||||
extern FILE* open_memstream(char** bufp, size_t* sizep);
|
extern FILE* open_memstream(char** bufp, size_t* sizep);
|
||||||
extern FILE* tmpfile(void);
|
|
||||||
extern int dprintf(int fildes, const char* restrict format, ...);
|
extern int dprintf(int fildes, const char* restrict format, ...);
|
||||||
extern int fgetpos(FILE* restrict stream, fpos_t* restrict pos);
|
extern int fgetpos(FILE* restrict stream, fpos_t* restrict pos);
|
||||||
extern int fsetpos(FILE* stream, const fpos_t* pos);
|
extern int fsetpos(FILE* stream, const fpos_t* pos);
|
||||||
|
|
39
libc/tmpfile.cpp
Normal file
39
libc/tmpfile.cpp
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
||||||
|
|
||||||
|
This file is part of the Sortix C Library.
|
||||||
|
|
||||||
|
The Sortix C Library is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
option) any later version.
|
||||||
|
|
||||||
|
The Sortix C Library is distributed in the hope that it will be useful, but
|
||||||
|
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
tmpfile.cpp
|
||||||
|
Opens an unnamed temporary file.
|
||||||
|
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
extern "C" FILE* tmpfile()
|
||||||
|
{
|
||||||
|
char name[5 + sizeof(pid_t) * 3];
|
||||||
|
snprintf(name, sizeof(name), "/tmp/%ju", (uintmax_t) getpid());
|
||||||
|
FILE* ret = fopen(name, "w+");
|
||||||
|
if ( !ret )
|
||||||
|
return NULL;
|
||||||
|
unlink(name);
|
||||||
|
return ret;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue