4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include "mhd_local.h"
37 int mhd_debug
= MHD_DEBUG
;
41 * free and clear error
48 if (mhep
->name
!= NULL
)
50 (void) memset(mhep
, 0, sizeof (*mhep
));
65 mhep
->errnum
= errnum
;
67 mhep
->name
= Strdup(name
);
74 * mhd_error_t to string
81 static char buf
[1024];
84 switch (mhep
->errnum
) {
86 return ("could not get any reservations");
88 return ("disk is reserved");
90 if ((emsg
= strerror(mhep
->errnum
)) != NULL
)
92 (void) sprintf(buf
, "errno %d out of range", errno
);
106 if (isatty(fileno(stderr
))) {
107 static mutex_t stderr_mx
= DEFAULTMUTEX
;
109 mhd_mx_lock(&stderr_mx
);
110 (void) vfprintf(stderr
, fmt
, ap
);
111 (void) fflush(stderr
);
112 (void) fsync(fileno(stderr
));
113 mhd_mx_unlock(&stderr_mx
);
115 vsyslog(LOG_ERR
, fmt
, ap
);
128 mhd_vprintf(fmt
, ap
);
133 * printf-like perror() log
145 size_t len
= sizeof (buf
);
148 if ((mhep
->name
!= NULL
) && (mhep
->name
[0] != '\0')) {
149 n
= snprintf(p
, len
, "%s: ", mhep
->name
);
153 if ((fmt
!= NULL
) && (*fmt
!= '\0')) {
154 n
= vsnprintf(p
, len
, fmt
, ap
);
157 n
= snprintf(p
, len
, ": ");
161 (void) snprintf(p
, len
, "%s", mhd_strerror(mhep
));
162 mhd_eprintf("%s\n", buf
);
176 mhd_vperror(mhep
, fmt
, ap
);
188 mhd_error_t status
= mhd_null_error
;
190 (void) mhd_error(&status
, errno
, NULL
);
192 mhd_vperror(&status
, fmt
, ap
);
194 mhd_clrerror(&status
);