Commit 2e8c3b0b by Edward Thomson

oid functions: return an int

Stop returning a void for functions, future-proofing them to allow them
to fail.
parent 9893d376
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment