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