Undo io_linenum.t part of #34148. It was io_multihomed.t that I meant
[p5sagit/p5-mst-13.2.git] / ext / SDBM_File / sdbm / sdbm.c
index 5952d71..cc6d0e9 100644 (file)
@@ -24,7 +24,9 @@
 #endif
 
 #ifdef I_STRING
-# include <string.h>
+# ifndef __ultrix__
+#  include <string.h>
+# endif
 #else
 # include <strings.h>
 #endif
 /*
  * externals
  */
-#ifndef WIN32
-#ifndef sun
-extern int errno;
-#endif
+
+#include <errno.h> /* See notes in perl.h about avoiding
+                       extern int errno; */
 
 extern Malloc_t malloc proto((MEM_SIZE));
 extern Free_t free proto((Malloc_t));
-extern Off_t lseek(int, Off_t, int);
-#endif
 
 /*
  * forward
@@ -61,7 +60,7 @@ static int makroom proto((DBM *, long, int));
 #define OFF_PAG(off)   (long) (off) * PBLKSIZ
 #define OFF_DIR(off)   (long) (off) * DBLKSIZ
 
-static long masks[] = {
+static const long masks[] = {
        000000000000, 000000000001, 000000000003, 000000000007,
        000000000017, 000000000037, 000000000077, 000000000177,
        000000000377, 000000000777, 000000001777, 000000003777,
@@ -128,7 +127,7 @@ sdbm_prep(char *dirname, char *pagname, int flags, int mode)
  * open the files in sequence, and stat the dirfile.
  * If we fail anywhere, undo everything, return NULL.
  */
-#if defined(OS2) || defined(MSDOS) || defined(WIN32) || defined(CYGWIN)
+#if defined(OS2) || defined(MSDOS) || defined(WIN32) || defined(__CYGWIN__)
        flags |= O_BINARY;
 #      endif
        if ((db->pagf = open(pagname, flags, mode)) > -1) {
@@ -283,6 +282,10 @@ makroom(register DBM *db, long int hash, int need)
 {
        long newp;
        char twin[PBLKSIZ];
+#if defined(DOSISH) || defined(WIN32)
+       char zer[PBLKSIZ];
+       long oldtail;
+#endif
        char *pag = db->pagbuf;
        char *New = twin;
        register int smax = SPLTMAX;
@@ -305,6 +308,23 @@ makroom(register DBM *db, long int hash, int need)
  * still looking at the page of interest. current page is not updated
  * here, as sdbm_store will do so, after it inserts the incoming pair.
  */
+
+#if defined(DOSISH) || defined(WIN32)
+               /*
+                * Fill hole with 0 if made it.
+                * (hole is NOT read as 0)
+                */
+               oldtail = lseek(db->pagf, 0L, SEEK_END);
+               memset(zer, 0, PBLKSIZ);
+               while (OFF_PAG(newp) > oldtail) {
+                       if (lseek(db->pagf, 0L, SEEK_END) < 0 ||
+                           write(db->pagf, zer, PBLKSIZ) < 0) {
+
+                               return 0;
+                       }
+                       oldtail += PBLKSIZ;
+               }
+#endif
                if (hash & (db->hmask + 1)) {
                        if (lseek(db->pagf, OFF_PAG(db->pagbno), SEEK_SET) < 0
                            || write(db->pagf, db->pagbuf, PBLKSIZ) < 0)