diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2020-01-18 17:17:46 +0000 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2020-01-24 15:12:56 -0600 |
commit | 2e8c3b0b18896ac8aeaed758da51f3ea9c133fe8 (patch) | |
tree | 7f5fee0daab370571aa4392eeef73069d0932a22 | |
parent | 9893d376eea1624870a844ef6644c837062b1751 (diff) | |
download | libgit2-2e8c3b0b18896ac8aeaed758da51f3ea9c133fe8.tar.gz |
oid functions: return an int
Stop returning a void for functions, future-proofing them to allow them
to fail.
-rw-r--r-- | include/git2/oid.h | 15 | ||||
-rw-r--r-- | src/oid.c | 20 |
2 files changed, 23 insertions, 12 deletions
diff --git a/include/git2/oid.h b/include/git2/oid.h index 8f27c1365..549df4eab 100644 --- a/include/git2/oid.h +++ b/include/git2/oid.h @@ -73,8 +73,9 @@ GIT_EXTERN(int) git_oid_fromstrn(git_oid *out, const char *str, size_t length); * * @param out oid structure the result is written into. * @param raw the raw input bytes to be copied. + * @return 0 on success or error code */ -GIT_EXTERN(void) git_oid_fromraw(git_oid *out, const unsigned char *raw); +GIT_EXTERN(int) git_oid_fromraw(git_oid *out, const unsigned char *raw); /** * Format a git_oid into a hex string. @@ -85,8 +86,9 @@ GIT_EXTERN(void) git_oid_fromraw(git_oid *out, const unsigned char *raw); * oid digits are written; a '\\0' terminator must be added * by the caller if it is required. * @param id oid structure to format. + * @return 0 on success or error code */ -GIT_EXTERN(void) git_oid_fmt(char *out, const git_oid *id); +GIT_EXTERN(int) git_oid_fmt(char *out, const git_oid *id); /** * Format a git_oid into a partial hex string. @@ -96,8 +98,9 @@ GIT_EXTERN(void) git_oid_fmt(char *out, const git_oid *id); * will be zeroed; if not, a '\0' terminator is NOT added. * @param n number of characters to write into out string * @param id oid structure to format. + * @return 0 on success or error code */ -GIT_EXTERN(void) git_oid_nfmt(char *out, size_t n, const git_oid *id); +GIT_EXTERN(int) git_oid_nfmt(char *out, size_t n, const git_oid *id); /** * Format a git_oid into a loose-object path string. @@ -111,8 +114,9 @@ GIT_EXTERN(void) git_oid_nfmt(char *out, size_t n, const git_oid *id); * oid digits are written; a '\\0' terminator must be added * by the caller if it is required. * @param id oid structure to format. + * @return 0 on success, non-zero callback return value, or error code */ -GIT_EXTERN(void) git_oid_pathfmt(char *out, const git_oid *id); +GIT_EXTERN(int) git_oid_pathfmt(char *out, const git_oid *id); /** * Format a git_oid into a statically allocated c-string. @@ -151,8 +155,9 @@ GIT_EXTERN(char *) git_oid_tostr(char *out, size_t n, const git_oid *id); * * @param out oid structure the result is written into. * @param src oid structure to copy from. + * @return 0 on success or error code */ -GIT_EXTERN(void) git_oid_cpy(git_oid *out, const git_oid *src); +GIT_EXTERN(int) git_oid_cpy(git_oid *out, const git_oid *src); /** * Compare two oid structures. @@ -64,13 +64,13 @@ GIT_INLINE(char) *fmt_one(char *str, unsigned int val) return str; } -void git_oid_nfmt(char *str, size_t n, const git_oid *oid) +int git_oid_nfmt(char *str, size_t n, const git_oid *oid) { size_t i, max_i; if (!oid) { memset(str, 0, n); - return; + return 0; } if (n > GIT_OID_HEXSZ) { memset(&str[GIT_OID_HEXSZ], 0, n - GIT_OID_HEXSZ); @@ -84,14 +84,16 @@ void git_oid_nfmt(char *str, size_t n, const git_oid *oid) if (n & 1) *str++ = to_hex[oid->id[i] >> 4]; + + return 0; } -void git_oid_fmt(char *str, const git_oid *oid) +int git_oid_fmt(char *str, const git_oid *oid) { - git_oid_nfmt(str, GIT_OID_HEXSZ, oid); + return git_oid_nfmt(str, GIT_OID_HEXSZ, oid); } -void git_oid_pathfmt(char *str, const git_oid *oid) +int git_oid_pathfmt(char *str, const git_oid *oid) { size_t i; @@ -99,6 +101,8 @@ void git_oid_pathfmt(char *str, const git_oid *oid) *str++ = '/'; for (i = 1; i < sizeof(oid->id); i++) str = fmt_one(str, oid->id[i]); + + return 0; } char *git_oid_tostr_s(const git_oid *oid) @@ -167,14 +171,16 @@ void git_oid__writebuf(git_buf *buf, const char *header, const git_oid *oid) git_buf_putc(buf, '\n'); } -void git_oid_fromraw(git_oid *out, const unsigned char *raw) +int git_oid_fromraw(git_oid *out, const unsigned char *raw) { memcpy(out->id, raw, sizeof(out->id)); + return 0; } -void git_oid_cpy(git_oid *out, const git_oid *src) +int git_oid_cpy(git_oid *out, const git_oid *src) { memcpy(out->id, src->id, sizeof(out->id)); + return 0; } int git_oid_cmp(const git_oid *a, const git_oid *b) |