Document functions xmemdupz(), xread() and xwrite()
Signed-off-by: Heikki Orsila <heikki.orsila@iki.fi> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Heikki Orsila committed
Apr 27, 2008 at 12:48 UTC
e8729f5380788855943c69f749eb5e276c3b8310
1 file changed
+16
git-compat-util.h
+16
@@ -268,6 +268,12 @@ static inline void *xmalloc(size_t size)
268
return ret;
269
}
270
271
+/*
272
+ * xmemdupz() allocates (len + 1) bytes of memory, duplicates "len" bytes of
273
+ * "data" to the allocated memory, zero terminates the allocated memory,
274
+ * and returns a pointer to the allocated memory. If the allocation fails,
275
+ * the program dies.
276
+ */
277
static inline void *xmemdupz(const void *data, size_t len)
278
{
279
char *p = xmalloc(len + 1);
@@ -329,6 +335,11 @@ static inline void *xmmap(void *start, size_t length,
335
return ret;
336
}
337
338
+/*
339
+ * xread() is the same a read(), but it automatically restarts read()
340
+ * operations with a recoverable error (EAGAIN and EINTR). xread()
341
+ * DOES NOT GUARANTEE that "len" bytes is read even if the data is available.
342
+ */
343
static inline ssize_t xread(int fd, void *buf, size_t len)
344
{
345
ssize_t nr;
@@ -340,6 +351,11 @@ static inline ssize_t xread(int fd, void *buf, size_t len)
351
}
352
}
353
354
+/*
355
+ * xwrite() is the same a write(), but it automatically restarts write()
356
+ * operations with a recoverable error (EAGAIN and EINTR). xwrite() DOES NOT
357
+ * GUARANTEE that "len" bytes is written even if the operation is successful.
358
+ */
359
static inline ssize_t xwrite(int fd, const void *buf, size_t len)
360
{
361
ssize_t nr;