File: pvmfperror.m4

package info (click to toggle)
pvm 3.4beta7-4
  • links: PTS
  • area: main
  • in suites: slink
  • size: 5,256 kB
  • ctags: 5,938
  • sloc: ansic: 66,147; makefile: 1,446; fortran: 631; sh: 424; csh: 70; asm: 37
file content (44 lines) | stat: -rw-r--r-- 1,015 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

/* $Id: pvmfperror.m4,v 1.2 1996/10/04 15:27:26 pvmsrc Exp $ */

#include <stdio.h>
#include "pvm3.h"
#include "pvm_consts.h"

#define MAX(a,b) ((a) > (b) ? (a) : (b))

void
FUNCTION(pvmfperror) ARGS(`STRING_ARG(p), info')
STRING_ARG_DECL(p);
	int *info;
{
	static char *buf = 0;
	static int buflen = 0;
	char *malloc();

	/*
	 * Have to have a NUL at the end of the string, and
	 * the only way to do this portably is to copy the whole string
	 * into a malloc'ed buffer.  We keep the buffer around for
	 * future use rather than free'ing it each time we're done.
	 */
	if (!buf)
		buf = malloc(buflen = STRING_LEN(p) + 1);
	else
		if (STRING_LEN(p) + 1 > buflen) {
			buflen = MAX(STRING_LEN(p) + 1, buflen * 2);
			/* don't use realloc; it might cause old data to be copied */
			free(buf);
			buf = malloc(buflen);
		}
	if (!buf) {
		fprintf(stderr, "pvmfperror PvmNoMem");
		*info = PvmNoMem;
		return;
	}
	strncpy(buf, STRING_PTR(p), STRING_LEN(p));
	buf[STRING_LEN(p)] = '\0';

	*info = pvm_perror(buf);
}