Created xmldb plugin api
This commit is contained in:
parent
4169bd8d30
commit
f6b3e95100
39 changed files with 492 additions and 504 deletions
|
|
@ -58,7 +58,6 @@
|
|||
/* clicon */
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_chunk.h"
|
||||
#include "clixon_string.h"
|
||||
#include "clixon_file.h"
|
||||
|
||||
|
|
@ -66,7 +65,8 @@
|
|||
* qsort function
|
||||
*/
|
||||
static int
|
||||
clicon_file_dirent_sort(const void* arg1, const void* arg2)
|
||||
clicon_file_dirent_sort(const void* arg1,
|
||||
const void* arg2)
|
||||
{
|
||||
struct dirent *d1 = (struct dirent *)arg1;
|
||||
struct dirent *d2 = (struct dirent *)arg2;
|
||||
|
|
@ -81,10 +81,10 @@ clicon_file_dirent_sort(const void* arg1, const void* arg2)
|
|||
|
||||
/*! Return sorted matching files from a directory
|
||||
* @param[in] dir Directory path
|
||||
* @param[out] ent Entries pointer, will be filled in with dir entries
|
||||
* @param[out] ent Entries pointer, will be filled in with dir entries. Free
|
||||
* after use
|
||||
* @param[in] regexp Regexp filename matching
|
||||
* @param[in] type File type matching, see stat(2)
|
||||
* @param[in] label Clicon Chunk label for memory handling, unchunk after use
|
||||
*
|
||||
* @retval n Number of matching files in directory
|
||||
* @retval -1 Error
|
||||
|
|
@ -92,34 +92,34 @@ clicon_file_dirent_sort(const void* arg1, const void* arg2)
|
|||
* @code
|
||||
* char *dir = "/root/fs";
|
||||
* struct dirent *dp;
|
||||
* if ((ndp = clicon_file_dirent(dir, &dp, "(.so)$", S_IFREG, __FUNCTION__)) < 0)
|
||||
* if ((ndp = clicon_file_dirent(dir, &dp, "(.so)$", S_IFREG)) < 0)
|
||||
* return -1;
|
||||
* for (i = 0; i < ndp; i++)
|
||||
* do something with dp[i].d_name;
|
||||
* unchunk_group(__FUNCTION__);
|
||||
* free(dp);
|
||||
* @endcode
|
||||
*/
|
||||
int
|
||||
clicon_file_dirent(const char *dir,
|
||||
struct dirent **ent,
|
||||
const char *regexp,
|
||||
mode_t type,
|
||||
const char *label)
|
||||
mode_t type)
|
||||
{
|
||||
DIR *dirp;
|
||||
int retval = -1;
|
||||
int res;
|
||||
int nent;
|
||||
char *filename;
|
||||
regex_t re;
|
||||
char errbuf[128];
|
||||
struct stat st;
|
||||
struct dirent dent;
|
||||
int retval = -1;
|
||||
DIR *dirp;
|
||||
int res;
|
||||
int nent;
|
||||
regex_t re;
|
||||
char errbuf[128];
|
||||
char filename[MAXPATHLEN];
|
||||
struct stat st;
|
||||
struct dirent dent;
|
||||
struct dirent *dresp;
|
||||
struct dirent *tmp;
|
||||
struct dirent *new = NULL;
|
||||
struct dirent *dvecp = NULL;
|
||||
|
||||
|
||||
*ent = NULL;
|
||||
nent = 0;
|
||||
|
||||
|
|
@ -137,7 +137,9 @@ clicon_file_dirent(const char *dir,
|
|||
goto quit;
|
||||
}
|
||||
|
||||
for (res = readdir_r (dirp, &dent, &dresp); dresp; res = readdir_r (dirp, &dent, &dresp)) {
|
||||
for (res = readdir_r (dirp, &dent, &dresp);
|
||||
dresp;
|
||||
res = readdir_r (dirp, &dent, &dresp)) {
|
||||
if (res != 0) {
|
||||
clicon_err(OE_UNIX, 0, "readdir: %s", strerror(errno));
|
||||
goto quit;
|
||||
|
|
@ -150,12 +152,8 @@ clicon_file_dirent(const char *dir,
|
|||
}
|
||||
/* File type matching */
|
||||
if (type) {
|
||||
if ((filename = chunk_sprintf(__FUNCTION__, "%s/%s", dir, dent.d_name)) == NULL) {
|
||||
clicon_err(OE_UNIX, 0, "chunk: %s", strerror(errno));
|
||||
goto quit;
|
||||
}
|
||||
snprintf(filename, MAXPATHLEN-1, "%s/%s", dir, dent.d_name);
|
||||
res = lstat(filename, &st);
|
||||
unchunk (filename);
|
||||
if (res != 0) {
|
||||
clicon_err(OE_UNIX, 0, "lstat: %s", strerror(errno));
|
||||
goto quit;
|
||||
|
|
@ -164,8 +162,8 @@ clicon_file_dirent(const char *dir,
|
|||
continue;
|
||||
}
|
||||
|
||||
if ((tmp = rechunk(new, (nent+1)*sizeof(*dvecp), label)) == NULL) {
|
||||
clicon_err(OE_UNIX, 0, "chunk: %s", strerror(errno));
|
||||
if ((tmp = realloc(new, (nent+1)*sizeof(*dvecp))) == NULL) {
|
||||
clicon_err(OE_UNIX, errno, "realloc");
|
||||
goto quit;
|
||||
}
|
||||
new = tmp;
|
||||
|
|
@ -183,30 +181,9 @@ quit:
|
|||
closedir(dirp);
|
||||
if (regexp)
|
||||
regfree(&re);
|
||||
unchunk_group(__FUNCTION__);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*
|
||||
* Use mkstep() to create an empty temporary file, accessible only by this user.
|
||||
* A chunk:ed file name is returned so that caller can overwrite file safely.
|
||||
*/
|
||||
char *
|
||||
clicon_tmpfile(const char *label)
|
||||
{
|
||||
int fd;
|
||||
char file[] = "/tmp/.tmpXXXXXX";
|
||||
|
||||
if ((fd = mkstemp(file)) < 0){
|
||||
clicon_err(OE_UNIX, errno, "mkstemp");
|
||||
return NULL;
|
||||
}
|
||||
close(fd);
|
||||
|
||||
return (char *)chunkdup(file, strlen(file)+1, label);
|
||||
}
|
||||
|
||||
/*! Make a copy of file src
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue