/[global]/global/libutil/dbop.c
ViewVC logotype

Diff of /global/libutil/dbop.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.28 by shigio, Sat Nov 5 14:07:10 2005 UTC revision 1.29 by shigio, Thu Nov 17 03:11:27 2005 UTC
# Line 104  dbop_open(const char *path, int mode, in Line 104  dbop_open(const char *path, int mode, in
104           * if unlink do job normally, those who already open tag file can use           * if unlink do job normally, those who already open tag file can use
105           * it until closing.           * it until closing.
106           */           */
107          if (mode == 1 && test("f", path))          if (path != NULL && mode == 1 && test("f", path))
108                  (void)unlink(path);                  (void)unlink(path);
109          db = dbopen(path, rw, 0600, DB_BTREE, &info);          db = dbopen(path, rw, 0600, DB_BTREE, &info);
110          if (!db)          if (!db)
111                  return NULL;                  return NULL;
112          if (!(dbop = (DBOP *)malloc(sizeof(DBOP))))          if (!(dbop = (DBOP *)malloc(sizeof(DBOP))))
113                  die("short of memory.");                  die("short of memory.");
114          strlimcpy(dbop->dbname, path, sizeof(dbop->dbname));          if (path == NULL)
115                    dbop->dbname[0] = '\0';
116            else
117                    strlimcpy(dbop->dbname, path, sizeof(dbop->dbname));
118          dbop->db        = db;          dbop->db        = db;
119          dbop->openflags = flags;          dbop->openflags = flags;
120          dbop->perm      = (mode == 1) ? perm : 0;          dbop->perm      = (mode == 1) ? perm : 0;
# Line 407  dbop_close(DBOP *dbop) Line 410  dbop_close(DBOP *dbop)
410          /*          /*
411           * If DBOP_REMOVE is specified, omit writing to the disk in __bt_close().           * If DBOP_REMOVE is specified, omit writing to the disk in __bt_close().
412           */           */
413          (void)db->close(db, (dbop->openflags & DBOP_REMOVE) ? 1 : 0);          (void)db->close(db, (dbop->openflags & DBOP_REMOVE || dbop->dbname[0] == '\0') ? 1 : 0);
414  #endif  #endif
415          if (dbop->openflags & DBOP_REMOVE)          if (dbop->dbname[0] != '\0') {
416                  (void)unlink(dbop->dbname);                  if (dbop->openflags & DBOP_REMOVE)
417          else if (dbop->perm && chmod(dbop->dbname, dbop->perm) < 0)                          (void)unlink(dbop->dbname);
418                  die("cannot change file mode.");                  else if (dbop->perm && chmod(dbop->dbname, dbop->perm) < 0)
419                            die("cannot change file mode.");
420            }
421          (void)free(dbop);          (void)free(dbop);
422  }  }

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.29

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26