2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2013-03-30 00:33:01 +01:00
|
|
|
gb_replace_temp.h
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2017-01-13 04:29:42 +01:00
|
|
|
(c) 2000-2017 Benoît Minisini <gambas@users.sourceforge.net>
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-03-30 00:33:01 +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
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-03-30 00:33:01 +01:00
|
|
|
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.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-03-30 00:33:01 +01:00
|
|
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#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)
|
|
|
|
{
|
2013-03-30 00:33:01 +01:00
|
|
|
char *env;
|
|
|
|
int env_size;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-03-30 00:33:01 +01:00
|
|
|
if (!name || *name == 0)
|
|
|
|
return (-1);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-03-30 00:33:01 +01:00
|
|
|
if (overwrite == 0)
|
|
|
|
{
|
|
|
|
if (getenv(name))
|
|
|
|
return 0;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-03-30 00:33:01 +01:00
|
|
|
env_size = strlen(name) + strlen(value) + 2;
|
|
|
|
env = malloc(env_size);
|
|
|
|
if (!env)
|
|
|
|
return (-1);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-03-30 00:33:01 +01:00
|
|
|
strcpy(env, name);
|
|
|
|
strcat(env, "=");
|
|
|
|
strcat(env, value);
|
|
|
|
putenv(env);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2013-03-30 00:33:01 +01:00
|
|
|
return 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_UNSETENV
|
|
|
|
|
|
|
|
extern char **environ;
|
|
|
|
|
|
|
|
void unsetenv(const char *name)
|
|
|
|
{
|
2013-03-30 00:33:01 +01:00
|
|
|
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;
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_GETDOMAINNAME
|
|
|
|
|
|
|
|
int getdomainname(char *name, size_t len)
|
|
|
|
{
|
|
|
|
#if defined(HAVE_SYSINFO) && defined(SI_SRPC_DOMAIN)
|
2013-03-30 00:33:01 +01:00
|
|
|
sysinfo(SI_SRPC_DOMAIN, name, len);
|
2007-12-30 17:41:49 +01:00
|
|
|
#else
|
2013-03-30 00:33:01 +01:00
|
|
|
*name = 0;
|
|
|
|
return 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
#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)
|
|
|
|
{
|
2013-03-30 00:33:01 +01:00
|
|
|
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;
|
2008-03-21 02:36:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|