relative paths; open #9/ndb/local
This commit is contained in:
parent
87a52e0485
commit
34d1b690ef
1 changed files with 17 additions and 7 deletions
|
|
@ -5,10 +5,10 @@
|
||||||
#include <ndb.h>
|
#include <ndb.h>
|
||||||
#include "ndbhf.h"
|
#include "ndbhf.h"
|
||||||
|
|
||||||
static Ndb* doopen(char*);
|
static Ndb* doopen(char*, char*);
|
||||||
static void hffree(Ndb*);
|
static void hffree(Ndb*);
|
||||||
|
|
||||||
static char *deffile = "/lib/ndb/local";
|
static char *deffile = "#9/ndb/local";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* the database entry in 'file' indicates the list of files
|
* the database entry in 'file' indicates the list of files
|
||||||
|
|
@ -23,8 +23,8 @@ ndbopen(char *file)
|
||||||
Ndbtuple *t, *nt;
|
Ndbtuple *t, *nt;
|
||||||
|
|
||||||
if(file == 0)
|
if(file == 0)
|
||||||
file = deffile;
|
file = unsharp(deffile);
|
||||||
db = doopen(file);
|
db = doopen(file, nil);
|
||||||
if(db == 0)
|
if(db == 0)
|
||||||
return 0;
|
return 0;
|
||||||
first = last = db;
|
first = last = db;
|
||||||
|
|
@ -48,7 +48,7 @@ ndbopen(char *file)
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
db = doopen(nt->val);
|
db = doopen(nt->val, file);
|
||||||
if(db == 0)
|
if(db == 0)
|
||||||
continue;
|
continue;
|
||||||
last->next = db;
|
last->next = db;
|
||||||
|
|
@ -62,15 +62,25 @@ ndbopen(char *file)
|
||||||
* open a single file
|
* open a single file
|
||||||
*/
|
*/
|
||||||
static Ndb*
|
static Ndb*
|
||||||
doopen(char *file)
|
doopen(char *file, char *rel)
|
||||||
{
|
{
|
||||||
|
char *p;
|
||||||
Ndb *db;
|
Ndb *db;
|
||||||
|
|
||||||
db = (Ndb*)malloc(sizeof(Ndb));
|
db = (Ndb*)malloc(sizeof(Ndb));
|
||||||
if(db == 0)
|
if(db == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
memset(db, 0, sizeof(Ndb));
|
memset(db, 0, sizeof(Ndb));
|
||||||
strncpy(db->file, file, sizeof(db->file)-1);
|
/*
|
||||||
|
* Rooted paths are taken as is.
|
||||||
|
* Unrooted paths are taken relative to db we opened.
|
||||||
|
*/
|
||||||
|
if(file[0]!='/' && rel && (p=strrchr(rel, '/'))!=nil)
|
||||||
|
snprint(db->file, sizeof(db->file), "%.*s/%s",
|
||||||
|
utfnlen(rel, p-rel), rel, file);
|
||||||
|
else
|
||||||
|
strncpy(db->file, file, sizeof(db->file)-1);
|
||||||
|
|
||||||
if(ndbreopen(db) < 0){
|
if(ndbreopen(db) < 0){
|
||||||
free(db);
|
free(db);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue