+static char *rcfile = NULL;
+
+bool alternative_datafile = FALSE;
+bool alternative_rcfile = FALSE;
+
+static int
+datafile_writeable()
+{
+ FILE *f;
+
+ assert(datafile != NULL);
+
+ if( (f = fopen(datafile, "a")) == NULL)
+ return FALSE;
+
+ fclose(f);
+
+ return TRUE;
+}
+
+static void
+check_abook_directory()
+{
+ struct stat s;
+ char *dir;
+
+ assert(!is_ui_initialized());
+
+ if(alternative_datafile)
+ return;
+
+ dir = strconcat(getenv("HOME"), "/" DIR_IN_HOME, NULL);
+ assert(dir != NULL);
+
+ if(stat(dir, &s) == -1) {
+ if(errno != ENOENT) {
+ perror(dir);
+ free(dir);
+ exit(EXIT_FAILURE);
+ }
+ if(mkdir(dir, 0700) == -1) {
+ printf(_("Cannot create directory %s\n"), dir);
+ perror(dir);
+ free(dir);
+ exit(EXIT_FAILURE);
+ }
+ } else if(!S_ISDIR(s.st_mode)) {
+ printf(_("%s is not a directory\n"), dir);
+ free(dir);
+ exit(EXIT_FAILURE);
+ }
+
+ free(dir);
+}
+
+static void
+xmalloc_error_handler(int err)
+{
+ /*
+ * We don't try to save addressbook here because we don't know
+ * if it's fully loaded to memory.
+ */
+ if(is_ui_initialized())
+ close_ui();
+
+ fprintf(stderr, _("Memory allocation failure: %s\n"), strerror(err));
+ exit(EXIT_FAILURE);
+}