git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Document functions xmemdupz(), xread() and xwrite()

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 27, 2008, 06:12 UTC
Message-ID
<7viqy3j07f.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20080424235823.GA22898@zakalwe.fi>
Heikki Orsila <heikki.orsila@iki.fi> writes:
Show 19 quoted lines
> Signed-off-by: Heikki Orsila <heikki.orsila@iki.fi>
> ---
>  git-compat-util.h |   14 ++++++++++++++
>  1 files changed, 14 insertions(+), 0 deletions(-)
>
> diff --git a/git-compat-util.h b/git-compat-util.h
> index a18235e..7498bee 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -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.
Show 12 quoted lines
>  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.
Show 10 quoted lines
>  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?

Show 5 quoted lines
>  static inline ssize_t xwrite(int fd, const void *buf, size_t len)
>  {
>  	ssize_t nr;
> -- 
> 1.5.4.4
Previous: Heikki Orsila
Message 2 of 2 in “Document functions xmemdupz(), xread() and xwrite()”
  1. Document functions xmemdupz(), xread() and xwrite()Heikki Orsila, Apr 24, 2008
  2. Junio C HamanoApr 27, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.