@@ -268,6 +268,12 @@ static inline void *xmalloc(size_t size)
268268 return ret ;
269269}
270270
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+ */
271277static inline void * xmemdupz (const void * data , size_t len )
272278{
273279 char * p = xmalloc (len + 1 );
@@ -329,6 +335,11 @@ static inline void *xmmap(void *start, size_t length,
329335 return ret ;
330336}
331337
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+ */
332343static inline ssize_t xread (int fd , void * buf , size_t len )
333344{
334345 ssize_t nr ;
@@ -340,6 +351,11 @@ static inline ssize_t xread(int fd, void *buf, size_t len)
340351 }
341352}
342353
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+ */
343359static inline ssize_t xwrite (int fd , const void * buf , size_t len )
344360{
345361 ssize_t nr ;
0 commit comments