1*84ab085aSmws /*
2*84ab085aSmws * CDDL HEADER START
3*84ab085aSmws *
4*84ab085aSmws * The contents of this file are subject to the terms of the
5*84ab085aSmws * Common Development and Distribution License, Version 1.0 only
6*84ab085aSmws * (the "License"). You may not use this file except in compliance
7*84ab085aSmws * with the License.
8*84ab085aSmws *
9*84ab085aSmws * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*84ab085aSmws * or http://www.opensolaris.org/os/licensing.
11*84ab085aSmws * See the License for the specific language governing permissions
12*84ab085aSmws * and limitations under the License.
13*84ab085aSmws *
14*84ab085aSmws * When distributing Covered Code, include this CDDL HEADER in each
15*84ab085aSmws * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*84ab085aSmws * If applicable, add the following below this CDDL HEADER, with the
17*84ab085aSmws * fields enclosed by brackets "[]" replaced with your own identifying
18*84ab085aSmws * information: Portions Copyright [yyyy] [name of copyright owner]
19*84ab085aSmws *
20*84ab085aSmws * CDDL HEADER END
21*84ab085aSmws */
22*84ab085aSmws
23*84ab085aSmws /*
24*84ab085aSmws * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
25*84ab085aSmws * Use is subject to license terms.
26*84ab085aSmws */
27*84ab085aSmws
28*84ab085aSmws #pragma ident "%Z%%M% %I% %E% SMI"
29*84ab085aSmws
30*84ab085aSmws #include <sys/smbios_impl.h>
31*84ab085aSmws
32*84ab085aSmws #include <strings.h>
33*84ab085aSmws #include <unistd.h>
34*84ab085aSmws #include <stdlib.h>
35*84ab085aSmws #include <stdarg.h>
36*84ab085aSmws #include <stdio.h>
37*84ab085aSmws
38*84ab085aSmws smbios_hdl_t *
smb_open_error(smbios_hdl_t * shp,int * errp,int err)39*84ab085aSmws smb_open_error(smbios_hdl_t *shp, int *errp, int err)
40*84ab085aSmws {
41*84ab085aSmws if (shp != NULL)
42*84ab085aSmws smbios_close(shp);
43*84ab085aSmws
44*84ab085aSmws if (errp != NULL)
45*84ab085aSmws *errp = err;
46*84ab085aSmws
47*84ab085aSmws return (NULL);
48*84ab085aSmws }
49*84ab085aSmws
50*84ab085aSmws const char *
smb_strerror(int err)51*84ab085aSmws smb_strerror(int err)
52*84ab085aSmws {
53*84ab085aSmws return (strerror(err));
54*84ab085aSmws }
55*84ab085aSmws
56*84ab085aSmws void *
smb_alloc(size_t len)57*84ab085aSmws smb_alloc(size_t len)
58*84ab085aSmws {
59*84ab085aSmws return (len ? malloc(len) : NULL);
60*84ab085aSmws }
61*84ab085aSmws
62*84ab085aSmws void *
smb_zalloc(size_t len)63*84ab085aSmws smb_zalloc(size_t len)
64*84ab085aSmws {
65*84ab085aSmws void *buf;
66*84ab085aSmws
67*84ab085aSmws if ((buf = smb_alloc(len)) != NULL)
68*84ab085aSmws bzero(buf, len);
69*84ab085aSmws
70*84ab085aSmws return (buf);
71*84ab085aSmws }
72*84ab085aSmws
73*84ab085aSmws /*ARGSUSED*/
74*84ab085aSmws void
smb_free(void * buf,size_t len)75*84ab085aSmws smb_free(void *buf, size_t len)
76*84ab085aSmws {
77*84ab085aSmws free(buf);
78*84ab085aSmws }
79*84ab085aSmws
80*84ab085aSmws /*PRINTFLIKE2*/
81*84ab085aSmws void
smb_dprintf(smbios_hdl_t * shp,const char * format,...)82*84ab085aSmws smb_dprintf(smbios_hdl_t *shp, const char *format, ...)
83*84ab085aSmws {
84*84ab085aSmws va_list ap;
85*84ab085aSmws
86*84ab085aSmws if (!(shp->sh_flags & SMB_FL_DEBUG))
87*84ab085aSmws return;
88*84ab085aSmws
89*84ab085aSmws (void) fprintf(stderr, "smb DEBUG: ");
90*84ab085aSmws va_start(ap, format);
91*84ab085aSmws (void) vfprintf(stderr, format, ap);
92*84ab085aSmws va_end(ap);
93*84ab085aSmws }
94