1*a824f5a1SJean-Baptiste Boric /* $NetBSD: lpkg.c,v 1.1.1.2 2009/02/02 20:44:06 joerg Exp $ */
2*a824f5a1SJean-Baptiste Boric
3*a824f5a1SJean-Baptiste Boric /*
4*a824f5a1SJean-Baptiste Boric * Copyright (c) 1999 Christian E. Hopps
5*a824f5a1SJean-Baptiste Boric * All rights reserved.
6*a824f5a1SJean-Baptiste Boric *
7*a824f5a1SJean-Baptiste Boric * Redistribution and use in source and binary forms, with or without
8*a824f5a1SJean-Baptiste Boric * modification, are permitted provided that the following conditions
9*a824f5a1SJean-Baptiste Boric * are met:
10*a824f5a1SJean-Baptiste Boric * 1. Redistributions of source code must retain the above copyright
11*a824f5a1SJean-Baptiste Boric * notice, this list of conditions and the following disclaimer.
12*a824f5a1SJean-Baptiste Boric * 2. Redistributions in binary form must reproduce the above copyright
13*a824f5a1SJean-Baptiste Boric * notice, this list of conditions and the following disclaimer in the
14*a824f5a1SJean-Baptiste Boric * documentation and/or other materials provided with the distribution.
15*a824f5a1SJean-Baptiste Boric * 3. The name of the author may not be used to endorse or promote products
16*a824f5a1SJean-Baptiste Boric * derived from this software without specific prior written permission
17*a824f5a1SJean-Baptiste Boric *
18*a824f5a1SJean-Baptiste Boric * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19*a824f5a1SJean-Baptiste Boric * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20*a824f5a1SJean-Baptiste Boric * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21*a824f5a1SJean-Baptiste Boric * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22*a824f5a1SJean-Baptiste Boric * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23*a824f5a1SJean-Baptiste Boric * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24*a824f5a1SJean-Baptiste Boric * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25*a824f5a1SJean-Baptiste Boric * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26*a824f5a1SJean-Baptiste Boric * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27*a824f5a1SJean-Baptiste Boric * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*a824f5a1SJean-Baptiste Boric *
29*a824f5a1SJean-Baptiste Boric * Package-list auxiliary functions
30*a824f5a1SJean-Baptiste Boric */
31*a824f5a1SJean-Baptiste Boric
32*a824f5a1SJean-Baptiste Boric #if HAVE_CONFIG_H
33*a824f5a1SJean-Baptiste Boric #include "config.h"
34*a824f5a1SJean-Baptiste Boric #endif
35*a824f5a1SJean-Baptiste Boric #include <nbcompat.h>
36*a824f5a1SJean-Baptiste Boric #if HAVE_ERR_H
37*a824f5a1SJean-Baptiste Boric #include <err.h>
38*a824f5a1SJean-Baptiste Boric #endif
39*a824f5a1SJean-Baptiste Boric #include "lib.h"
40*a824f5a1SJean-Baptiste Boric
41*a824f5a1SJean-Baptiste Boric /*
42*a824f5a1SJean-Baptiste Boric * Add a package to the (add/recursive delete) list
43*a824f5a1SJean-Baptiste Boric */
44*a824f5a1SJean-Baptiste Boric lpkg_t *
alloc_lpkg(const char * pkgname)45*a824f5a1SJean-Baptiste Boric alloc_lpkg(const char *pkgname)
46*a824f5a1SJean-Baptiste Boric {
47*a824f5a1SJean-Baptiste Boric lpkg_t *lpp;
48*a824f5a1SJean-Baptiste Boric
49*a824f5a1SJean-Baptiste Boric lpp = xmalloc(sizeof(*lpp));
50*a824f5a1SJean-Baptiste Boric lpp->lp_name = xstrdup(pkgname);
51*a824f5a1SJean-Baptiste Boric return (lpp);
52*a824f5a1SJean-Baptiste Boric }
53*a824f5a1SJean-Baptiste Boric
54*a824f5a1SJean-Baptiste Boric void
free_lpkg(lpkg_t * lpp)55*a824f5a1SJean-Baptiste Boric free_lpkg(lpkg_t *lpp)
56*a824f5a1SJean-Baptiste Boric {
57*a824f5a1SJean-Baptiste Boric free(lpp->lp_name);
58*a824f5a1SJean-Baptiste Boric free(lpp);
59*a824f5a1SJean-Baptiste Boric }
60*a824f5a1SJean-Baptiste Boric
61*a824f5a1SJean-Baptiste Boric lpkg_t *
find_on_queue(lpkg_head_t * qp,const char * name)62*a824f5a1SJean-Baptiste Boric find_on_queue(lpkg_head_t *qp, const char *name)
63*a824f5a1SJean-Baptiste Boric {
64*a824f5a1SJean-Baptiste Boric lpkg_t *lpp;
65*a824f5a1SJean-Baptiste Boric
66*a824f5a1SJean-Baptiste Boric for (lpp = TAILQ_FIRST(qp); lpp; lpp = TAILQ_NEXT(lpp, lp_link))
67*a824f5a1SJean-Baptiste Boric if (!strcmp(name, lpp->lp_name))
68*a824f5a1SJean-Baptiste Boric return (lpp);
69*a824f5a1SJean-Baptiste Boric return (0);
70*a824f5a1SJean-Baptiste Boric }
71