Files
Arquivotheca.Solaris-2.5/cmd/backup/lib/handles.c
seta75D 7c4988eac0 Init
2021-10-11 19:38:01 -03:00

69 lines
1.1 KiB
C
Executable File

#ident "@(#)handles.c 1.4 91/12/20"
/*
* Copyright (c) 1990,1991,1992 by Sun Microsystems, Inc.
*/
#include <database/handles.h>
#include <stdlib.h>
#include <string.h>
/*LINTLIBRARY*/
static struct file_handle *handles;
struct file_handle *
new_handle(hid, host)
int hid;
char *host;
{
struct file_handle *h;
h = (struct file_handle *)malloc(sizeof (struct file_handle));
if (h == NULL_HANDLE) {
return (h);
}
if ((h->host = malloc((unsigned)(strlen(host)+1))) == NULL) {
free((char *)h);
return (NULL_HANDLE);
}
h->hid = hid;
(void) strcpy(h->host, host);
h->nxt = handles;
handles = h;
return (h);
}
struct file_handle *
handle_lookup(hid)
int hid;
{
register struct file_handle *h;
for (h = handles; h; h = h->nxt)
if (h->hid == hid)
return (h);
return (NULL_HANDLE);
}
void
free_handle(h)
struct file_handle *h;
{
register struct file_handle *p;
if (h == handles) {
handles = h->nxt;
free(h->host);
free((char *)h);
} else {
for (p = handles; p; p = p->nxt) {
if (p->nxt == h) {
p->nxt = h->nxt;
free(h->host);
free((char *)h);
}
}
}
}