3 * add.c - add a new entry to the database
12 #include "csc.quota.h"
14 void add(int argc, char ** argv) {
16 char db_file_name[PATH_MAX];
17 struct quota_entry entry;
22 fputs("Usage: add userid quota\n", stderr);
26 key.dptr = strdup(argv[0]);
27 key.dsize = strlen(key.dptr) + 1;
28 value.dptr = (char *) &entry;
29 value.dsize = sizeof(struct quota_entry);
31 entry.megabytes = atoi(argv[1]);
32 entry.flags = QUOTAF_NORMAL;
34 sprintf(db_file_name, "%s/" QUOTA_DB,
35 QUOTA_DIR, current_term());
37 dbf = gdbm_open(db_file_name, BUFSIZ, GDBM_WRCREAT, 0600, NULL);
40 fprintf(stderr, "error opening the quota database: %s\n",
41 gdbm_strerror(gdbm_errno));
45 ret = gdbm_store(dbf, key, value, GDBM_INSERT);
46 /* we immediately close the gdbm since we're done with it */
49 fprintf(stderr, "%s already in the database\n",
51 } else if (ret == -1) {
52 fputs("add error\n", stderr);