File: pvmfperror.m4

package info (click to toggle)
pvm 3.4.6-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 8,284 kB
  • sloc: ansic: 72,074; makefile: 1,198; fortran: 631; sh: 285; csh: 74; asm: 37
file content (50 lines) | stat: -rw-r--r-- 1,089 bytes parent folder | download | duplicates (4)
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
45
46
47
48
49
50

/* $Id: pvmfperror.m4,v 1.3 2007/04/19 23:15:00 pvmsrc Exp $ */

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

#ifdef  SYSVSTR
#include <string.h>
#else
#include <strings.h>
#endif

#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;

	/*
	 * 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);
}