comparison src/database.c @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents 56c54cf7c5b6
children 1040fe1366ac
comparison
equal deleted inserted replaced
69:804d1389bcd6 70:131b0175ea99
69 struct lcrecord_header header; 69 struct lcrecord_header header;
70 Lisp_Object fname; 70 Lisp_Object fname;
71 XEMACS_DB_TYPE type; 71 XEMACS_DB_TYPE type;
72 int mode; 72 int mode;
73 int ackcess; 73 int ackcess;
74 int dberrno; 74 int errno;
75 void *db_handle; 75 void *db_handle;
76 DB_FUNCS *funcs; 76 DB_FUNCS *funcs;
77 }; 77 };
78 78
79 #define XDATABASE(x) XRECORD (x, database, struct database_struct) 79 #define XDATABASE(x) XRECORD (x, database, struct database_struct)
98 98
99 dbase->fname = Qnil; 99 dbase->fname = Qnil;
100 dbase->db_handle = NULL; 100 dbase->db_handle = NULL;
101 dbase->ackcess = 0; 101 dbase->ackcess = 0;
102 dbase->mode = 0; 102 dbase->mode = 0;
103 dbase->dberrno = 0; 103 dbase->errno = 0;
104 dbase->type = DB_UNKNOWN; 104 dbase->type = DB_UNKNOWN;
105 return (dbase); 105 return (dbase);
106 } 106 }
107 107
108 static Lisp_Object 108 static Lisp_Object
320 } 320 }
321 321
322 static Lisp_Object 322 static Lisp_Object
323 dbm_lasterr (struct database_struct *dbp) 323 dbm_lasterr (struct database_struct *dbp)
324 { 324 {
325 char *temp = strerror (dbp->dberrno); 325 char *temp = strerror (dbp->errno);
326 return (make_string ((unsigned char *) temp, strlen (temp))); 326 return (make_string ((unsigned char *) temp, strlen (temp)));
327 } 327 }
328 328
329 static void 329 static void
330 dbm_closeit (struct database_struct *db) 330 dbm_closeit (struct database_struct *db)
403 } 403 }
404 404
405 static Lisp_Object 405 static Lisp_Object
406 berkdb_lasterr (struct database_struct *dbp) 406 berkdb_lasterr (struct database_struct *dbp)
407 { 407 {
408 char *temp = strerror (dbp->dberrno); 408 char *temp = strerror (dbp->errno);
409 return (make_string ((unsigned char *) temp, strlen (temp))); 409 return (make_string ((unsigned char *) temp, strlen (temp)));
410 } 410 }
411 411
412 static Lisp_Object 412 static Lisp_Object
413 berkdb_get (struct database_struct *db, Lisp_Object key) 413 berkdb_get (struct database_struct *db, Lisp_Object key)
422 status = dbp->get (dbp, &keydatum, &valdatum, 0); 422 status = dbp->get (dbp, &keydatum, &valdatum, 0);
423 423
424 if (!status) 424 if (!status)
425 return (make_string (valdatum.data, valdatum.size)); 425 return (make_string (valdatum.data, valdatum.size));
426 426
427 db->dberrno = (status == 1) ? -1 : errno; 427 db->errno = (status == 1) ? -1 : errno;
428 return (Qnil); 428 return (Qnil);
429 } 429 }
430 430
431 static int 431 static int
432 berkdb_put (struct database_struct *db, 432 berkdb_put (struct database_struct *db,
442 keydatum.size = XSTRING_LENGTH (key); 442 keydatum.size = XSTRING_LENGTH (key);
443 valdatum.data = XSTRING_DATA (val); 443 valdatum.data = XSTRING_DATA (val);
444 valdatum.size = XSTRING_LENGTH (val); 444 valdatum.size = XSTRING_LENGTH (val);
445 status = dbp->put (dbp, &keydatum, &valdatum, NILP (replace) 445 status = dbp->put (dbp, &keydatum, &valdatum, NILP (replace)
446 ? R_NOOVERWRITE : 0); 446 ? R_NOOVERWRITE : 0);
447 db->dberrno = (status == 1) ? -1 : errno; 447 db->errno = (status == 1) ? -1 : errno;
448 return status; 448 return status;
449 } 449 }
450 450
451 static int 451 static int
452 berkdb_remove (struct database_struct *db, Lisp_Object key) 452 berkdb_remove (struct database_struct *db, Lisp_Object key)
460 460
461 status = dbp->del (dbp, &keydatum, 0); 461 status = dbp->del (dbp, &keydatum, 0);
462 if (!status) 462 if (!status)
463 return 0; 463 return 0;
464 464
465 db->dberrno = (status == 1) ? -1 : errno; 465 db->errno = (status == 1) ? -1 : errno;
466 return 1; 466 return 1;
467 } 467 }
468 468
469 static void 469 static void
470 berkdb_map (struct database_struct *db, Lisp_Object func) 470 berkdb_map (struct database_struct *db, Lisp_Object func)
541 int accessmask = 0; 541 int accessmask = 0;
542 XEMACS_DB_TYPE the_type; 542 XEMACS_DB_TYPE the_type;
543 DB_FUNCS *funcblock; 543 DB_FUNCS *funcblock;
544 struct database_struct *dbase = NULL; 544 struct database_struct *dbase = NULL;
545 void *db = NULL; 545 void *db = NULL;
546 struct gcpro gcpro1; 546
547 547 CHECK_STRING (file);
548 GCPRO1 (file);
549 file = Fexpand_file_name (file, Qnil);
550 548
551 if (NILP (ackcess)) 549 if (NILP (ackcess))
552 { 550 {
553 accessmask = O_RDWR | O_CREAT; 551 accessmask = O_RDWR | O_CREAT;
554 } 552 }
623 dbase->ackcess = accessmask; 621 dbase->ackcess = accessmask;
624 dbase->db_handle = db; 622 dbase->db_handle = db;
625 dbase->funcs = funcblock; 623 dbase->funcs = funcblock;
626 XSETDATABASE (retval, dbase); 624 XSETDATABASE (retval, dbase);
627 625
628 UNGCPRO;
629
630 return (retval); 626 return (retval);
631 } 627 }
632 628
633 DEFUN ("put-database", Fputdatabase, 3, 4, 0, /* 629 DEFUN ("put-database", Fputdatabase, 3, 4, 0, /*
634 Store KEY and VAL in DATABASE. If optinal fourth arg REPLACE is 630 Store KEY and VAL in DATABASE. If optinal fourth arg REPLACE is