2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2009-08-17 12:41:51 +02:00
|
|
|
gb_replace_temp.h
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-08-17 12:41:51 +02:00
|
|
|
(c) 2000-2009 Benoît Minisini <gambas@users.sourceforge.net>
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2009-08-17 12:41:51 +02:00
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
2007-12-30 17:41:49 +01:00
|
|
|
any later version.
|
|
|
|
|
|
|
|
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 the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "gb_replace.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
2008-03-21 02:36:11 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <termios.h>
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
#ifndef HAVE_SETENV
|
|
|
|
|
|
|
|
int setenv(const char *name, const char *value, int overwrite)
|
|
|
|
{
|
|
|
|
char *env;
|
2008-01-06 21:06:44 +01:00
|
|
|
int env_size;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
if (!name || *name == 0)
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
if (overwrite == 0)
|
|
|
|
{
|
|
|
|
if (getenv(name))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-01-06 21:06:44 +01:00
|
|
|
env_size = strlen(name) + strlen(value) + 2;
|
|
|
|
env = malloc(env_size);
|
2007-12-30 17:41:49 +01:00
|
|
|
if (!env)
|
|
|
|
return (-1);
|
|
|
|
|
2008-02-19 00:07:24 +01:00
|
|
|
strcpy(env, name);
|
|
|
|
strcat(env, "=");
|
|
|
|
strcat(env, value);
|
2007-12-30 17:41:49 +01:00
|
|
|
putenv(env);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_UNSETENV
|
|
|
|
|
|
|
|
extern char **environ;
|
|
|
|
|
|
|
|
void unsetenv(const char *name)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
char **ep;
|
|
|
|
|
|
|
|
if (name == NULL || *name == '\0' || strchr (name, '=') != NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
len = strlen(name);
|
|
|
|
|
|
|
|
ep = environ;
|
|
|
|
while (*ep != NULL)
|
|
|
|
{
|
|
|
|
if (!strncmp (*ep, name, len) && (*ep)[len] == '=')
|
|
|
|
{
|
|
|
|
char **dp = ep;
|
|
|
|
|
|
|
|
do
|
|
|
|
dp[0] = dp[1];
|
|
|
|
while (*dp++);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++ep;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_GETDOMAINNAME
|
|
|
|
|
|
|
|
int getdomainname(char *name, size_t len)
|
|
|
|
{
|
|
|
|
#if defined(HAVE_SYSINFO) && defined(SI_SRPC_DOMAIN)
|
|
|
|
sysinfo(SI_SRPC_DOMAIN, name, len);
|
|
|
|
#else
|
|
|
|
*name = 0;
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_GETPT
|
|
|
|
|
|
|
|
int getpt(void)
|
|
|
|
{
|
|
|
|
#ifdef OS_FREEBSD
|
|
|
|
return posix_openpt(O_RDWR | O_NOCTTY);
|
|
|
|
#else
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2008-03-21 02:36:11 +01:00
|
|
|
#ifndef HAVE_CFMAKERAW
|
|
|
|
|
|
|
|
void cfmakeraw(struct termios *termios_p)
|
|
|
|
{
|
|
|
|
termios_p->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
|
|
|
|
termios_p->c_oflag &= ~OPOST;
|
|
|
|
termios_p->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
|
|
|
|
termios_p->c_cflag &= ~(CSIZE|PARENB);
|
|
|
|
termios_p->c_cflag |= CS8;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|