Example #1
0
MODULE MODULE_EXPORT int
install_hook(const char *ga_root, const char *config, const char *app_exe)
{
	char s_drive[_MAX_DRIVE], s_dir[_MAX_DIR], s_fname[_MAX_FNAME];
	
	if(ga_root == NULL || config == NULL) {
		ga_error("[install_hook] no ga-root nor configuration were specified.\n");
		return -1;
	}
	
	_splitpath(app_exe, s_drive, s_dir, s_fname, NULL);
#if 0
	if(strncpy(g_appexe, s_fname, sizeof(g_appexe)) < 0)
		return -1;
	if(strncpy(g_root, ga_root, sizeof(g_root)) < 0)
		return -1;
	if(strncpy(g_confpath, config, sizeof(g_confpath)) < 0)
		return -1;
#endif
	_putenv_s("GA_APPEXE", s_fname);
	_putenv_s("GA_ROOT", ga_root);
	_putenv_s("GA_CONFIG", config);
	
	if((gHook = SetWindowsHookEx(WH_CBT, hook_proc, hInst, 0)) == NULL) {
		ga_error("SetWindowsHookEx filaed (0x%08x)\n", GetLastError());
		return -1;
	}

	ga_error("[install_hook] success.\n");
	
	return 0;
}
Example #2
0
int git_init()
{
	char *home;
	char path[MAX_PATH+1];
	char *prefix;
	int ret;
	size_t homesize,size;

	_fmode = _O_BINARY;
	_setmode(_fileno(stdin), _O_BINARY);
	_setmode(_fileno(stdout), _O_BINARY);
	_setmode(_fileno(stderr), _O_BINARY);

	// set HOME if not set already
	getenv_s(&homesize, NULL, 0, "HOME");
	if (!homesize)
	{
		_dupenv_s(&home,&size,"USERPROFILE");
		_putenv_s("HOME",home);
		free(home);
	}
	GetModuleFileName(NULL, path, MAX_PATH);
	convert_slash(path);

	git_extract_argv0_path(path);
	g_prefix = prefix = setup_git_directory();
	ret = git_config(git_default_config, NULL);

	if (!homesize)
	{
		_putenv_s("HOME","");/* clear home evironment to avoid affact third part software*/
	}

	return ret;
}
Example #3
0
int setenv(const char* name, const char* value, int overwrite) {
  if (overwrite == 0 && getenv(name) != nullptr) {
    return 0;
  }

  if (*value != '\0') {
    auto e = _putenv_s(name, value);
    if (e != 0) {
      errno = e;
      return -1;
    }
    return 0;
  }

  // We are trying to set the value to an empty string, but
  // _putenv_s deletes entries if the value is an empty string,
  // and just calling SetEnvironmentVariableA doesn't update
  // _environ, so we have to do these terrible things.
  if (_putenv_s(name, "  ") != 0) {
    errno = EINVAL;
    return -1;
  }

  // Here lies the documentation we blatently ignore to make
  // this work >_>...
  *getenv(name) = '\0';
  // This would result in a double null termination, which
  // normally signifies the end of the environment variable
  // list, so we stick a completely empty environment variable
  // into the list instead.
  *(getenv(name) + 1) = '=';

  // If _wenviron is null, the wide environment has not been initialized
  // yet, and we don't need to try to update it.
  // We have to do this otherwise we'd be forcing the initialization and
  // maintenance of the wide environment even though it's never actually
  // used in most programs.
  if (_wenviron != nullptr) {
    wchar_t buf[_MAX_ENV + 1];
    size_t len;
    if (mbstowcs_s(&len, buf, _MAX_ENV + 1, name, _MAX_ENV) != 0) {
      errno = EINVAL;
      return -1;
    }
    *_wgetenv(buf) = u'\0';
    *(_wgetenv(buf) + 1) = u'=';
  }

  // And now, we have to update the outer environment to have
  // a proper empty value.
  if (!SetEnvironmentVariableA(name, value)) {
    errno = EINVAL;
    return -1;
  }
  return 0;
}
Example #4
0
int git_init()
{
	char path[MAX_PATH+1];
	size_t homesize;

	_fmode = _O_BINARY;
	_setmode(_fileno(stdin), _O_BINARY);
	_setmode(_fileno(stdout), _O_BINARY);
	_setmode(_fileno(stderr), _O_BINARY);

	// set HOME if not set already
	getenv_s(&homesize, NULL, 0, "HOME");
	if (!homesize)
	{
		_wputenv_s(L"HOME", wget_windows_home_directory());
	}
	GetModuleFileName(NULL, path, MAX_PATH);
	convert_slash(path);

	git_extract_argv0_path(path);
	reset_git_env();
	g_prefix = setup_git_directory();
	git_config(git_default_config, NULL);

	if (!homesize)
	{
		_putenv_s("HOME","");/* clear home evironment to avoid affact third part software*/
	}

	return 0;
}
Example #5
0
static void portable_setenv(const char* key, const char* value) {
#ifdef SK_BUILD_FOR_WIN32
    _putenv_s(key, value);
#else
    setenv(key, value, 1);
#endif
}
int
setenv(const char *name, const char *value, int overwrite)
{
    int errcode = 0;

    if (!overwrite) {
	size_t envsize = 0;

#ifdef HAVE_GETENV_S
	errcode = getenv_s(&envsize, NULL, 0, name);
#else
	if (getenv(name) == NULL)
	    errcode = EINVAL;
#endif
	if (errcode || envsize)
	    return errcode;
    }
#ifdef HAVE__PUTENV_S
    return _putenv_s(name, value);
#else
    {
	size_t maxlen = strlen(name)+strlen(value)+2;
	char *keyval = (char *)malloc(maxlen);
	if (!keyval)
	    return ENOMEM;
	snprintf(keyval, maxlen, "%s=%s", name, value);
	return putenv(keyval);
    }
#endif
}
Example #7
0
TEST(CConfigFileMemory, parseVariables)
{
#ifdef _MSC_VER
	_putenv_s("ENV_VAR_MULTIPLIER", "2");
#else
	::setenv("ENV_VAR_MULTIPLIER", "2", 1);
#endif

	const std::string sampleCfgTxt2 =
		"@define MAXSPEED 10\n"
		"@define  MAXOMEGA  -30  \n"
		"[test]\n"
		"var1=5\n"
		"var2=${MAXSPEED}\n"
		"var3=${MAXOMEGA}\n"
		"var4=$eval{5*MAXSPEED+MAXOMEGA}\n"
		"var5 = $eval{ MAXSPEED - MAXOMEGA } \n"
		"var6=$env{ENV_VAR_MULTIPLIER}\n"
		"varstr1=MAXSPEED\n";
	;
	mrpt::config::CConfigFileMemory cfg;
	cfg.setContent(sampleCfgTxt2);

	EXPECT_EQ(cfg.read_int("test", "var1", 0), 5);
	EXPECT_EQ(cfg.read_int("test", "var2", 0), 10);
	EXPECT_EQ(cfg.read_int("test", "var3", 0), -30);
	EXPECT_NEAR(cfg.read_double("test", "var4", .0), 20.0, 1e-6);
	EXPECT_NEAR(cfg.read_double("test", "var5", .0), 40.0, 1e-6);
	EXPECT_NEAR(cfg.read_double("test", "var6", .0), 2.0, 1e-6);
	EXPECT_EQ(cfg.read_string("test", "varstr1", ""), std::string("MAXSPEED"));
}
Example #8
0
int main(int argc, char **argv)
#endif
{
    PRTime ct;
    PRExplodedTime et;
    PRStatus rv;
    char *sp1 = "Sat, 1 Jan 3001 00:00:00";  /* no time zone */
    char *sp2 = "Fri, 31 Dec 3000 23:59:60";  /* no time zone, not normalized */

#if _MSC_VER >= 1400 && !defined(WINCE)
    /* Run this test in the US Pacific Time timezone. */
    _putenv_s("TZ", "PST8PDT");
    _tzset();
#endif

    rv = PR_ParseTimeString(sp1, PR_FALSE, &ct);
    printf("rv = %d\n", rv);
    PR_ExplodeTime(ct, PR_GMTParameters, &et);
    PrintExplodedTime(&et);
    printf("\n");

    rv = PR_ParseTimeString(sp2, PR_FALSE, &ct);
    printf("rv = %d\n", rv);
    PR_ExplodeTime(ct, PR_GMTParameters, &et);
    PrintExplodedTime(&et);
    printf("\n");

    return 0;
}
		bool putenv(const char *varName, const char *value)
		{
#if defined(_MSC_VER) && _MSC_VER >= 1400
			return _putenv_s(varName, value) == 0;
#else

#endif
		}
