1 /*######################################################################
3 # This file contains some general utility functions for wmSMPmon. #
5 # All of them were taken from the program 'top' from the procps #
7 # With thanks to the author of top: #
8 # James C. Warner <warnerjc@worldnet.att.net> #
10 # This file is placed under the conditions of the GNU Library #
11 # General Public License, version 2, or any later version. #
12 # See file COPYING for information on distribution conditions. #
14 ######################################################################*/
16 #include "standards.h"
20 * The usual program end --
21 * called only by functions in this section. */
22 void bye_bye(int eno
, const char *str
)
37 * This routine simply formats whatever the caller wants and
38 * returns a pointer to the resulting 'const char' string... */
39 const char *fmtmk(const char *fmts
, ...)
41 static char buf
[BIGBUFSIZ
]; /* with help stuff, our buffer */
42 va_list va
; /* requirements exceed 1k */
45 vsnprintf(buf
, sizeof(buf
), fmts
, va
);
47 return ((const char *)buf
);
51 * Standard error handler to normalize the look of all err o/p */
52 void std_err(const char *str
)
54 static char buf
[SMLBUFSIZ
];
57 /* we'll use our own buffer so callers can still use fmtmk()
58 * and, yes the leading tab is not the standard convention,
59 * but the standard is wrong -- OUR msg won't get lost in
60 * screen clutter, like so many others! */
61 snprintf(buf
, sizeof(buf
), "\t%s: %s\n", Myname
, str
);
63 /* not to worry, he'll change our exit code to 1 due to 'buf' */
68 * Handle our own memory stuff without the risk of leaving the
69 * user's terminal in an ugly state should things go sour. */
70 void *alloc_c(unsigned numb
)
76 if (!(p
= calloc(1, numb
)))
77 std_err("failed memory allocate");