* Copyright (c) 1986 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)db_save.c 4.14 (Berkeley) 6/18/88";
* 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");