From: handa Date: Thu, 14 Sep 2006 00:56:44 +0000 (+0000) Subject: Include . X-Git-Tag: REL-1-3-4~66 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2e9eb4e2271f98c142f98028eaf31c928283a79;p=m17n%2Fm17n-lib.git Include . (mdatabase__lock): Make a directory if necessary. --- diff --git a/src/database.c b/src/database.c index 68f788c..614fb9f 100644 --- a/src/database.c +++ b/src/database.c @@ -134,6 +134,7 @@ #include #include #include +#include #include "m17n.h" #include "m17n-misc.h" @@ -1030,10 +1031,20 @@ mdatabase__lock (MDatabase *mdb) fp = fopen (db_info->uniq_file, "w"); if (! fp) { - free (db_info->uniq_file); - free (db_info->lock_file); - db_info->lock_file = NULL; - return -1; + char *str = strdup (db_info->uniq_file); + char *dir = dirname (str); + + if (stat (dir, &buf) == 0 + || mkdir (dir, 0777) < 0 + || ! (fp = fopen (db_info->uniq_file, "w"))) + { + free (db_info->uniq_file); + free (db_info->lock_file); + db_info->lock_file = NULL; + free (str); + return -1; + } + free (str); } fclose (fp); if (link (db_info->uniq_file, db_info->lock_file) < 0