From 7961acce46283a29bd9e7629e515908848f8c9e1 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sat, 10 Mar 2012 12:29:35 +0100 Subject: fileutils: differentiate xmkstemp and xfmkstemp Let developer to choose, case by case, what sort of return value is best in her code. The xmkstemp() is for users who want file descriptor as return value of the function, xfmkstemp() will return FILE pointer. Proposed-By: Karel Zak CC: Davidlohr Bueso Reference: http://marc.info/?l=util-linux-ng&m=133129570124003&w=2 Signed-off-by: Sami Kerola --- include/fileutils.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'include/fileutils.h') diff --git a/include/fileutils.h b/include/fileutils.h index 27b566190..691429ba0 100644 --- a/include/fileutils.h +++ b/include/fileutils.h @@ -1,6 +1,20 @@ #ifndef UTIL_LINUX_FILEUTILS #define UTIL_LINUX_FILEUTILS -extern FILE * xmkstemp(char **tmpname); +extern int xmkstemp(char **tmpname); +static inline FILE *xfmkstemp(char **tmpname) +{ + int fd; + FILE *ret; + fd = xmkstemp(tmpname); + if (fd == -1) { + return NULL; + } + if (!(ret = fdopen(fd, "w+"))) { + close(fd); + return NULL; + } + return ret; +} #endif -- cgit v1.2.3-55-g7522