Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / apps / JAWS / clients / WebSTONE / src / errexit.c
blobb376f878c41c5a65be4478685877c4466ecd3da1
1 /**************************************************************************
3 * Copyright (C) 1995 Silicon Graphics, Inc.
5 * These coded instructions, statements, and computer programs were
6 * developed by SGI for public use. If any changes are made to this code
7 * please try to get the changes back to the author. Feel free to make
8 * modifications and changes to the code and release it.
10 **************************************************************************/
12 /* errexit call for general error handling */
14 #include <stdio.h>
15 #ifndef WIN32
16 #include <errno.h>
17 #include <netdb.h>
18 #include <unistd.h>
19 #endif /* WIN32 */
20 #include <stdarg.h>
21 #include <sys/types.h>
23 #include "sysdep.h"
24 #include "bench.h"
26 #ifdef HAVE_VPRINTF
27 #define VPRINTF(stderr, format, args) vfprintf((stderr), (format), (args))
28 #else
29 #ifdef HAVE_DOPRNT
30 #define VPRINTF(stderr, format, args) _doprnt((format), (args), (stderr))
31 #endif /* HAVE_DOPRNT */
32 #endif /* HAVE_VPRINTF */
34 /* print an error message and exit 1 */
35 void
36 errexit(const char *format, ...)
38 va_list args;
39 char hostname[64] = "";
40 pid_t PID;
42 PID = getpid();
43 gethostname(hostname, sizeof(hostname));
44 fprintf(stderr, "%s PID %d: ", hostname, PID);
46 va_start(args, format);
47 VPRINTF(stderr, format, args);
48 debug && VPRINTF(debugfile, format, args);
49 va_end(args);
50 fflush(stderr);
51 exit(1);
53 /* that's it */
55 /* print an error message and return -1 */
56 int
57 returnerr(const char *format, ...)
59 va_list args;
60 char hostname[64] = "";
61 pid_t PID;
63 PID = getpid();
64 gethostname(hostname, sizeof(hostname));
65 fprintf(stderr, "%s PID %d: ", hostname, PID);
67 va_start(args, format);
68 VPRINTF(stderr, format, args);
69 debug && VPRINTF(debugfile, format, args);
70 va_end(args);
71 fflush(stderr);
72 debug && fflush(debugfile);
73 return(-1);
75 /* that's it */
77 /* print a debug message and then flush */
78 int
79 d_printf(const char *format, ...)
81 va_list args;
83 va_start(args, format);
84 VPRINTF(debugfile, format, args);
85 va_end(args);
87 fflush(debugfile);
88 return 0;
90 /* that's it */
92 /* returns the last network error as a string */
93 char *neterrstr(void) {
94 static char buf[200];
96 #ifdef WIN32
97 sprintf(buf, "WSAGetLastError() = %d", WSAGetLastError());
98 WSASetLastError(0);
99 #else
100 sprintf(buf, "errno = %d: %s", errno, strerror(errno));
101 errno = 0;
102 #endif /* WIN32 */
104 return buf;