diff options
author | schu <schu-github@schulog.org> | 2011-08-03 17:57:33 +0400 |
---|---|---|
committer | schu <schu-github@schulog.org> | 2011-08-03 18:05:32 +0400 |
commit | 63396a3998610ea1e3555b15a26051525e00e58e (patch) | |
tree | 718bf96b9d66d3bfd42fbfd749c85ae72dc9234b /src/signature.c | |
parent | 5274c31a89ec9075cc74ff189f6264a976c04571 (diff) |
signature: adjust API to return error codes
git_signature_new() and git_signature_now() currently don't return error
codes. Change the API to return error codes and not pointers to let the
user handle errors properly.
Signed-off-by: schu <schu-github@schulog.org>
Diffstat (limited to 'src/signature.c')
-rw-r--r-- | src/signature.c | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/src/signature.c b/src/signature.c index 7116db572..327efe247 100644 --- a/src/signature.c +++ b/src/signature.c @@ -81,15 +81,19 @@ static int process_trimming(const char *input, char **storage, const char *input return GIT_SUCCESS; } -git_signature *git_signature_new(const char *name, const char *email, git_time_t time, int offset) +int git_signature_new(git_signature **sig_out, const char *name, const char *email, git_time_t time, int offset) { int error; git_signature *p = NULL; assert(name && email); - if ((p = git__malloc(sizeof(git_signature))) == NULL) + *sig_out = NULL; + + if ((p = git__malloc(sizeof(git_signature))) == NULL) { + error = GIT_ENOMEM; goto cleanup; + } memset(p, 0x0, sizeof(git_signature)); @@ -108,28 +112,37 @@ git_signature *git_signature_new(const char *name, const char *email, git_time_t p->when.time = time; p->when.offset = offset; - return p; + *sig_out = p; + + return error; cleanup: git_signature_free(p); - return NULL; + return error; } git_signature *git_signature_dup(const git_signature *sig) { - return git_signature_new(sig->name, sig->email, sig->when.time, sig->when.offset); + git_signature *new; + if (git_signature_new(&new, sig->name, sig->email, sig->when.time, sig->when.offset) < GIT_SUCCESS) + return NULL; + return new; } -git_signature *git_signature_now(const char *name, const char *email) +int git_signature_now(git_signature **sig_out, const char *name, const char *email) { + int error; time_t now; time_t offset; struct tm *utc_tm, *local_tm; + git_signature *sig; #ifndef GIT_WIN32 struct tm _utc, _local; #endif + *sig_out = NULL; + time(&now); /** @@ -151,7 +164,12 @@ git_signature *git_signature_now(const char *name, const char *email) if (local_tm->tm_isdst) offset += 60; - return git_signature_new(name, email, now, (int)offset); + if ((error = git_signature_new(&sig, name, email, now, (int)offset)) < GIT_SUCCESS) + return error; + + *sig_out = sig; + + return error; } static int parse_timezone_offset(const char *buffer, int *offset_out) |