Skip to contentSkip to conversation

strbuf: describe the return value of strbuf_read_file()

PATCH In review Pranit Bauva 2 participants 3 messages Jun 16, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 strbuf: describe the return value of strbuf_read_file()

---
It is easy to be misguided on the return value of the function strbuf_read_file(). It does follow the pattern of other standard functions for reading files but its better to explicitly specify it.

 strbuf.h | 2 ++
 1 file changed, 2 insertions(+)
strbuf.h +2 -0
index 7987405..4b487f7 100644
@@ -377,6 +377,8 @@ extern ssize_t strbuf_read_once(struct strbuf *, int fd, size_t hint);
 /**
  * Read the contents of a file, specified by its path. The third argument
  * can be used to give a hint about the file size, to avoid reallocs.
+ * Return the number of bytes read or -1 if some error occurred while
+ * opening or reading the file.
  */
 extern ssize_t strbuf_read_file(struct strbuf *sb, const char *path, size_t hint);
 
Signature · 1 line
2.8.4
#1 lore raw
Quoted 7 lines · Pranit Bauva

---
It is easy to be misguided on the return value of the function strbuf_read_file(). It does follow the pattern of other standard functions for reading files but its better to explicitly specify it.

Good thing to do; I wonder if we want to explicitly say -1 or leave it at "negative values are errors", though (my knee-jerk reaction being "do not over-specify more than absolute minimum to write callers correctly").

Quoted 16 lines
 strbuf.h | 2 ++
 1 file changed, 2 insertions(+)
strbuf.h +2 -0
index 7987405..4b487f7 100644
@@ -377,6 +377,8 @@ extern ssize_t strbuf_read_once(struct strbuf *, int fd, size_t hint);
 /**
  * Read the contents of a file, specified by its path. The third argument
  * can be used to give a hint about the file size, to avoid reallocs.
+ * Return the number of bytes read or -1 if some error occurred while
+ * opening or reading the file.
  */
 extern ssize_t strbuf_read_file(struct strbuf *sb, const char *path, size_t hint);
#2 lore raw

Hey Junio,

Quoted 8 lines · Junio C Hamano
Quoted 3 lines

It is easy to be misguided on the return value of the function strbuf_read_file(). It does follow the pattern of other standard functions for reading files but its better to explicitly specify it.

Good thing to do; I wonder if we want to explicitly say -1 or leave it at "negative values are errors", though (my knee-jerk reaction being "do not over-specify more than absolute minimum to write callers correctly").

Sure I will re-roll with specifying about negative values as errors.

Regards,
Pranit Bauva