Example #10
0
void QgsServer::putenv( const QString &var, const QString &val )
{
#ifdef _MSC_VER
  _putenv_s( var.toUtf8().data(), val.toUtf8().data() );
#else
  setenv( var.toUtf8().data(), val.toUtf8().data(), 1 );
#endif
}
// This is all you need to run all the tests
int main(int argc, char *argv[])
{
    SetupEnvironment();
    SetupNetworking();
    SelectParams(CBaseChainParams::MAIN);
    noui_connect();
    ClearDatadirCache();
    fs::path pathTemp = fs::temp_directory_path() / strprintf("test_cypherfunk-qt_%lu_%i", (unsigned long)GetTime(), (int)GetRand(100000));
    fs::create_directories(pathTemp);
    gArgs.ForceSetArg("-datadir", pathTemp.string());

    bool fInvalid = false;

    // Prefer the "minimal" platform for the test instead of the normal default
    // platform ("xcb", "windows", or "cocoa") so tests can't unintentially
    // interfere with any background GUIs and don't require extra resources.
    #if defined(WIN32)
        _putenv_s("QT_QPA_PLATFORM", "minimal");
    #else
        setenv("QT_QPA_PLATFORM", "minimal", 0);
    #endif

    // Don't remove this, it's needed to access
    // QApplication:: and QCoreApplication:: in the tests
    QApplication app(argc, argv);
    app.setApplicationName("Cypherfunk-Qt-test");

    SSL_library_init();

    URITests test1;
    if (QTest::qExec(&test1) != 0) {
        fInvalid = true;
    }
#ifdef ENABLE_WALLET
    PaymentServerTests test2;
    if (QTest::qExec(&test2) != 0) {
        fInvalid = true;
    }
#endif
    RPCNestedTests test3;
    if (QTest::qExec(&test3) != 0) {
        fInvalid = true;
    }
    CompatTests test4;
    if (QTest::qExec(&test4) != 0) {
        fInvalid = true;
    }
#ifdef ENABLE_WALLET
    WalletTests test5;
    if (QTest::qExec(&test5) != 0) {
        fInvalid = true;
    }
#endif

    fs::remove_all(pathTemp);

    return fInvalid;
}
Example #12
0
int
osdep_setenv(const char *name, const char *value, int overwrite)
{
  if (overwrite || getenv(name) == NULL) {
    _putenv_s(name, value);
  }

  return 0;
}
Example #13
0
void QgsServer::putenv( const QString &var, const QString &val )
{
#ifdef _MSC_VER
  _putenv_s( var.toStdString().c_str(), val.toStdString().c_str() );
#else
  setenv( var.toStdString().c_str(), val.toStdString().c_str(), 1 );
#endif
  sSettings.load( var );
}
Example #14
0
  void SetTZ(const char* tz) {
#if _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_
    _putenv_s("TZ", tz);
    _tzset();
#else
    setenv("TZ", tz, 1);
    tzset();
#endif
  }
