Skip to contentSkip to conversation

Document functions xmemdupz(), xread() and xwrite()

PATCH In review Heikki Orsila 2 participants 2 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Document functions xmemdupz(), xread() and xwrite()

---
 git-compat-util.h |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
git-compat-util.h +14 -0
index a18235e..7498bee 100644
@@ -268,6 +268,12 @@ static inline void *xmalloc(size_t size)
 	return ret;
 }
 
+/*
+ * xmemdupz() allocates (len + 1) bytes of memory, duplicates "len" bytes of
+ * "data" to the allocated memory, zero terminates the allocated memory,
+ * and returns a pointer to the allocated memory. If the allocation fails,
+ * the program dies.
+ */
 static inline void *xmemdupz(const void *data, size_t len)
 {
 	char *p = xmalloc(len + 1);
@@ -329,6 +335,11 @@ static inline void *xmmap(void *start, size_t length,
 	return ret;
 }
 
+/*
+ * xread() is the same a read(), but it automatically restarts read()
+ * operations with a recoverable error (EAGAIN and EINTR). xread()
+ * DOES NOT GUARANTEE that "len" bytes is read even if the data is available.
+ */
 static inline ssize_t xread(int fd, void *buf, size_t len)
 {
 	ssize_t nr;
@@ -340,6 +351,9 @@ static inline ssize_t xread(int fd, void *buf, size_t len)
 	}
 }
 
+/*
+ * xwrite() is similar to xread()
+ */
 static inline ssize_t xwrite(int fd, const void *buf, size_t len)
 {
 	ssize_t nr;
Signature · 1 line
1.5.4.4
#1 lore raw
Quoted 10 lines · Heikki Orsila
---
 git-compat-util.h |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
git-compat-util.h +0 -0
index a18235e..7498bee 100644

git-compat-util.h static inline void *xmalloc(size_t size) · line 276

Quoted 9 lines
git-compat-util.h +6 -0
@@ -268,6 +268,12 @@ static inline void *xmalloc(size_t size)
 	return ret;
 }
 
+/*
+ * xmemdupz() allocates (len + 1) bytes of memory, duplicates "len" bytes of
+ * "data" to the allocated memory, zero terminates the allocated memory,
+ * and returns a pointer to the allocated memory. If the allocation fails,
+ * the program dies.
+ */

Ok.

git-compat-util.h static inline void *xmmap(void *start, size_t length, · line 342

Quoted 12 lines
git-compat-util.h +5 -0
 static inline void *xmemdupz(const void *data, size_t len)
 {
 	char *p = xmalloc(len + 1);
@@ -329,6 +335,11 @@ static inline void *xmmap(void *start, size_t length,
 	return ret;
 }
 
+/*
+ * xread() is the same a read(), but it automatically restarts read()
+ * operations with a recoverable error (EAGAIN and EINTR). xread()
+ * DOES NOT GUARANTEE that "len" bytes is read even if the data is available.
+ */

Ok.

git-compat-util.h static inline ssize_t xread(int fd, void *buf, size_t len) · line 356

Quoted 10 lines
git-compat-util.h +3 -0
 static inline ssize_t xread(int fd, void *buf, size_t len)
 {
 	ssize_t nr;
@@ -340,6 +351,9 @@ static inline ssize_t xread(int fd, void *buf, size_t len)
 	}
 }
 
+/*
+ * xwrite() is similar to xread()
+ */

Well, up to "how recoverable errors are handled" they may be similar but would the last sentence apply to it as well, or does it need rewording?

Quoted 5 lines
git-compat-util.h +0 -0
 static inline ssize_t xwrite(int fd, const void *buf, size_t len)
 {
 	ssize_t nr;
Signature · 1 line
1.5.4.4