Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Gregory <andrew.gregory.8@gmail.com>2015-04-12 00:01:23 -0400
committerAllan McRae <allan@archlinux.org>2015-05-12 14:00:55 +1000
commit9a9e0203de9a440be0e359a36bf55151ffb51ca6 (patch)
treeead63e3c4874e59f222160c8a80d799b0e13966a /lib
parent1545a042535a8c73c1fa5e0a8bc399394f553a4f (diff)
alpm_logaction: implement documented return value
"return 0 on success, -1 on error (pm_errno is set accordingly)" Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/libalpm/log.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/lib/libalpm/log.c b/lib/libalpm/log.c
index 602dd371..43837357 100644
--- a/lib/libalpm/log.c
+++ b/lib/libalpm/log.c
@@ -34,6 +34,17 @@
* @{
*/
+static int _alpm_log_leader(FILE *f, const char *prefix)
+{
+ time_t t = time(NULL);
+ struct tm *tm = localtime(&t);
+
+ /* Use ISO-8601 date format */
+ return fprintf(f, "[%04d-%02d-%02d %02d:%02d] [%s] ",
+ tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
+ tm->tm_hour, tm->tm_min, prefix);
+}
+
/** A printf-like function for logging.
* @param handle the context handle
* @param prefix caller-specific prefix for the log
@@ -84,14 +95,11 @@ int SYMEXPORT alpm_logaction(alpm_handle_t *handle, const char *prefix,
}
if(handle->logstream) {
- time_t t = time(NULL);
- struct tm *tm = localtime(&t);
-
- /* Use ISO-8601 date format */
- fprintf(handle->logstream, "[%04d-%02d-%02d %02d:%02d] [%s] ",
- tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
- tm->tm_hour, tm->tm_min, prefix);
- ret = vfprintf(handle->logstream, fmt, args);
+ if(_alpm_log_leader(handle->logstream, prefix) < 0
+ || vfprintf(handle->logstream, fmt, args) < 0) {
+ ret = -1;
+ handle->pm_errno = ALPM_ERR_SYSTEM;
+ }
fflush(handle->logstream);
}