home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume40 / ddb / patch01 / Patch01
Encoding:
Text File  |  1993-11-26  |  19.3 KB  |  974 lines

  1. *** ../ddb.old/Makefile    Thu Nov 18 00:08:26 1993
  2. --- Makefile    Wed Nov 17 23:53:07 1993
  3. ***************
  4. *** 1,5 ****
  5.   OPT=-O
  6. ! CFLAGS=$(OPT) -I.
  7.   CDBS=hash.c list.c queue.c stack.c binary.c bit.c
  8.   CSRCS=new.c $(CDBS)
  9.   COBJS=$(CSRCS:.c=.o)
  10. --- 1,5 ----
  11.   OPT=-O
  12. ! CFLAGS=$(OPT)
  13.   CDBS=hash.c list.c queue.c stack.c binary.c bit.c
  14.   CSRCS=new.c $(CDBS)
  15.   COBJS=$(CSRCS:.c=.o)
  16. *** ../ddb.old/binary.c    Thu Nov 18 00:08:27 1993
  17. --- binary.c    Thu Nov 18 00:01:03 1993
  18. ***************
  19. *** 21,27 ****
  20.   #include <stdlib.h>
  21.   #include <string.h>
  22.   #include <sys/types.h>
  23. ! #include <ddb.h>
  24.   
  25.   #define MIN(a,b)    ((a) < (b) ? (a) : (b))
  26.   
  27. --- 21,28 ----
  28.   #include <stdlib.h>
  29.   #include <string.h>
  30.   #include <sys/types.h>
  31. ! #include <errno.h>
  32. ! #include "ddb.h"
  33.   
  34.   #define MIN(a,b)    ((a) < (b) ? (a) : (b))
  35.   
  36. ***************
  37. *** 48,53 ****
  38. --- 49,56 ----
  39.   
  40.   extern void    *ddb_new(const DATUM *, const DATUM *, size_t);
  41.   
  42. + extern int    errno;
  43.   int
  44.   ddb_memcmp(const DATUM *dp1, const DATUM *dp2)
  45.   {
  46. ***************
  47. *** 65,71 ****
  48.   static int
  49.   validbd(int bd)
  50.   {
  51. !     return binary && bd < maxbinaries && binary[bd].used;
  52.   }
  53.   
  54.   static int
  55. --- 68,78 ----
  56.   static int
  57.   validbd(int bd)
  58.   {
  59. !     int    valid = binary && bd < maxbinaries && binary[bd].used;
  60. !     if (!valid)
  61. !         errno = EBADF;
  62. !     return valid;
  63.   }
  64.   
  65.   static int
  66. ***************
  67. *** 77,82 ****
  68. --- 84,90 ----
  69.       case DDB_DUPLICATE:
  70.           return 1;
  71.       default:
  72. +         errno = EINVAL;
  73.           return 0;
  74.       }
  75.   }
  76. ***************
  77. *** 167,172 ****
  78. --- 175,181 ----
  79.               bp->left = bp_new;
  80.           } else /* DDB_INSERT */ {
  81.               bfree(bp_new);
  82. +             errno = EEXIST;
  83.               return -1;
  84.           }
  85.       } else
  86. ***************
  87. *** 191,198 ****
  88.       if (bp = find(bd, key, cmp, NULL))
  89.   #endif
  90.           return &bp->data;
  91. !     else
  92.           return NULL;
  93.   }
  94.   
  95.   int
  96. --- 200,209 ----
  97.       if (bp = find(bd, key, cmp, NULL))
  98.   #endif
  99.           return &bp->data;
  100. !     else {
  101. !         errno = ENOENT;
  102.           return NULL;
  103. +     }
  104.   }
  105.   
  106.   int
  107. ***************
  108. *** 206,212 ****
  109.   #endif
  110.   
  111.       if (!validbd(bd))
  112. !         return NULL;
  113.       if (!cmp)
  114.           cmp = ddb_memcmp;
  115.   
  116. --- 217,223 ----
  117.   #endif
  118.   
  119.       if (!validbd(bd))
  120. !         return -1;
  121.       if (!cmp)
  122.           cmp = ddb_memcmp;
  123.   
  124. ***************
  125. *** 254,261 ****
  126.               free(bp);
  127.           }
  128.           return 0;
  129. !     } else
  130.           return -1;
  131.   }
  132.   
  133.   static void
  134. --- 265,274 ----
  135.               free(bp);
  136.           }
  137.           return 0;
  138. !     } else {
  139. !         errno = ENOENT;
  140.           return -1;
  141. +     }
  142.   }
  143.   
  144.   static void
  145. ***************
  146. *** 385,422 ****
  147.   {
  148.       if (validbd(bd))
  149.           recurse(binary[bd].root, f, order);
  150. - }
  151. - DATUM *
  152. - ddb_blargestkey(int bd)
  153. - {
  154. -     BELEM    *bp;
  155. -     if (!validbd(bd))
  156. -         return NULL;
  157. -     if (bp = binary[bd].root) {
  158. -         while (bp->right)
  159. -             bp = bp->right;
  160. -         return &bp->key;
  161. -     } else
  162. -         return NULL;
  163. - }
  164. - DATUM *
  165. - ddb_bsmallestkey(int bd)
  166. - {
  167. -     BELEM    *bp;
  168. -     if (!validbd(bd))
  169. -         return NULL;
  170. -     if (bp = binary[bd].root) {
  171. -         while (bp->left)
  172. -             bp = bp->left;
  173. -         return &bp->key;
  174. -     } else
  175. -         return NULL;
  176.   }
  177.   
  178.   #ifdef DEBUG
  179. --- 398,403 ----
  180. *** ../ddb.old/bit.c    Thu Nov 18 00:08:27 1993
  181. --- bit.c    Thu Nov 18 00:07:35 1993
  182. ***************
  183. *** 20,26 ****
  184.   #include <string.h>
  185.   #include <limits.h>
  186.   #include <sys/types.h>
  187. ! #include <ddb.h>
  188.   
  189.   #define MIN(a,b)    ((a) < (b) ? (a) : (b))
  190.   
  191. --- 20,27 ----
  192.   #include <string.h>
  193.   #include <limits.h>
  194.   #include <sys/types.h>
  195. ! #include <errno.h>
  196. ! #include "ddb.h"
  197.   
  198.   #define MIN(a,b)    ((a) < (b) ? (a) : (b))
  199.   
  200. ***************
  201. *** 42,54 ****
  202.   static BIT    *vector = NULL;
  203.   static int    maxvectors = 0;
  204.   
  205. ! #define CHECK_MAXBIT    1
  206.   
  207.   static int
  208. ! validbd(int bd, unsigned long bit, int check)
  209.   {
  210. !     return vector && bd < maxvectors && vector[bd].used
  211. !       && (check != CHECK_MAXBIT || bit <= vector[bd].maxbit);
  212.   }
  213.   
  214.   static int
  215. --- 43,58 ----
  216.   static BIT    *vector = NULL;
  217.   static int    maxvectors = 0;
  218.   
  219. ! extern int    errno;
  220.   
  221.   static int
  222. ! validbd(int bd)
  223.   {
  224. !     int    valid = vector && bd < maxvectors && vector[bd].used;
  225. !     if (!valid)
  226. !         errno = EBADF;
  227. !     return valid;
  228.   }
  229.   
  230.   static int
  231. ***************
  232. *** 60,65 ****
  233. --- 64,70 ----
  234.       case DDB_DUPLICATE:
  235.           return 1;
  236.       default:
  237. +         errno = EINVAL;
  238.           return 0;
  239.       }
  240.   }
  241. ***************
  242. *** 71,78 ****
  243.       unsigned long    nints1, nints2;
  244.       unsigned long    bit;
  245.   
  246. !     if (maxbit > (unsigned long)LONG_MAX)
  247.           return -1;
  248.   
  249.       nints1 = vector[bd].maxbit / WORD_BIT + 1;
  250.       nints2 = maxbit / WORD_BIT + 1;
  251. --- 76,85 ----
  252.       unsigned long    nints1, nints2;
  253.       unsigned long    bit;
  254.   
  255. !     if (maxbit > (unsigned long)LONG_MAX) {
  256. !         errno = EDOM;
  257.           return -1;
  258. +     }
  259.   
  260.       nints1 = vector[bd].maxbit / WORD_BIT + 1;
  261.       nints2 = maxbit / WORD_BIT + 1;
  262. ***************
  263. *** 94,100 ****
  264.   int
  265.   ddb_bitwrite(int bd, unsigned long bit, int mode)
  266.   {
  267. !     if (!validbd(bd, bit, !CHECK_MAXBIT) || !validmode(mode))
  268.           return -1;
  269.       if (bit > vector[bd].maxbit && enlarge(bd, bit) == -1)
  270.           return -1;
  271. --- 101,107 ----
  272.   int
  273.   ddb_bitwrite(int bd, unsigned long bit, int mode)
  274.   {
  275. !     if (!validbd(bd) || !validmode(mode))
  276.           return -1;
  277.       if (bit > vector[bd].maxbit && enlarge(bd, bit) == -1)
  278.           return -1;
  279. ***************
  280. *** 101,108 ****
  281.   
  282.       if (!isset(vector[bd].bits, bit))
  283.           setbit(vector[bd].bits, bit);
  284. !     else if (mode & DDB_INSERT)
  285.           return -1;
  286.   
  287.       return 0;
  288.   }
  289. --- 108,117 ----
  290.   
  291.       if (!isset(vector[bd].bits, bit))
  292.           setbit(vector[bd].bits, bit);
  293. !     else if (mode & DDB_INSERT) {
  294. !         errno = EEXIST;
  295.           return -1;
  296. +     }
  297.   
  298.       return 0;
  299.   }
  300. ***************
  301. *** 110,140 ****
  302.   int
  303.   ddb_bitread(int bd, unsigned long bit)
  304.   {
  305. !     if (!validbd(bd, bit, !CHECK_MAXBIT))
  306.           return -1;
  307.   
  308. !     if (bit > vector[bd].maxbit)
  309.           return 0;
  310. -     return isset(vector[bd].bits, bit) != 0;
  311.   }
  312.   
  313.   int
  314.   ddb_bitdelete(int bd, unsigned long bit)
  315.   {
  316. !     if (!validbd(bd, bit, CHECK_MAXBIT))
  317.           return -1;
  318. !     if (isset(vector[bd].bits, bit)) {
  319.           clrbit(vector[bd].bits, bit);
  320.           return 0;
  321. !     } else
  322. !         return -1;
  323.   }
  324.   
  325.   int
  326.   ddb_bitclose(int bd)
  327.   {
  328. !     if (!validbd(bd, 0, !CHECK_MAXBIT))
  329.           return -1;
  330.   
  331.       vector[bd].used = 0;
  332. --- 119,152 ----
  333.   int
  334.   ddb_bitread(int bd, unsigned long bit)
  335.   {
  336. !     if (!validbd(bd))
  337.           return -1;
  338.   
  339. !     if (bit > vector[bd].maxbit || !isset(vector[bd].bits, bit)) {
  340. !         errno = ENOENT;
  341. !         return -1;
  342. !     } else
  343.           return 0;
  344.   }
  345.   
  346.   int
  347.   ddb_bitdelete(int bd, unsigned long bit)
  348.   {
  349. !     if (!validbd(bd))
  350.           return -1;
  351. !     if (bit > vector[bd].maxbit || !isset(vector[bd].bits, bit)) {
  352. !         errno = ENOENT;
  353. !         return -1;
  354. !     } else {
  355.           clrbit(vector[bd].bits, bit);
  356.           return 0;
  357. !     }
  358.   }
  359.   
  360.   int
  361.   ddb_bitclose(int bd)
  362.   {
  363. !     if (!validbd(bd))
  364.           return -1;
  365.   
  366.       vector[bd].used = 0;
  367. ***************
  368. *** 147,153 ****
  369.   int
  370.   ddb_bitset(int bd, int on)
  371.   {
  372. !     if (!validbd(bd, 0, !CHECK_MAXBIT))
  373.           return -1;
  374.   
  375.       (void)memset(vector[bd].bits, on ? ~0 : '\0',
  376. --- 159,165 ----
  377.   int
  378.   ddb_bitset(int bd, int on)
  379.   {
  380. !     if (!validbd(bd))
  381.           return -1;
  382.   
  383.       (void)memset(vector[bd].bits, on ? ~0 : '\0',
  384. ***************
  385. *** 164,171 ****
  386.       int        j;
  387.       BIT        *vtmp;
  388.   
  389. !     if (maxbit > (unsigned long)LONG_MAX)
  390.           return -1;
  391.   
  392.       for (i = 0; i < maxvectors && vector[i].used; i++)
  393.           ;
  394. --- 176,185 ----
  395.       int        j;
  396.       BIT        *vtmp;
  397.   
  398. !     if (maxbit > (unsigned long)LONG_MAX) {
  399. !         errno = EDOM;
  400.           return -1;
  401. +     }
  402.   
  403.       for (i = 0; i < maxvectors && vector[i].used; i++)
  404.           ;
  405. ***************
  406. *** 243,250 ****
  407.   {
  408.       unsigned long    index;
  409.   
  410. !     if (!validbd(bd, 0, !CHECK_MAXBIT) || (index = findword(vector[bd].bits,
  411. !       0, vector[bd].maxbit / WORD_BIT, 0)) == -1)
  412.           return -1;
  413.       else
  414.           return vector[bd].lastbit = findlowset(vector[bd].bits[index],
  415. --- 257,264 ----
  416.   {
  417.       unsigned long    index;
  418.   
  419. !     if (!validbd(bd) || (index = findword(vector[bd].bits, 0,
  420. !       vector[bd].maxbit / WORD_BIT, 0)) == -1)
  421.           return -1;
  422.       else
  423.           return vector[bd].lastbit = findlowset(vector[bd].bits[index],
  424. ***************
  425. *** 259,265 ****
  426.       unsigned int    mask;
  427.       unsigned long    index;
  428.   
  429. !     if (!validbd(bd, 0, !CHECK_MAXBIT))
  430.           return -1;
  431.       mask = wordmask(vector[bd].lastbit % WORD_BIT);
  432.       if ((index = findword(vector[bd].bits, vector[bd].lastbit / WORD_BIT,
  433. --- 273,279 ----
  434.       unsigned int    mask;
  435.       unsigned long    index;
  436.   
  437. !     if (!validbd(bd))
  438.           return -1;
  439.       mask = wordmask(vector[bd].lastbit % WORD_BIT);
  440.       if ((index = findword(vector[bd].bits, vector[bd].lastbit / WORD_BIT,
  441. *** ../ddb.old/ddb.3    Thu Nov 18 00:08:27 1993
  442. --- ddb.3    Wed Nov 17 23:53:08 1993
  443. ***************
  444. *** 126,145 ****
  445.   .BR write(\|)
  446.   functions use to add to the databases.
  447.   Must include only one of the following values:
  448. ! .IP DDB_INSERT
  449.   Insert the pair only if the key is not currently in the database.
  450. ! .IP DDB_REPLACE
  451.   Add the pair to the database.
  452.   If the key is already in the database, delete that entry.
  453. ! .IP DDB_DUPLICATE
  454.   Add the pair to the database.
  455.   If the key is already in the database, do not delete that entry.
  456.   For the
  457.   .BR ddb_lwrite(\|)
  458. ! function, the value
  459. ! .IR DDB_TAIL
  460. ! can be inclusively OR'ed into
  461.   .IR flag
  462.   to specify writing at the tail of the list.
  463.   .IP \fIf\fP
  464. --- 126,145 ----
  465.   .BR write(\|)
  466.   functions use to add to the databases.
  467.   Must include only one of the following values:
  468. ! .RS
  469. ! .IP DDB_INSERT 14
  470.   Insert the pair only if the key is not currently in the database.
  471. ! .IP DDB_REPLACE 14
  472.   Add the pair to the database.
  473.   If the key is already in the database, delete that entry.
  474. ! .IP DDB_DUPLICATE 14
  475.   Add the pair to the database.
  476.   If the key is already in the database, do not delete that entry.
  477. ! .RE
  478. ! .IP
  479.   For the
  480.   .BR ddb_lwrite(\|)
  481. ! function, the value DDB_TAIL can be inclusively OR'ed into
  482.   .IR flag
  483.   to specify writing at the tail of the list.
  484.   .IP \fIf\fP
  485. ***************
  486. *** 229,240 ****
  487.   functions.
  488.   .LP
  489.   Functions returning type pointer\-to\-DATUM return NULL on failure.
  490. ! .SH NOTES
  491. ! All of the
  492.   .BR read(\|)
  493. ! functions except
  494. ! .BR ddb_bitread(\|)
  495. ! return pointers to memory which should be freed when unneeded.
  496.   .LP
  497.   Altering a database and then calling a
  498.   .BR next(\|)
  499. --- 229,329 ----
  500.   functions.
  501.   .LP
  502.   Functions returning type pointer\-to\-DATUM return NULL on failure.
  503. ! .SH ERRORS
  504. ! .LP
  505. ! If an
  506. ! .BR open(\|)
  507. ! function fails, errno will be set to one of the following values:
  508. ! .IP [ENOMEM] 9
  509. ! Sufficient memory could not be allocated.
  510. ! .IP [EDOM] 9
  511. ! .BR ddb_bitopen(\|)
  512. ! has been called with
  513. ! .IR maxbit
  514. ! larger than LONG_MAX.
  515. ! .LP
  516. ! If a
  517. ! .BR close(\|)
  518. ! function fails, errno will be set to
  519. ! .IP [EBADF] 9
  520. ! The
  521. ! .IR dbd
  522. ! argument is not a valid database descriptor.
  523. ! .LP
  524. ! If a
  525.   .BR read(\|)
  526. ! function fails, errno may be set to one of the following values:
  527. ! .IP [EBADF] 9
  528. ! The
  529. ! .IR dbd
  530. ! argument is not a valid database descriptor.
  531. ! .IP [ENOENT] 9
  532. ! The
  533. ! .IR key
  534. ! argument does not specify an entry in the database.
  535. ! .LP
  536. ! Errno is not changed when the relevant database is empty
  537. ! and
  538. ! .BR ddb_lread(\|)
  539. ! is called with
  540. ! .IR key
  541. ! NULL or
  542. ! .BR ddb_qread(\|)
  543. ! or
  544. ! .BR ddb_sread(\|)
  545. ! are called.
  546. ! .LP
  547. ! If a
  548. ! .BR write(\|)
  549. ! function fails, errno will be set to one of the following values:
  550. ! .IP [EBADF] 9
  551. ! The
  552. ! .IR dbd
  553. ! argument is not a valid database descriptor.
  554. ! .IP [EINVAL] 9
  555. ! The
  556. ! .IR flag
  557. ! argument is not valid.
  558. ! .IP [EEXIST] 9
  559. ! The entry indicated by
  560. ! .IR key
  561. ! is already present in the database and DDB_INSERT was specified.
  562. ! .IP [ENOMEM] 9
  563. ! Sufficient memory could not be allocated.
  564. ! .IP [EDOM] 9
  565. ! .BR ddb_bitwrite(\|)
  566. ! has been called with
  567. ! .IR bit
  568. ! larger than LONG_MAX.
  569. ! .LP
  570. ! If a
  571. ! .BR delete(\|)
  572. ! function fails, errno will be set to one of the following values:
  573. ! .IP [EBADF] 9
  574. ! The
  575. ! .IR dbd
  576. ! argument is not a valid database descriptor.
  577. ! .IP [ENOENT] 9
  578. ! The
  579. ! .IR key
  580. ! argument does not specify an entry in the database.
  581. ! .LP
  582. ! When the
  583. ! .BR first(\|)
  584. ! and
  585. ! .BR next(\|)
  586. ! functions fail because the all of the entries in a database have
  587. ! been returned, errno is not changed.
  588. ! However, they can fail with errno set to
  589. ! .IP [EBADF] 9
  590. ! The
  591. ! .IR dbd
  592. ! argument is not a valid database descriptor.
  593. ! .SH NOTES
  594. ! The
  595. ! .BR ddb_qread(\|)
  596. ! function
  597. ! returns a pointer to memory which should be freed when unneeded.
  598.   .LP
  599.   Altering a database and then calling a
  600.   .BR next(\|)
  601. *** ../ddb.old/ddb.h    Thu Nov 18 00:08:27 1993
  602. --- ddb.h    Wed Nov 17 23:53:08 1993
  603. ***************
  604. *** 46,53 ****
  605.   extern DATUM    *ddb_bfirst(int);
  606.   extern DATUM    *ddb_bnext(int);
  607.   extern void    ddb_bfunc(int, void (*)(const DATUM *, const DATUM *), int);
  608. - extern DATUM    *ddb_blargestkey(int);
  609. - extern DATUM    *ddb_bsmallestkey(int);
  610.   #ifdef DEBUG
  611.   extern void    ddb_bdump(int, void (*)(const DATUM *), void (*)(const DATUM *),
  612.             int);
  613. --- 46,51 ----
  614. ***************
  615. *** 61,68 ****
  616.   extern int    ddb_bitread(int, unsigned long);
  617.   extern long    ddb_bitfirst(int);
  618.   extern long    ddb_bitnext(int);
  619. - extern long    ddb_bitlargestkey(int);
  620. - extern long    ddb_bitsmallestkey(int);
  621.   extern int    ddb_bitset(int, int);
  622.   #ifdef DEBUG
  623.   extern void    ddb_bitdump(int);
  624. --- 59,64 ----
  625. *** ../ddb.old/hash.c    Thu Nov 18 00:08:28 1993
  626. --- hash.c    Wed Nov 17 23:53:08 1993
  627. ***************
  628. *** 19,25 ****
  629.   #include <stdlib.h>
  630.   #include <string.h>
  631.   #include <sys/types.h>
  632. ! #include <ddb.h>
  633.   
  634.   typedef struct hashent {
  635.       DATUM        key;
  636. --- 19,26 ----
  637.   #include <stdlib.h>
  638.   #include <string.h>
  639.   #include <sys/types.h>
  640. ! #include <errno.h>
  641. ! #include "ddb.h"
  642.   
  643.   typedef struct hashent {
  644.       DATUM        key;
  645. ***************
  646. *** 46,51 ****
  647. --- 47,54 ----
  648.   extern void    *ddb_new(const DATUM *, const DATUM *, size_t);
  649.   extern int    ddb_memcmp(const DATUM *, const DATUM *);
  650.   
  651. + extern int    errno;
  652.   static size_t
  653.   def_hash(const char *key, size_t keysize, size_t nbuckets)
  654.   {
  655. ***************
  656. *** 60,66 ****
  657.   static int
  658.   validhd(int hd)
  659.   {
  660. !     return hashtable && hd < maxtables && hashtable[hd].used;
  661.   }
  662.   
  663.   static DATUM *
  664. --- 63,73 ----
  665.   static int
  666.   validhd(int hd)
  667.   {
  668. !     int    valid =  hashtable && hd < maxtables && hashtable[hd].used;
  669. !     if (!valid)
  670. !         errno = EBADF;
  671. !     return valid;
  672.   }
  673.   
  674.   static DATUM *
  675. ***************
  676. *** 88,100 ****
  677.           }
  678.   
  679.       if (action == H_READ)
  680. !         return ptr ? &ptr->data : NULL;
  681.   
  682. !     if (ptr && action == DDB_INSERT)
  683.           return NULL;
  684.   
  685. !     if (!ptr && action == H_DELETE)
  686.           return NULL;
  687.   
  688.       if (ptr && action != DDB_DUPLICATE) {    /* H_DELETE || DDB_REPLACE */
  689.           free(ptr->data.addr);
  690. --- 95,116 ----
  691.           }
  692.   
  693.       if (action == H_READ)
  694. !         if (ptr)
  695. !             return &ptr->data;
  696. !         else {
  697. !             errno = ENOENT;
  698. !             return NULL;
  699. !         }
  700.   
  701. !     if (ptr && action == DDB_INSERT) {
  702. !         errno = EEXIST;
  703.           return NULL;
  704. +     }
  705.   
  706. !     if (!ptr && action == H_DELETE) {
  707. !         errno = ENOENT;
  708.           return NULL;
  709. +     }
  710.   
  711.       if (ptr && action != DDB_DUPLICATE) {    /* H_DELETE || DDB_REPLACE */
  712.           free(ptr->data.addr);
  713. ***************
  714. *** 140,148 ****
  715.   ddb_hwrite(int hd, const DATUM *key, const DATUM *data, ddb_cmp_t cmp, int mode,
  716.     ddb_hash_t hash)
  717.   {
  718. !     if (mode != DDB_INSERT && mode != DDB_REPLACE && mode != DDB_DUPLICATE)
  719.           return -1;
  720. !     else if (hashop(hd, mode, key, data, cmp, hash))
  721.           return 0;
  722.       else
  723.           return -1;
  724. --- 156,166 ----
  725.   ddb_hwrite(int hd, const DATUM *key, const DATUM *data, ddb_cmp_t cmp, int mode,
  726.     ddb_hash_t hash)
  727.   {
  728. !     if (mode != DDB_INSERT && mode != DDB_REPLACE
  729. !       && mode != DDB_DUPLICATE) {
  730. !         errno = EINVAL;
  731.           return -1;
  732. !     } else if (hashop(hd, mode, key, data, cmp, hash))
  733.           return 0;
  734.       else
  735.           return -1;
  736. *** ../ddb.old/list.c    Thu Nov 18 00:08:28 1993
  737. --- list.c    Wed Nov 17 23:53:08 1993
  738. ***************
  739. *** 19,25 ****
  740.   #include <stdlib.h>
  741.   #include <string.h>
  742.   #include <sys/types.h>
  743. ! #include <ddb.h>
  744.   
  745.   extern void    *ddb_new(const DATUM *, const DATUM *, size_t);
  746.   extern int    ddb_memcmp(const DATUM *, const DATUM *);
  747. --- 19,26 ----
  748.   #include <stdlib.h>
  749.   #include <string.h>
  750.   #include <sys/types.h>
  751. ! #include <errno.h>
  752. ! #include "ddb.h"
  753.   
  754.   extern void    *ddb_new(const DATUM *, const DATUM *, size_t);
  755.   extern int    ddb_memcmp(const DATUM *, const DATUM *);
  756. ***************
  757. *** 38,47 ****
  758.   static LIST    *list = NULL;
  759.   static int    maxlists = 0;
  760.   
  761.   static int
  762.   validld(int ld)
  763.   {
  764. !     return list && ld < maxlists && list[ld].used;
  765.   }
  766.   
  767.   static int
  768. --- 39,54 ----
  769.   static LIST    *list = NULL;
  770.   static int    maxlists = 0;
  771.   
  772. + extern int    errno;
  773.   static int
  774.   validld(int ld)
  775.   {
  776. !     int    valid = list && ld < maxlists && list[ld].used;
  777. !     if (!valid)
  778. !         errno = EBADF;
  779. !     return valid;
  780.   }
  781.   
  782.   static int
  783. ***************
  784. *** 53,58 ****
  785. --- 60,66 ----
  786.       case DDB_DUPLICATE:
  787.           return 1;
  788.       default:
  789. +         errno = EINVAL;
  790.           return 0;
  791.       }
  792.   }
  793. ***************
  794. *** 99,107 ****
  795.           if (mode & DDB_TAIL)
  796.               (void)find(ld, NULL, cmp, &le_prev);
  797.       } else if (le = find(ld, key, cmp, NULL))
  798. !         if (mode & DDB_INSERT)
  799.               return -1;
  800. !         else /* DDB_REPLACE */ {
  801.               free(le->key.addr);
  802.               free(le->data.addr);
  803.               le->key = le_new->key;
  804. --- 107,116 ----
  805.           if (mode & DDB_TAIL)
  806.               (void)find(ld, NULL, cmp, &le_prev);
  807.       } else if (le = find(ld, key, cmp, NULL))
  808. !         if (mode & DDB_INSERT) {
  809. !             errno = EEXIST;
  810.               return -1;
  811. !         } else /* DDB_REPLACE */ {
  812.               free(le->key.addr);
  813.               free(le->data.addr);
  814.               le->key = le_new->key;
  815. ***************
  816. *** 144,149 ****
  817. --- 153,159 ----
  818.       if (le = find(ld, key, cmp, NULL))
  819.           return &le->data;
  820.   
  821. +     errno = ENOENT;
  822.       return NULL;
  823.   }
  824.   
  825. ***************
  826. *** 173,178 ****
  827. --- 183,189 ----
  828.           return 0;
  829.       }
  830.   
  831. +     errno = ENOENT;
  832.       return -1;
  833.   }
  834.   
  835. *** ../ddb.old/new.c    Thu Nov 18 00:08:28 1993
  836. --- new.c    Wed Nov 17 23:53:08 1993
  837. ***************
  838. *** 19,25 ****
  839.   #include <stdlib.h>
  840.   #include <sys/types.h>
  841.   #include <string.h>
  842. ! #include <ddb.h>
  843.   
  844.   void *
  845.   ddb_new(const DATUM *key, const DATUM *data, size_t size)
  846. --- 19,25 ----
  847.   #include <stdlib.h>
  848.   #include <sys/types.h>
  849.   #include <string.h>
  850. ! #include "ddb.h"
  851.   
  852.   void *
  853.   ddb_new(const DATUM *key, const DATUM *data, size_t size)
  854. *** ../ddb.old/patchlevel.h    Thu Nov 18 00:08:28 1993
  855. --- patchlevel.h    Wed Nov 17 23:53:09 1993
  856. ***************
  857. *** 1 ****
  858. ! #define PATCHLEVEL    0
  859. --- 1 ----
  860. ! #define PATCHLEVEL    1
  861. *** ../ddb.old/queue.c    Thu Nov 18 00:08:28 1993
  862. --- queue.c    Wed Nov 17 23:53:09 1993
  863. ***************
  864. *** 18,24 ****
  865.   #include <stdio.h>
  866.   #include <stdlib.h>
  867.   #include <sys/types.h>
  868. ! #include <ddb.h>
  869.   
  870.   typedef struct qent {
  871.       DATUM        data;
  872. --- 18,25 ----
  873.   #include <stdio.h>
  874.   #include <stdlib.h>
  875.   #include <sys/types.h>
  876. ! #include <errno.h>
  877. ! #include "ddb.h"
  878.   
  879.   typedef struct qent {
  880.       DATUM        data;
  881. ***************
  882. *** 35,44 ****
  883.   
  884.   extern void    *ddb_new(const DATUM *, const DATUM *, size_t);
  885.   
  886.   static int
  887.   validqd(int qd)
  888.   {
  889. !     return queue && qd < maxqueues && queue[qd].used;
  890.   }
  891.   
  892.   int
  893. --- 36,51 ----
  894.   
  895.   extern void    *ddb_new(const DATUM *, const DATUM *, size_t);
  896.   
  897. + extern int    errno;
  898.   static int
  899.   validqd(int qd)
  900.   {
  901. !     int    valid = queue && qd < maxqueues && queue[qd].used;
  902. !     if (!valid)
  903. !         errno = EBADF;
  904. !     return valid;
  905.   }
  906.   
  907.   int
  908. *** ../ddb.old/stack.c    Thu Nov 18 00:08:29 1993
  909. --- stack.c    Wed Nov 17 23:53:09 1993
  910. ***************
  911. *** 18,24 ****
  912.   #include <stdio.h>
  913.   #include <stdlib.h>
  914.   #include <sys/types.h>
  915. ! #include <ddb.h>
  916.   
  917.   typedef struct {
  918.       int    used;
  919. --- 18,25 ----
  920.   #include <stdio.h>
  921.   #include <stdlib.h>
  922.   #include <sys/types.h>
  923. ! #include <errno.h>
  924. ! #include "ddb.h"
  925.   
  926.   typedef struct {
  927.       int    used;
  928. ***************
  929. *** 31,40 ****
  930.   
  931.   extern void    *ddb_new(const DATUM *, const DATUM *, size_t);
  932.   
  933.   static int
  934.   validsd(int sd)
  935.   {
  936. !     return stack && sd < maxstacks && stack[sd].used;
  937.   }
  938.   
  939.   int
  940. --- 32,47 ----
  941.   
  942.   extern void    *ddb_new(const DATUM *, const DATUM *, size_t);
  943.   
  944. + extern int    errno;
  945.   static int
  946.   validsd(int sd)
  947.   {
  948. !     int    valid = stack && sd < maxstacks && stack[sd].used;
  949. !     if (!valid)
  950. !         errno = EBADF;
  951. !     return valid;
  952.   }
  953.   
  954.   int
  955.