2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: UErrNoBMS.c /main/9 1998/04/09 17:50:11 mgreess $ */
25 * (c) Copyright 1995 Digital Equipment Corporation.
26 * (c) Copyright 1987, 1988, 1989, 1990, 1993, 1994, 1995 Hewlett-Packard Company
27 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
28 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
29 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
30 * (c) Copyright 1995 FUJITSU LIMITED.
31 * (c) Copyright 1995 Hitachi.
33 /*************************************<+>*************************************
34 *****************************************************************************
40 ** Description: This file contains the CDE 1.0 message logging functions
42 ****************************************************************************
43 ************************************<+>*************************************/
48 #include <Dt/MsgLog.h>
49 #include <Dt/MsgLogI.h>
50 #include <Dt/UserMsg.h>
52 #define MESSAGE_BUFFER 2048
55 static char * errno_string(
56 unsigned int errn, char *buff) ;
57 static void log_message(
67 unsigned int errn, char *buff)
73 /* These are all in POSIX 1003.1 and/or X/Open XPG3 */
74 /* ---------------------------------------------------- */
75 case EPERM : s = "EPERM"; break;
76 case ENOENT : s = "ENOENT"; break;
77 case ESRCH : s = "ESRCH"; break;
78 case EINTR : s = "EINTR"; break;
79 case EIO : s = "EIO"; break;
80 case ENXIO : s = "ENXIO"; break;
81 case E2BIG : s = "E2BIG"; break;
82 case ENOEXEC : s = "ENOEXEC";break;
83 case EBADF : s = "EBADF"; break;
84 case ECHILD : s = "ECHILD"; break;
85 case EAGAIN : s = "EAGAIN"; break;
86 case ENOMEM : s = "ENOMEM"; break;
87 case EACCES : s = "EACCES"; break;
88 case EFAULT : s = "EFAULT"; break;
89 case ENOTBLK : s = "ENOTBLK";break;
90 case EBUSY : s = "EBUSY"; break;
91 case EEXIST : s = "EEXIST"; break;
92 case EXDEV : s = "EXDEV"; break;
93 case ENODEV : s = "ENODEV"; break;
94 case ENOTDIR : s = "ENOTDIR";break;
95 case EISDIR : s = "EISDIR"; break;
96 case EINVAL : s = "EINVAL"; break;
97 case ENFILE : s = "ENFILE"; break;
98 case EMFILE : s = "EMFILE"; break;
99 case ENOTTY : s = "ENOTTY"; break;
100 case ETXTBSY : s = "ETXTBSY";break;
101 case EFBIG : s = "EFBIG"; break;
102 case ENOSPC : s = "ENOSPC"; break;
103 case ESPIPE : s = "ESPIPE"; break;
104 case EROFS : s = "EROFS"; break;
105 case EMLINK : s = "EMLINK"; break;
106 case EPIPE : s = "EPIPE"; break;
107 case ENOMSG : s = "ENOMSG"; break;
108 case EIDRM : s = "EIDRM"; break;
109 case EDEADLK : s = "EDEADLK";break;
110 case ENOLCK : s = "ENOLCK"; break;
112 case ENOTEMPTY : s = "ENOTEMPTY"; break;
114 case ENAMETOOLONG : s = "ENAMETOOLONG"; break;
115 case ENOSYS : s = "ENOSYS"; break;
116 default : s = NULL; break;
120 sprintf(buff, "%s (%d)",s,errn);
122 sprintf(buff, "(%d)",errn);
129 * This function calls the CDE message logging service.
139 char * errmsg = NULL;
140 char * errname = NULL;
142 DtMsgLogType msg_type;
145 (void) strcpy (format, "%s");
148 (void) strcat (format, "\n %s");
153 if (errnoset == TRUE) /* Use "errno" from <errno.h> ? */
154 errn = errno; /* --- yep. */
156 errn = errnoset; /* No, not the magic value, use parm */
158 errname = errno_string(errn, buff);
160 if (!(errmsg = strerror(errn)))
165 * Must map the old message types to the new
171 msg_type = DtMsgLogError; break;
174 msg_type = DtMsgLogInformation; break;
176 msg_type = DtMsgLogWarning; break;
178 msg_type = DtMsgLogError;
182 (void) strcat (format, "\n [%s] %s");
186 DtMsgLogMessage (progName, msg_type, format, message, help,
189 DtMsgLogMessage (progName, msg_type, format, message, help);
192 DtMsgLogMessage (progName, msg_type, format, message, errname, errmsg);
194 DtMsgLogMessage (progName, msg_type, format, message);
208 char *message = (char*) malloc(MESSAGE_BUFFER);
210 if (NULL == message) return;
212 Va_start(args, format);
213 #if defined(USE_SNPRINTF)
214 (void) vsnprintf(message, MESSAGE_BUFFER, format, args);
216 (void) vsprintf(message, format, args);
220 log_message(progName, help, message, severity, FALSE);
221 if (message) free(message);
233 char *message = (char*) malloc(MESSAGE_BUFFER);
235 if (NULL == message) return;
237 Va_start(args, format);
238 #if defined(USE_SNPRINTF)
239 (void) vsnprintf(message, MESSAGE_BUFFER, format, args);
241 (void) vsprintf(message, format, args);
245 log_message(progName, help, message, severity, TRUE);
246 if (message) free(message);