Example #15
0
IntegrationTestFixture::IntegrationTestFixture()
{
    // TODO fix this when we have an encapsulation layer for handling
    // environment variables
#ifdef GMX_NATIVE_WINDOWS
    _putenv_s("GMX_MAXBACKUP", s_maxBackup.c_str());
#else
    setenv("GMX_MAXBACKUP", s_maxBackup.c_str(), true);
#endif
}
Example #16
0
void setenv(std::string name, std::string value) {
#if defined(__APPLE__) || defined(__unix)
    if (::setenv(name.c_str(), value.c_str(), 1) != 0)
        throw new std::runtime_error("Could not set environment variable");
#elif defined(_WIN32)
    if (_putenv_s(name.c_str(), value.c_str()) != 0)
        throw new std::runtime_error("Could not set environment variable");
#else
#error "util::setenv() is not implemented for this operating system"
#endif
}
Example #17
0
// qt did not introduce qputenv until 4.4, so we'll keep a copy here for 4.2
//   compat
bool my_qputenv(const char *varName, const QByteArray& value)
{
#if defined(_MSC_VER) && _MSC_VER >= 1400
    return _putenv_s(varName, value.constData()) == 0;
#else
    QByteArray buffer(varName);
    buffer += "=";
    buffer += value;
    return putenv(qstrdup(buffer.constData())) == 0;
#endif
}
Example #18
0
/*
 * os_unsetenv -- remove an environment variable
 */
