dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / fm / modules / sun4 / cpumem-diagnosis / cmd_util.c
blobcadcd7e414a08e39296002f2b1cb11473ecb84b5
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 #include <cmd.h>
29 #include <errno.h>
30 #include <stdarg.h>
31 #include <string.h>
32 #include <fm/fmd_api.h>
33 #include <sys/fm/protocol.h>
35 int
36 cmd_set_errno(int err)
38 errno = err;
39 return (-1);
42 void *
43 cmd_buf_read(fmd_hdl_t *hdl, fmd_case_t *cp, const char *bufname, size_t bufsz)
45 void *buf;
46 size_t sz;
48 if ((sz = fmd_buf_size(hdl, cp, bufname)) == 0) {
49 (void) cmd_set_errno(ENOENT);
50 return (NULL);
51 } else if (sz != bufsz) {
52 (void) cmd_set_errno(EINVAL);
53 return (NULL);
56 buf = fmd_hdl_alloc(hdl, bufsz, FMD_SLEEP);
57 fmd_buf_read(hdl, cp, bufname, buf, bufsz);
59 return (buf);
62 void
63 cmd_vbufname(char *buf, size_t bufsz, const char *fmt, va_list ap)
65 char *c;
67 (void) vsnprintf(buf, bufsz, fmt, ap);
69 for (c = buf; *c != '\0'; c++) {
70 if (*c == ' ' || *c == '/' || *c == ':')
71 *c = '_';
75 void
76 cmd_bufname(char *buf, size_t bufsz, const char *fmt, ...)
78 va_list ap;
80 va_start(ap, fmt);
81 cmd_vbufname(buf, bufsz, fmt, ap);
82 va_end(ap);