eperl
view release on metacpan or search on metacpan
eperl_sys.c view on Meta::CPAN
/*
** ____ _
** ___| _ \ ___ _ __| |
** / _ \ |_) / _ \ '__| |
** | __/ __/ __/ | | |
** \___|_| \___|_| |_|
**
** ePerl -- Embedded Perl 5 Language
**
** ePerl interprets an ASCII file bristled with Perl 5 program statements
** by evaluating the Perl 5 code while passing through the plain ASCII
** data. It can operate both as a standard Unix filter for general file
** generation tasks and as a powerful Webserver scripting language for
** dynamic HTML page programming.
**
** ======================================================================
**
** Copyright (c) 1996,1997,1998 Ralf S. Engelschall <rse@engelschall.com>
**
** This program is free software; it may be redistributed and/or modified
** only under the terms of either the Artistic License or the GNU General
** Public License, which may be found in the ePerl source distribution.
** Look at the files ARTISTIC and COPYING or run ``eperl -l'' to receive
** a built-in copy of both license files.
**
** This program is distributed in the hope that it will be useful, but
** WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the
** Artistic License or the GNU General Public License for more details.
**
** ======================================================================
**
** eperl_sys.c -- ePerl system functions
*/
#include "eperl_config.h"
#include "eperl_global.h"
#include "eperl_proto.h"
/*
**
** own setenv() function which works with Perl
**
*/
char **mysetenv(char **env, char *var, char *str, ...)
{
va_list ap;
char ca[1024];
char ca2[1024];
char *cp;
int i;
char **envN;
extern char **environ;
static int stillcalled = FALSE;
int replaced = FALSE;
/* create the key=val string */
va_start(ap, str);
vsprintf(ca, str, ap);
sprintf(ca2, "%s=%s", var, ca);
cp = strdup(ca2);
/* now duplicate the old structure */
for (i = 0; env[i] != NULL; i++)
;
envN = (char **)malloc(sizeof(char *) * (i+2));
for (i = 0; env[i] != NULL; i++) {
if (strncmp(env[i], var, strlen(var)) == 0) {
envN[i] = cp;
replaced = TRUE;
}
else
envN[i] = env[i];
}
/* add the new entry if not replaced */
if (!replaced) {
envN[i++] = cp;
envN[i++] = NULL;
}
/* set the libc/exec variable which Perl uses */
if (stillcalled)
free(environ);
stillcalled = TRUE;
environ = envN;
va_end(ap);
return envN;
}
/*
**
** I/O handle redirection
**
*/
#define HANDLE_STDIN 0
#define HANDLE_STDOUT 1
#define HANDLE_STDERR 2
#define HANDLE_STORE_STDIN 10
#define HANDLE_STORE_STDOUT 11
#define HANDLE_STORE_STDERR 12
( run in 2.402 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )