summaryrefslogtreecommitdiff
path: root/include/fileutils.h
diff options
context:
space:
mode:
authorSami Kerola <kerolasa@iki.fi>2012-03-10 12:29:35 +0100
committerSami Kerola <kerolasa@iki.fi>2012-03-18 14:29:38 +0100
commit7961acce46283a29bd9e7629e515908848f8c9e1 (patch)
tree1d51f8d8ddf4959ace301df56d70e35248b65877 /include/fileutils.h
parentfd2e8c693e02c0b8ca0503e68bc9fe09dea4f0b2 (diff)
downloadutil-linux-7961acce46283a29bd9e7629e515908848f8c9e1.tar.gz
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 <kzak@redhat.com> CC: Davidlohr Bueso <dave@gnu.org> Reference: http://marc.info/?l=util-linux-ng&m=133129570124003&w=2 Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'include/fileutils.h')
-rw-r--r--include/fileutils.h16
1 files changed, 15 insertions, 1 deletions
diff --git a/include/fileutils.h b/include/fileutils.h
index 27b56619..691429ba 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