Пример #1
0
void
local_setenv(char *termNinfo)
{
	extern char **environ;
	static char *newenviron[2] = { 0, 0 };
	static unsigned int termsize = BUFSIZ;
	static char _terminfo[BUFSIZ];
	static char *terminfo = &_terminfo[0];
	register int termlen;

	if (termNinfo && *termNinfo) {
		if (verbose)
			(void) fprintf(trace, "setting TERMINFO=%s.\n",
			    termNinfo);
		termlen = strlen(termNinfo);
		if (termlen + 10 > termsize) {
			termsize = termlen + 20;
			terminfo = (char *) malloc(termsize * sizeof (char));
		}
		if (terminfo == (char *) NULL)
			badmalloc();
		(void) sprintf(terminfo, "TERMINFO=%s", termNinfo);
		newenviron[0] = terminfo;
	} else
		newenviron[0] = (char *) 0;
	environ = newenviron;
}
Пример #2
0
void *
xrealloc(
	void	*ptr,
	size_t	size)
{
	ptr = realloc(ptr, size);
	if (ptr || !size)
		return ptr;
	badmalloc();
	/* NOTREACHED */
	return NULL;
}
Пример #3
0
char *
xstrdup(
	const char	*s1)
{
	char		*s;

	s = strdup(s1);
	if (s)
		return s;
	badmalloc();
	/* NOTREACHED */
	return NULL;
}
Пример #4
0
void *
xmalloc(
	size_t	size)
{
	void	*ptr;

	ptr = valloc(size);
	if (ptr)
		return ptr;
	badmalloc();
	/* NOTREACHED */
	return NULL;
}
Пример #5
0
void *
xcalloc(
	size_t	nelem,
	size_t	elsize)
{
	void	*ptr;

	ptr = calloc(nelem, elsize);
	if (ptr)
		return ptr;
	badmalloc();
	/* NOTREACHED */
	return NULL;
}
Пример #6
0
/*
    Allocate and initialize the global data structures and variables.
*/
void
allocvariables(int argc, int firstoptind)
{
	register int i, nullseen;

	/* find out how many names we are dealing with */
	for (numbools = 0; boolnames[numbools]; numbools++)
		;
	for (numnums = 0; numnames[numnums]; numnums++)
		;
	for (numstrs = 0; strnames[numstrs]; numstrs++)
		;

	if (verbose) {
		(void) fprintf(trace, "There are %d boolean capabilities.\n",
		    numbools);
		(void) fprintf(trace, "There are %d numeric capabilities.\n",
		    numnums);
		(void) fprintf(trace, "There are %d string capabilities.\n",
		    numstrs);
	}

	/* Allocate storage for the names and their values */
	ibool = (struct boolstruct  *) malloc((unsigned) numbools *
	    sizeof (struct boolstruct));
	num = (struct numstruct *) malloc((unsigned) numnums *
	    sizeof (struct numstruct));
	str = (struct strstruct *) malloc((unsigned) numstrs *
	    sizeof (struct strstruct));

	/* Allocate array to keep track of which names have been used. */
	if (use)
		used = (char *) malloc((unsigned) (argc - firstoptind) *
		    sizeof (char));

	if ((ibool == NULL) || (num == NULL) || (str == NULL) ||
	    (use && (used == NULL)))
		badmalloc();

	/* Fill in the names and initialize the structures. */
	nullseen = FALSE;
	for (i = 0; i < numbools; i++) {
		ibool[i].infoname = boolnames[i];
		ibool[i].capname = boolcodes[i];
		/* This is necessary until fnames.c is */
		/* incorporated into standard curses. */
		if (nullseen || (boolfnames[i] == NULL)) {
			ibool[i].fullname = "unknown_boolean";
			nullseen = TRUE;
		} else
			ibool[i].fullname = boolfnames[i];
		ibool[i].changed = FALSE;
		ibool[i].seenagain = FALSE;
	}
	nullseen = 0;
	for (i = 0; i < numnums; i++) {
		num[i].infoname = numnames[i];
		num[i].capname = numcodes[i];
		if (nullseen || (numfnames[i] == NULL)) {
			ibool[i].fullname = "unknown_number";
			nullseen = TRUE;
		} else
			num[i].fullname = numfnames[i];
		num[i].changed = FALSE;
		num[i].seenagain = FALSE;
	}
	nullseen = 0;
	for (i = 0; i < numstrs; i++) {
		str[i].infoname = strnames[i];
		str[i].capname = strcodes[i];
		if (nullseen || (strfnames[i] == NULL)) {
			str[i].fullname = "unknown_string";
			nullseen = TRUE;
		} else
			str[i].fullname = strfnames[i];
		str[i].changed = FALSE;
		str[i].seenagain = FALSE;
	}
}