Thread (13 messages) flat view 13 messages, 6 authors, 2016-06-15

Re: [PATCH 1/2] Introduces xmkstemp()

From: Marius Storm-Olsen <hidden>
Date: 2016-06-15 22:43:31
Subsystem: the rest · Maintainer: Linus Torvalds

Luiz Fernando N. Capitulino said the following on 14.08.2007 21:44:
quoted hunk ↗ jump to hunk
This is a wrapper for mkstemp() that performs error checking and
calls die() when an error occur.

Signed-off-by: Luiz Fernando N. Capitulino <redacted>
---
 git-compat-util.h |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/git-compat-util.h b/git-compat-util.h
index 362e040..ca0a597 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -303,6 +303,16 @@ static inline FILE *xfdopen(int fd, const char *mode)
 	return stream;
 }
 
+static inline int xmkstemp(char *template)
+{
+	int fd;
+
+	fd = mkstemp(template);
+	if (fd < 0)
+		die("Unable to create temporary file: %s", strerror(errno));
+	return fd;
+}
+
 static inline size_t xsize_t(off_t len)
 {
 	return (size_t)len;
This functions needs to be further down in the file for
MinGW builds, since mkstemp() is forward declared later
in the file. So, something like this:
diff --git a/git-compat-util.h b/git-compat-util.h
index 9e075b7..f9ba8b0 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -477,4 +477,14 @@ extern __attribute__((noreturn)) int git_exit(int code);

 #endif /* __MINGW32__ */

+static inline int xmkstemp(char *template)
+{
+       int fd;
+
+       fd = mkstemp(template);
+       if (fd < 0)
+               die("Unable to create temporary file: %s", strerror(errno));
+       return fd;
+}
+
 #endif
-- 
.marius

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help