* Copyright (c) 1986 Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char sccsid
[] = "@(#)db_save.c 4.16 (Berkeley) 3/21/91";
* Buffer allocation and deallocation routines.
#include <arpa/nameser.h>
* Allocate a name buffer & save name.
register struct namebuf
*np
;
np
= (struct namebuf
*) malloc(sizeof(struct namebuf
));
syslog(LOG_ERR
, "savename: %m");
np
->n_dname
= savestr(name
);
* Allocate a data buffer & save data.
savedata(class, type
, ttl
, data
, size
)
register struct databuf
*dp
;
malloc((unsigned)DATASIZE(size
)+sizeof(u_long
));
dp
= (struct databuf
*) malloc((unsigned)DATASIZE(size
));
syslog(LOG_ERR
, "savedata: %m");
bcopy(data
, dp
->d_data
, dp
->d_size
);
int hashsizes
[] = { /* hashtable sizes */
* Allocate a data buffer & save data.
register struct hashbuf
*oldhtp
;
register struct hashbuf
*htp
;
register struct namebuf
*np
, *nnp
, **hp
;
for (n
= 0; newsize
= hashsizes
[n
++]; )
if (oldhtp
->h_size
== newsize
) {
newsize
= oldhtp
->h_size
* 2 + 1;
fprintf(ddt
, "savehash GROWING to %d\n", newsize
);
htp
= (struct hashbuf
*) malloc((unsigned)HASHSIZE(newsize
));
syslog(LOG_ERR
, "savehash: %m");
bzero((char *) htp
->h_tab
, newsize
* sizeof(struct hashbuf
*));
fprintf(ddt
,"savehash(%#x) cnt=%d, sz=%d, newsz=%d\n",
oldhtp
, oldhtp
->h_cnt
, oldhtp
->h_size
, newsize
);
htp
->h_cnt
= oldhtp
->h_cnt
;
for (n
= 0; n
< oldhtp
->h_size
; n
++) {
for (np
= oldhtp
->h_tab
[n
]; np
!= NULL
; np
= nnp
) {
hp
= &htp
->h_tab
[np
->n_hashval
% htp
->h_size
];
* Allocate an inverse query buffer.
register struct invbuf
*ip
;
ip
= (struct invbuf
*) malloc(sizeof(struct invbuf
));
syslog(LOG_ERR
, "saveinv: %m");
bzero((char *)ip
->i_dname
, sizeof(ip
->i_dname
));
* Make a copy of a string and return a pointer to it.
cp
= malloc((unsigned)strlen(str
) + 1);
syslog(LOG_ERR
, "savestr: %m");