about.c: cosmetix
[k8lowj.git] / src / journalstore.c
blob869f01196938d983ca323e15407387ca56f1b169
1 /* logjam - a GTK client for LiveJournal.
2 * Copyright (C) 2000-2003 Evan Martin <evan@livejournal.com>
4 * vim: tabstop=4 shiftwidth=4 noexpandtab :
5 */
7 #include "glib-all.h"
8 #include <errno.h>
10 #include "conf.h"
11 #include "journalstore.h"
13 gboolean
14 journal_store_find_relative(JournalStore *js, gint itemid,
15 int *ritemid, int dir, GError *err) {
16 time_t when = journal_store_lookup_entry_time(js, itemid);
18 return journal_store_find_relative_by_time(js, when,
19 ritemid, dir, err);
22 char*
23 journal_store_get_lastsync(JournalStore *js) {
24 char *filename;
25 char *sync = NULL;
27 if (journal_store_get_invalid(js)) {
28 /* the journalstore was invalid; we need to resync. */
29 return NULL;
32 filename = conf_make_account_path(journal_store_get_account(js),
33 "lastsync");
34 if (g_file_get_contents(filename, &sync, NULL, NULL)) {
35 g_strchomp(sync);
36 } else {
37 sync = NULL;
39 g_free(filename);
40 return sync;
43 gboolean
44 journal_store_put_lastsync(JournalStore *js, const char *lastsync, GError **err) {
45 char *filename;
46 FILE *f;
48 filename = conf_make_account_path(journal_store_get_account(js),
49 "lastsync");
50 f = fopen(filename, "w");
51 if (f == NULL) {
52 g_set_error(err, 0, 0, _("Can't open '%s': %s"), filename,
53 g_strerror(errno));
54 g_free(filename);
55 return FALSE;
57 fprintf(f, "%s\n", lastsync);
58 fclose(f);
60 g_free(filename);
61 return TRUE;