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 #include <sys/smbios_impl.h>
29*84ab085aSmws
30*84ab085aSmws #include <strings.h>
31*84ab085aSmws #include <unistd.h>
32*84ab085aSmws #include <stdlib.h>
33*84ab085aSmws #include <stdarg.h>
34*84ab085aSmws #include <stdio.h>
35*84ab085aSmws
36*84ab085aSmws smbios_hdl_t *
smb_open_error(smbios_hdl_t * shp,int * errp,int err)37*84ab085aSmws smb_open_error(smbios_hdl_t *shp, int *errp, int err)
38*84ab085aSmws {
39*84ab085aSmws if (shp != NULL)
40*84ab085aSmws smbios_close(shp);
41*84ab085aSmws
42*84ab085aSmws if (errp != NULL)
43*84ab085aSmws *errp = err;
44*84ab085aSmws
45*84ab085aSmws return (NULL);
46*84ab085aSmws }
47*84ab085aSmws
48*84ab085aSmws const char *
smb_strerror(int err)49*84ab085aSmws smb_strerror(int err)
50*84ab085aSmws {
51*84ab085aSmws return (strerror(err));
52*84ab085aSmws }
53*84ab085aSmws
54*84ab085aSmws void *
smb_alloc(size_t len)55*84ab085aSmws smb_alloc(size_t len)
56*84ab085aSmws {
57*84ab085aSmws return (len ? malloc(len) : NULL);
58*84ab085aSmws }
59*84ab085aSmws
60*84ab085aSmws void *
smb_zalloc(size_t len)61*84ab085aSmws smb_zalloc(size_t len)
62*84ab085aSmws {
63*84ab085aSmws void *buf;
64*84ab085aSmws
65*84ab085aSmws if ((buf = smb_alloc(len)) != NULL)
66*84ab085aSmws bzero(buf, len);
67*84ab085aSmws
68*84ab085aSmws return (buf);
69*84ab085aSmws }
70*84ab085aSmws
71*84ab085aSmws /*ARGSUSED*/
72*84ab085aSmws void
smb_free(void * buf,size_t len)73*84ab085aSmws smb_free(void *buf, size_t len)
74*84ab085aSmws {
75*84ab085aSmws free(buf);
76*84ab085aSmws }
77*84ab085aSmws
78*84ab085aSmws /*PRINTFLIKE2*/
79*84ab085aSmws void
smb_dprintf(smbios_hdl_t * shp,const char * format,...)80*84ab085aSmws smb_dprintf(smbios_hdl_t *shp, const char *format, ...)
81*84ab085aSmws {
82*84ab085aSmws va_list ap;
83*84ab085aSmws
84*84ab085aSmws if (!(shp->sh_flags & SMB_FL_DEBUG))
85*84ab085aSmws return;
86*84ab085aSmws
87*84ab085aSmws (void) fprintf(stderr, "smb DEBUG: ");
88*84ab085aSmws va_start(ap, format);
89*84ab085aSmws (void) vfprintf(stderr, format, ap);
90*84ab085aSmws va_end(ap);
91*84ab085aSmws }
92