int
os_unsetenv(const char *name)
{
	errno_t err;
	if ((err = _putenv_s(name, "")) != 0) {
		errno = err;
		return -1;
	}

	return 0;
}
Example #19
0
/** Restore the previously saved timezone. */
void
restore_tz(void)
{
  if (saved_tz) {
#ifdef WIN32
    _putenv_s("TZ", saved_tz);
#else
    setenv("TZ", saved_tz, 1);
#endif
    mush_free(saved_tz, "timezone");
    saved_tz = NULL;
  } else {
#ifdef WIN32
    _putenv_s("TZ", "");
#else
    unsetenv("TZ");
#endif
  }

  tzset();
}
Example #20
0
int setenv(QString name, QString value, bool overwrite)
{
    int errcode = 0;
    if(!overwrite) {
        size_t envsize = 0;
        errcode = getenv_s(&envsize, NULL, 0, name.toLatin1().constData());
        if(errcode || envsize) return errcode;
    }

    // make the update
    return _putenv_s(name.toLatin1().constData(), value.toLatin1().constData());
}
Example #21
0
// This is all you need to run all the tests
int main(int argc, char *argv[])
{
    SetupEnvironment();
    SetupNetworking();
    SelectParams(CBaseChainParams::MAIN);
    noui_connect();

    bool fInvalid = false;

    // Prefer the "minimal" platform for the test instead of the normal default
    // platform ("xcb", "windows", or "cocoa") so tests can't unintentially
    // interfere with any background GUIs and don't require extra resources.
    #if defined(WIN32)
        _putenv_s("QT_QPA_PLATFORM", "minimal");
    #else
        setenv("QT_QPA_PLATFORM", "minimal", 0);
    #endif

    // Don't remove this, it's needed to access
    // QApplication:: and QCoreApplication:: in the tests
    QApplication app(argc, argv);
    app.setApplicationName("Bitcoin-Qt-test");

    SSL_library_init();

    URITests test1;
    if (QTest::qExec(&test1) != 0) {
        fInvalid = true;
    }
#ifdef ENABLE_WALLET
    PaymentServerTests test2;
    if (QTest::qExec(&test2) != 0) {
        fInvalid = true;
    }
#endif
    RPCNestedTests test3;
    if (QTest::qExec(&test3) != 0) {
        fInvalid = true;
    }
    CompatTests test4;
    if (QTest::qExec(&test4) != 0) {
        fInvalid = true;
    }
#ifdef ENABLE_WALLET
    WalletTests test5;
    if (QTest::qExec(&test5) != 0) {
        fInvalid = true;
    }
#endif

    return fInvalid;
}
Example #22
0
int setenv(const char *name, const char *value, int overwrite)
{
        int errorcode = 0;

        if(!overwrite) {
                size_t envsize = 0;
                errorcode = getenv_s(&envsize, NULL, 0, name);
                if(errorcode || envsize)
                        return errorcode;
        }

        return _putenv_s(name, value);
}
Example #23
0
uint8_t extcap_base_parse_options(extcap_parameters * extcap, int result, char * optargument)
{
    uint8_t ret = 1;

    switch (result) {
        case EXTCAP_OPT_DEBUG:
#ifdef _WIN32
            _putenv_s("G_MESSAGES_DEBUG", "all");
#else
            setenv("G_MESSAGES_DEBUG", "all", 1);
#endif
            extcap->debug = TRUE;
            break;
        case EXTCAP_OPT_DEBUG_FILE:
            extcap_init_custom_log(optargument);
            g_log_set_default_handler(extcap_custom_log, NULL);
            break;
        case EXTCAP_OPT_LIST_INTERFACES:
            extcap->do_list_interfaces = 1;
            break;
        case EXTCAP_OPT_VERSION:
            extcap->ws_version = g_strdup(optargument);
            extcap->do_version = 1;
            break;
        case EXTCAP_OPT_LIST_DLTS:
            extcap->do_list_dlts = 1;
            break;
        case EXTCAP_OPT_INTERFACE:
            extcap->interface = g_strdup(optargument);
            break;
        case EXTCAP_OPT_CONFIG:
            extcap->show_config = 1;
            break;
        case EXTCAP_OPT_CAPTURE:
            extcap->capture = 1;
            break;
        case EXTCAP_OPT_CAPTURE_FILTER:
            extcap->capture_filter = g_strdup(optargument);
            break;
        case EXTCAP_OPT_FIFO:
            extcap->fifo = g_strdup(optargument);
            break;
        default:
            ret = 0;
    }

    return ret;
}
Example #24
0
File: aff.cpp Project: halbbob/dff
void aff::start(std::map<std::string, Variant* > args)
{
  std::list<Variant *> vl; 
  std::list<Variant *>::iterator 		 vpath; 
  AffNode*					 node;

  if (args["parent"])
    this->parent = args["parent"]->value<Node* >();
  else
    this->parent = VFS::Get().GetNode("/");
  if (args["path"])
    vl = args["path"]->value<std::list<Variant* > >();
  else
    throw(envError("aff module requires path argument"));
  if (args["cache size"])
  {
    std::ostringstream cs;
    cs << args["cache size"]->value<uint32_t >();
    this->cache_size = cs.str(); 
  }
  else
    this->cache_size = "2";
#ifndef WIN32
  setenv("AFFLIB_CACHE_PAGES", this->cache_size.c_str(), 1);
#else
  _putenv_s("AFFLIB_CACHE_PAGES", this->cache_size.c_str());
#endif

  for (vpath = vl.begin(); vpath != vl.end(); vpath++)
  {
     std::string path = (*vpath)->value<Path* >()->path;
     AFFILE* affile = af_open(path.c_str(), O_RDONLY, 0);
     if (affile)
     {
	std::string nname = path.substr(path.rfind('/') + 1);
	node = new AffNode(nname, af_get_imagesize(affile), NULL, this, path, affile);
   	this->registerTree(this->parent, node);   
	this->res[path] = new Variant(std::string("added successfully by aff module"));
     }
     else 
        this->res[path] = new Variant(std::string("can't be added by aff module"));
  }

  return ;

}
// windows has renamed the setenv func to _putenv_s
int setenv(const char *name, const char *value, int overwrite)
{
	if (!overwrite) 
	{
		// see if env var already exists
		size_t envsize = 0;
		int ret = getenv_s(&envsize, NULL, 0, name);
		// if exists, don't overwrite
		if (ret || envsize)
		{
			return ret;
		}
	}

	// set env var
	return _putenv_s(name, value);
}
Example #26
0
void BLI_setenv(const char *env, const char*val)
{
	/* SGI or free windows */
#if (defined(__sgi) || ((defined(WIN32) || defined(WIN64)) && defined(FREE_WINDOWS)))
	char *envstr= MEM_mallocN(sizeof(char) * (strlen(env) + strlen(val) + 2), "envstr"); /* one for = another for \0 */

	sprintf(envstr, "%s=%s", env, val);
	putenv(envstr);
	MEM_freeN(envstr);

	/* non-free windows */
#elif (defined(WIN32) || defined(WIN64)) /* not free windows */
	_putenv_s(env, val);
#else
	/* linux/osx/bsd */
	setenv(env, val, 1);
#endif
}
Example #27
0
void Q_setenv( const char *name, const char *value ) {
#ifdef _WIN32
    if( !value ) {
        value = "";
    }
#if( _MSC_VER >= 1400 )
    _putenv_s( name, value );
#else
    _putenv( va( "%s=%s", name, value ) );
#endif
#else // _WIN32
    if( value ) {
        setenv( name, value, 1 );
    } else {
        unsetenv( name );
    }
#endif // !_WIN32
}
Example #28
0
error_t TP_putenv_s(LPTSTR name, LPTSTR value)
{
    if (NULL == name || NULL == value) return 1;

#ifdef WINDOWS
    if( 0 != _putenv_s(name, value))
        return 2;
    else
        return 0;
#else
    int retVal = 0;
    char *assignment = (char*) malloc(sizeof(char) * (strlen(name) + strlen(value) + 1));
    sprintf(assignment, "%s=%s", name, value);

    if (0 != putenv(assignment))
        retVal = 2;
    free(assignment);
    return retVal;
#endif
}
Example #29
0
/// This function is copied from QtCoreLib (>5.1)
/// and is not available in qt4
bool TIGLViewerWindow::deleteEnvVar(const char * varName)
{
#if defined(_MSC_VER) && _MSC_VER >= 1400
    return _putenv_s(varName, "");
#elif (defined(_POSIX_VERSION) && (_POSIX_VERSION-0) >= 200112L) || defined(Q_OS_BSD4)
    // POSIX.1-2001 and BSD have unsetenv
    return unsetenv(varName) == 0;
#elif defined(Q_CC_MINGW)
    // On mingw, putenv("var=") removes "var" from the environment
    QByteArray buffer(varName);
    buffer += '=';
    return putenv(buffer.constData()) == 0;
#else
    // Fallback to putenv("var=") which will insert an empty var into the
    // environment and leak it
    QByteArray buffer(varName);
    buffer += '=';
    char *envVar = qstrdup(buffer.constData());
    return putenv(envVar) == 0;
#endif
}
Example #30
0
/** Save the current timezone (The TZ environment variable) and set a new one.
 * \param newzone The new timezone.
 */
void
save_and_set_tz(const char *newzone)
{
  const char *tz;

  if (!newzone)
    newzone = "";

  tz = getenv("TZ");
  if (tz)
    saved_tz = mush_strdup(tz, "timezone");
  else
    saved_tz = NULL;

#ifdef WIN32
  _putenv_s("TZ", newzone);
#else
  setenv("TZ", newzone, 1);
#endif

  tzset();
}