lib: eliminate fprintf from _notmuch_message_file_open

You may wonder why _notmuch_message_file_open_ctx has two parameters.
This is because we need sometime to use a ctx which is a
notmuch_message_t. While we could get the database from this, there is
no easy way in C to tell type we are getting.
This commit is contained in:
David Bremner 2014-12-26 18:34:49 +01:00
parent 736ac26407
commit 9d192da683
4 changed files with 13 additions and 8 deletions

View file

@ -2314,7 +2314,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
if (ret)
return ret;
message_file = _notmuch_message_file_open (filename);
message_file = _notmuch_message_file_open (notmuch, filename);
if (message_file == NULL)
return NOTMUCH_STATUS_FILE_ERROR;

View file

@ -76,7 +76,8 @@ _notmuch_message_file_destructor (notmuch_message_file_t *message)
/* Create a new notmuch_message_file_t for 'filename' with 'ctx' as
* the talloc owner. */
notmuch_message_file_t *
_notmuch_message_file_open_ctx (void *ctx, const char *filename)
_notmuch_message_file_open_ctx (notmuch_database_t *notmuch,
void *ctx, const char *filename)
{
notmuch_message_file_t *message;
@ -98,16 +99,18 @@ _notmuch_message_file_open_ctx (void *ctx, const char *filename)
return message;
FAIL:
fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno));
_notmuch_database_log (notmuch, "Error opening %s: %s\n",
filename, strerror (errno));
_notmuch_message_file_close (message);
return NULL;
}
notmuch_message_file_t *
_notmuch_message_file_open (const char *filename)
_notmuch_message_file_open (notmuch_database_t *notmuch,
const char *filename)
{
return _notmuch_message_file_open_ctx (NULL, filename);
return _notmuch_message_file_open_ctx (notmuch, NULL, filename);
}
void

View file

@ -437,7 +437,8 @@ _notmuch_message_ensure_message_file (notmuch_message_t *message)
if (unlikely (filename == NULL))
return;
message->message_file = _notmuch_message_file_open_ctx (message, filename);
message->message_file = _notmuch_message_file_open_ctx (
_notmuch_message_database (message), message, filename);
}
const char *

View file

@ -358,11 +358,12 @@ typedef struct _notmuch_message_file notmuch_message_file_t;
* Returns NULL if any error occurs.
*/
notmuch_message_file_t *
_notmuch_message_file_open (const char *filename);
_notmuch_message_file_open (notmuch_database_t *notmuch, const char *filename);
/* Like notmuch_message_file_open but with 'ctx' as the talloc owner. */
notmuch_message_file_t *
_notmuch_message_file_open_ctx (void *ctx, const char *filename);
_notmuch_message_file_open_ctx (notmuch_database_t *notmuch,
void *ctx, const char *filename);
/* Close a notmuch message previously opened with notmuch_message_open. */
void