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