| 1 |
/* |
| 2 |
* ndbm-makedb.c - create an empty ndbm database |
| 3 |
*/ |
| 4 |
|
| 5 |
/* There are some variations in ndbm implementations that use different |
| 6 |
suffixes for database files. I think the original ndbm inherited |
| 7 |
*.dir / *.pag from the original dbm, while BSD-traits uses *.db (they |
| 8 |
might be a wrapper of old berkeley db, though I'm not sure.) |
| 9 |
This small program is run during build stage and creates an empty |
| 10 |
ndbm database with the name given to the command line. Then the build |
| 11 |
process finds out what files are actually created. |
| 12 |
*/ |
| 13 |
|
| 14 |
#include <stdio.h> |
| 15 |
#include <unistd.h> |
| 16 |
#include <stdlib.h> |
| 17 |
#include <errno.h> |
| 18 |
#include <string.h> |
| 19 |
#include <fcntl.h> |
| 20 |
#include "dbmconf.h" |
| 21 |
|
| 22 |
#if HAVE_NDBM_H |
| 23 |
#include <ndbm.h> |
| 24 |
#elif HAVE_GDBM_SLASH_NDBM_H |
| 25 |
#include <gdbm/ndbm.h> |
| 26 |
#elif HAVE_GDBM_MINUS_NDBM_H |
| 27 |
#include <gdbm-ndbm.h> |
| 28 |
#endif |
| 29 |
|
| 30 |
int main(int argc, char **argv) |
| 31 |
{ |
| 32 |
DBM *dbf; |
| 33 |
|
| 34 |
if (argc != 2) { |
| 35 |
printf("Usage: ndbm-makedb <dbname>\n"); |
| 36 |
exit(1); |
| 37 |
} |
| 38 |
|
| 39 |
if ((dbf = dbm_open(argv[1], O_CREAT|O_RDWR, 0777)) == NULL) { |
| 40 |
printf("dbm_open failed for %s: %s\n", argv[1], strerror(errno)); |
| 41 |
exit(1); |
| 42 |
} |
| 43 |
|
| 44 |
dbm_close(dbf); |
| 45 |
return 0; |
| 46 |
} |