Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
2c67a284
Commit
2c67a284
authored
Jun 18, 2009
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First step to ccanizing TDB.
parent
7104b7bc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
99 additions
and
1 deletion
+99
-1
ccan/tdb/_info
ccan/tdb/_info
+76
-0
ccan/tdb/io.c
ccan/tdb/io.c
+3
-1
ccan/tdb/tdb.h
ccan/tdb/tdb.h
+6
-0
ccan/tdb/tdb_private.h
ccan/tdb/tdb_private.h
+14
-0
No files found.
ccan/tdb/_info
0 → 100644
View file @
2c67a284
#include <string.h>
/**
* tdb - The trivial (transactional) database
*
* The tdb module provides an efficient keyword data mapping (usually
* within a file). It supports transactions, so the contents of the
* database is reliable even across crashes.
*
* Example:
* #include <ccan/tdb/tdb.h>
* #include <ccan/str/str.h>
* #include <err.h>
* #include <stdio.h>
*
* static void usage(void)
* {
* errx(1, "Usage: %s fetch <dbfile> <key>\n"
* "OR %s store <dbfile> <key> <data>");
* }
*
* int main(int argc, char *argv[])
* {
* struct tdb_context *tdb;
* TDB_DATA key, value;
*
* if (argc < 4)
* usage();
*
* tdb = tdb_open(argv[2], 1024, TDB_DEFAULT, O_CREAT|O_RDWR,
* 0600);
* if (!tdb)
* err(1, "Opening %s", argv[2]);
*
* key.dptr = (void *)argv[3];
* key.dsize = strlen(argv[3]);
*
* if (streq(argv[1], "fetch")) {
* if (argc != 4)
* usage();
* value = tdb_fetch(tdb, key);
* if (!value.dptr)
* errx(1, "fetch %s: %s",
* argv[3], tdb_errorstr(tdb));
* printf("%.*s\n", value.dsize, (char *)value.dptr);
* free(value.dptr);
* } else if (streq(argv[1], "store")) {
* if (argc != 5)
* usage();
* value.dptr = (void *)argv[4];
* value.dsize = strlen(argv[4]);
* if (tdb_store(tdb, key, value, 0) != 0)
* errx(1, "store %s: %s",
* argv[3], tdb_errorstr(tdb));
* } else
* usage();
*
* return 0;
* }
*
* Maintainer: Rusty Russell <rusty@rustcorp.com.au>
*
* Author: Andrew Tridgell, Jeremy Allison, Rusty Russell
*
* Licence: LGPLv3 (or later)
*/
int main(int argc, char *argv[])
{
if (argc != 2)
return 1;
if (strcmp(argv[1], "depends") == 0)
return 0;
return 1;
}
ccan/tdb/io.c
View file @
2c67a284
...
...
@@ -25,8 +25,10 @@
License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include "tdb_private.h"
#ifndef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
/* check for an out of bounds access - if it is out of bounds then
see if the database has been expanded by someone else and expand
...
...
ccan/tdb/tdb.h
View file @
2c67a284
...
...
@@ -30,6 +30,12 @@
extern
"C"
{
#endif
#ifndef _SAMBA_BUILD_
/* For mode_t */
#include <sys/types.h>
/* For sig_atomic_t. */
#include <signal.h>
#endif
/* flags to tdb_store() */
#define TDB_REPLACE 1
/* Unused */
...
...
ccan/tdb/tdb_private.h
View file @
2c67a284
...
...
@@ -23,12 +23,26 @@
License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef _SAMBA_BUILD_
#include "replace.h"
#include "system/filesys.h"
#include "system/time.h"
#include "system/shmem.h"
#include "system/select.h"
#include "system/wait.h"
#else
#define _XOPEN_SOURCE 500
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#endif
#include "tdb.h"
#ifndef HAVE_GETPAGESIZE
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment