static int write_index(int index_fd, off_t data_offset, off_t data_len, const char* sha1_hex)
{
    struct timeval tv;
    gettimeofday(&tv, NULL);

    const int buf_size = 256;
    char buf[buf_size];

    const char *remote_addr = getenv("HTTP_X_FORWARDED_FOR");
    if (remote_addr == NULL) {
        remote_addr = getenv("REMOTE_ADDR");
    }
    if (remote_addr == NULL) {
        remote_addr = "";
    }

    int rowlen = snprintf(
        buf,
        buf_size,
        "%lld %lld {\"ip\":\"%s\",\"t\":%lld,\"sha1\":\"%s\"}\n",
        (long long)data_offset,
        (long long)data_len,
        remote_addr,
        (long long)(tv.tv_sec * 1000 + tv.tv_usec / 1000),
        sha1_hex
    );

    errno = 0;
    ssize_t amt_written = write(index_fd, buf, rowlen);
    int ok = (amt_written == rowlen);
    if (!ok) {
        perror("Failed to write index");
    }
    return ok;
}
void lt_debug_init(void)
{
	int i = 0;
	char *tmp = getenv("HAL_DEBUG");
	if (! tmp)
		tmp = getenv("TRIPLE_DEBUG"); /* backwards compatibility... */
	if (! tmp)
		debuglevel = 0;
	else
		debuglevel = (int) strtol(tmp, NULL, 0);

	if (debuglevel == 0)
	{
		fprintf(stderr, "libstb-hal debug options can be set by exporting HAL_DEBUG.\n");
		fprintf(stderr, "The following values (or bitwise OR combinations) are valid:\n");
		while (lt_facility[i]) {
			fprintf(stderr, "\tcomponent: %s  0x%02x\n", lt_facility[i], 1 << i);
			i++;
		}
		fprintf(stderr, "\tall components:    0x%02x\n", (1 << i) - 1);
	} else {
		fprintf(stderr, "libstb-hal debug is active for the following components:\n");
		while (lt_facility[i]) {
			if (debuglevel & (1 << i))
				fprintf(stderr, "%s ", lt_facility[i]);
			i++;
		}
		fprintf(stderr, "\n");
	}
}
Example #3
0
/*!
 * \brief Get user's home directory
 *
 * Returns a pointer to a string which is the full path name of the
 * user's home directory.
 *
 * \return pointer to string
 * \return NULL on error
 */
const char *G__home(void)
{
    static int initialized;
    static const char *home = 0;

    if (G_is_initialized(&initialized))
	return home;

#ifdef __MINGW32__
    {
	char buf[GPATH_MAX];

	/* TODO: we should probably check if the dir exists */
	home = getenv("USERPROFILE");

	if (!home) {
	    sprintf(buf, "%s%s", getenv("HOMEDRIVE"), getenv("HOMEPATH"));

	    if (strlen(buf) >= 0)
		home = G_store(buf);
	}

	if (!home)
	    home = getenv("HOME");
    }
#else
    home = getenv("HOME");
#endif
    G_initialize_done(&initialized);
    return home;
}
Example #4
0
int
update_path_init(void)
{
	char buf[10240];
	char *cp, *thisp, *nextp;

	update_path_l = encap_list_new(LIST_QUEUE, NULL);
	if (update_path_l == NULL)
		return -1;

	cp = getenv("ENCAP_UPDATE_PATH");
	if (cp != NULL)
	{
		strlcpy(buf, cp, sizeof(buf));

		nextp = buf;
		while ((thisp = strsep(&nextp, " \t")) != NULL)
		{
			if (*thisp == '\0')
				continue;

			if (update_path_add(thisp, 0) != 0)
				return -1;
		}

		return 0;
	}

	cp = getenv("ENCAP_UPDATEDIR");
	if (cp != NULL
	    && update_path_add(cp, 0) != 0)
		return -1;

	return 0;
}
Example #5
0
void board_recovery_setup(void)
{
	int bootdev = get_boot_device();

	switch (bootdev) {
#if defined(CONFIG_FASTBOOT_STORAGE_MMC)
	case SD3_BOOT:
	case MMC3_BOOT:
		if (!getenv("bootcmd_android_recovery"))
			setenv("bootcmd_android_recovery", "booti mmc0 recovery");
		break;
	case SD4_BOOT:
	case MMC4_BOOT:
		if (!getenv("bootcmd_android_recovery"))
			setenv("bootcmd_android_recovery", "booti mmc1 recovery");
		break;
#endif /*CONFIG_FASTBOOT_STORAGE_MMC*/
#if defined(CONFIG_FASTBOOT_STORAGE_NAND)
	case NAND_BOOT:
		if (!getenv("bootcmd_android_recovery"))
			setenv("bootcmd_android_recovery",
				"nand read ${loadaddr} ${recovery_nand_offset} "
				"${recovery_nand_size};booti ${loadaddr}");
		break;
#endif /*CONFIG_FASTBOOT_STORAGE_NAND*/
	default:
		printf("Unsupported bootup device for recovery: dev: %d\n",
			bootdev);
		return;
	}

	printf("setup env for recovery..\n");
	setenv("bootcmd", "run bootcmd_android_recovery");
}
Example #6
0
static void perhapsRunQmake(int ac, char **av)
{
#if defined(RLWIN32)
    struct stat buf;
    if(getenv("QTDIR") == NULL) return;
    rlString name(getenv("QTDIR"));
    name.cat("\\bin\\qmake.exe");
    int ret = stat(name.text(),&buf);
    if(ret < 0)
    {
        printf("stat(\"%s\") ret=%d\n", name.text(), ret);
        return;
    }
    rlString cmd(name.text());
    for(int i=1; i<ac; i++) {
        cmd.cat(" ");
        cmd.cat(av[i]);
    }
    printf("running real: %s\n", cmd.text());
    ret = system(cmd.text());
    exit(ret);
#elif defined(RLMAC)
    rlString cmd("qmake");
    for(int i=1; i<ac; i++) {
        cmd.cat(" ");
        cmd.cat(av[i]);
    }
    printf("running real: %s\n", cmd.text());
    int ret = system(cmd.text());
    exit(ret);
#elif defined(RLUNIX)
    struct stat buf;
    const char *candidates[] = { "/usr/bin/qmake",
                                 "/usr/bin/qmake-qt4",
                                 "/usr/lib/qt4/bin/qmake-qt4",
                                 "/usr/lib/qt4/bin/qmake",
                                 "/usr/lib64/qt4/bin/qmake-qt4",
                                 "/usr/lib64/qt4/bin/qmake",
                                 ""
                               };
    const char *name;
    for(int j=0; ; j++)
    {
        name = candidates[j];
        if(*name == '\0') break;
        int ret = stat(name,&buf);
        if(ret >= 0)
        {
            rlString cmd(name);
            for(int i=1; i<ac; i++) {
                cmd.cat(" ");
                cmd.cat(av[i]);
            }
            printf("running real: %s\n", cmd.text());
            ret = system(cmd.text());
            exit(ret);
        }
    }
#endif
}
Example #7
0
static void write_username(char *home)
{
	int fd, ret;
	char path[PATH_MAX];
	char user[512];

	memset(path, 0, sizeof(path));
	slprintf(path, sizeof(path), "%s/%s", home, FILE_USERNAM);

	printf("Username: [%s] ", getenv("USER"));
	fflush(stdout);

	memset(user, 0, sizeof(user));
	if (fgets(user, sizeof(user), stdin) == NULL)
		panic("Could not read from stdin!\n");
	user[sizeof(user) - 1] = 0;
	user[strlen(user) - 1] = 0; /* omit last \n */
	if (strlen(user) == 0)
		strlcpy(user, getenv("USER"), sizeof(user));

	fd = open_or_die_m(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);

	ret = write(fd, user, strlen(user));
	if (ret != strlen(user))
		panic("Could not write username!\n");

	close(fd);

	printf("Username written to %s!\n", path);
}
Example #8
0
select_file_name (char * fname)
{
  const char * env;
  char * ptr;
  FILE * tfile;

  /* Keep generating file names till we find one that's not in use */
  for (;;) {
    /* Get temp directory name from environment TMP or TEMP variable;
     * if none, use "."
     */
    if ((env = (const char *) getenv("TMP")) == NULL)
      if ((env = (const char *) getenv("TEMP")) == NULL)
	env = ".";
    if (*env == '\0')		/* null string means "." */
      env = ".";
    ptr = fname;		/* copy name to fname */
    while (*env != '\0')
      *ptr++ = *env++;
    if (ptr[-1] != '\\' && ptr[-1] != '/')
      *ptr++ = '\\';		/* append backslash if not in env variable */
    /* Append a suitable file name */
    next_file_num++;		/* advance counter */
    sprintf(ptr, "JPG%03d.TMP", next_file_num);
    /* Probe to see if file name is already in use */
    if ((tfile = fopen(fname, READ_BINARY)) == NULL)
      break;
    fclose(tfile);		/* oops, it's there; close tfile & try again */
  }
}
Example #9
0
void
lmplayer_search_init(LmplayerObject *lmplayer)
{
	gchar *database;
	gchar *path;

	database = gconf_client_get_string(lmplayer->gc, GCONF_PREFIX"/library_database", NULL);

	if(!database || strlen(database) < 1)
	{
		database = g_build_filename((const char*)getenv("HOME"), ".lmplayer/media.database", NULL);
	  gconf_client_set_string(lmplayer->gc, GCONF_PREFIX"/library_database", (const gchar*)database, NULL);
	}

	path = gconf_client_get_string(lmplayer->gc, GCONF_PREFIX"/library_path", NULL);

	if(!path)
	{
		path = g_build_filename((const char*)getenv("HOME"), _("Music"), NULL);
		gconf_client_set_string(lmplayer->gc, GCONF_PREFIX"/library_path", (const gchar*)path, NULL);
	}

	search_library_init(database, path);

	g_free(database);
	g_free(path);
}
/*
 * Under a POSIX setup, the locale string should have a format
 * like [language[_territory][.codeset][@modifier]].
 *
 * So search for the underscore, and see if the "territory" is
 * US, and turn on imperial units by default.
 *
 * I guess Burma and Liberia should trigger this too. I'm too
 * lazy to look up the territory names, though.
 */
void setup_system_prefs(void)
{
	const char *env;

	subsurface_OS_pref_setup();
	default_prefs.divelist_font = strdup(system_divelist_default_font);
	default_prefs.font_size = system_divelist_default_font_size;

#if !defined(SUBSURFACE_MOBILE)
	default_prefs.default_filename = system_default_filename();
#endif
	env = getenv("LC_MEASUREMENT");
	if (!env)
		env = getenv("LC_ALL");
	if (!env)
		env = getenv("LANG");
	if (!env)
		return;
	env = strchr(env, '_');
	if (!env)
		return;
	env++;
	if (strncmp(env, "US", 2))
		return;

	default_prefs.units = IMPERIAL_units;
}
Example #11
0
File: ffe.c Project: igitur/ffe
char *
get_default_rc_name()
{
    char *home;
    char *result;
#ifdef WIN32
    char *file = "ffe.rc";
#else
    char *file = ".fferc";
#endif

    result = NULL;
    home = getenv("HOME");
#ifdef WIN32
    if(home == NULL)
    {
        home = getenv("FFE_HOME");
        if(home == NULL)
        {
            home = getenv("USERPROFILE");
        }
    }
#endif
    if(home != NULL)
    {
        result = xmalloc(strlen(home) + strlen(file) + strlen(PATH_SEPARATOR_STRING) + 2);
        strcpy(result,home);
        strcat(result,PATH_SEPARATOR_STRING);
        strcat(result,file);
    } else
    {
        result = file;
    }
    return result;
}
Example #12
0
void
initio(void)
{
#ifdef DF
	const char *lfp;
#endif

	/* force buffer allocation */
	shf_fdopen(1, SHF_WR, shl_stdout);
	shf_fdopen(2, SHF_WR, shl_out);
	shf_fdopen(2, SHF_WR, shl_xtrace);
#ifdef DF
	if ((lfp = getenv("SDMKSH_PATH")) == NULL) {
		if ((lfp = getenv("HOME")) == NULL || !mksh_abspath(lfp))
			errorf("can't get home directory");
		lfp = shf_smprintf(Tf_sSs, lfp, "mksh-dbg.txt");
	}

	if ((shl_dbg_fd = open(lfp, O_WRONLY | O_APPEND | O_CREAT, 0600)) < 0)
		errorf("can't open debug output file %s", lfp);
	if (shl_dbg_fd < FDBASE) {
		int nfd;

		nfd = fcntl(shl_dbg_fd, F_DUPFD, FDBASE);
		close(shl_dbg_fd);
		if ((shl_dbg_fd = nfd) == -1)
			errorf("can't dup debug output file");
	}
	fcntl(shl_dbg_fd, F_SETFD, FD_CLOEXEC);
	shf_fdopen(shl_dbg_fd, SHF_WR, shl_dbg);
	DF("=== open ===");
#endif
	initio_done = true;
}
Example #13
0
/*******************************************************************
 * collectors 
 */
int file_open_collector(struct collector *my, char *fname, char *flags)
{
	unsigned int count=0;
	time_t now=time(NULL);

	my->fp = (strcmp(fname,"-")==0?stdout:fopen(fname,flags));
	if (my->fp==NULL)
	{
		gl_error("collector file %s: %s", fname, strerror(errno));
		my->status = TS_DONE;
		return 0;
	}
	my->last.ts = TS_ZERO;
	my->status=TS_OPEN;
	my->type = FT_FILE;
	my->samples=0;

	/* put useful header information in file first */
	count += fprintf(my->fp,"# file...... %s\n", my->file);
	count += fprintf(my->fp,"# date...... %s", asctime(localtime(&now)));
#ifdef WIN32
	count += fprintf(my->fp,"# user...... %s\n", getenv("USERNAME"));
	count += fprintf(my->fp,"# host...... %s\n", getenv("MACHINENAME"));
#else
	count += fprintf(my->fp,"# user...... %s\n", getenv("USER"));
	count += fprintf(my->fp,"# host...... %s\n", getenv("HOST"));
#endif
	count += fprintf(my->fp,"# group..... %s\n", my->group);
	count += fprintf(my->fp,"# trigger... %s\n", my->trigger[0]=='\0'?"(none)":my->trigger);
	count += fprintf(my->fp,"# interval.. %d\n", my->interval);
	count += fprintf(my->fp,"# limit..... %d\n", my->limit);
	count += fprintf(my->fp,"# property.. timestamp,%s\n", my->property);

	return count;
}
Example #14
0
/*******************************************************************
 * recorders 
 */
int file_open_recorder(struct recorder *my, char *fname, char *flags)
{
	time_t now=time(NULL);
	OBJECT *obj=OBJECTHDR(my);
	
	my->fp = (strcmp(fname,"-")==0?stdout:fopen(fname,flags));
	if (my->fp==NULL)
	{
		gl_error("recorder file %s: %s", fname, strerror(errno));
		my->status = TS_DONE;
		return 0;
	}
	my->type = FT_FILE;
	my->last.ts = TS_ZERO;
	my->status=TS_OPEN;
	my->samples=0;

	/* put useful header information in file first */
	fprintf(my->fp,"# file...... %s\n", my->file);
	fprintf(my->fp,"# date...... %s", asctime(localtime(&now)));
#ifdef WIN32
	fprintf(my->fp,"# user...... %s\n", getenv("USERNAME"));
	fprintf(my->fp,"# host...... %s\n", getenv("MACHINENAME"));
#else
	fprintf(my->fp,"# user...... %s\n", getenv("USER"));
	fprintf(my->fp,"# host...... %s\n", getenv("HOST"));
#endif
	fprintf(my->fp,"# target.... %s %d\n", obj->parent->oclass->name, obj->parent->id);
	fprintf(my->fp,"# trigger... %s\n", my->trigger[0]=='\0'?"(none)":my->trigger);
	fprintf(my->fp,"# interval.. %d\n", my->interval);
	fprintf(my->fp,"# limit..... %d\n", my->limit);
	fprintf(my->fp,"# timestamp,%s\n", my->property);

	return 1;
}
Example #15
0
sqlite3 *open_or_create_db(char *name) {
	sqlite3 *db;
	int r;

	char *index_file_name;
	if (getenv("XDG_CONFIG_HOME") != NULL) {
		asprintf(&index_file_name, "%s/minstrel/%s", getenv("XDG_CONFIG_HOME"), name);
	} else {
		asprintf(&index_file_name, "%s/.config/minstrel/%s", getenv("HOME"), name);
	}
	oomp(index_file_name);

	r = sqlite3_open_v2(index_file_name, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, NULL);

	oomp(db);

	if (r != SQLITE_OK) {
		fprintf(stderr, "Failed to open/create index file: %s\n", sqlite3_errmsg(db));
		exit(EXIT_FAILURE);
	}

	free(index_file_name);

	return db;
}
bool ApplicationList::FindDefaultWindowsEditor()
{
    bool foundOne = false;
#ifdef WIN64 // As long as we do support 32-bit XP, we cannot be sure that the environment variable "ProgramFiles(x86)" exists
    const QString appPathx86(getenv("ProgramFiles(x86)"));
#else
    const QString appPathx86(getenv("ProgramFiles"));
#endif
    const QString appPathx64(getenv("ProgramW6432"));
    const QString windowsPath(getenv("windir"));

    if (CheckAndAddApplication(appPathx86 + "\\Notepad++\\notepad++.exe", "Notepad++", "-n(line) (file)"))
        foundOne = true;
    else if (CheckAndAddApplication(appPathx64 + "\\Notepad++\\notepad++.exe", "Notepad++", "-n(line) (file)"))
        foundOne = true;

    if (CheckAndAddApplication(appPathx86 + "\\Notepad2\\Notepad2.exe", "Notepad2", "/g (line) (file)"))
        foundOne = true;
    else if (CheckAndAddApplication(appPathx64 + "\\Notepad2\\Notepad2.exe", "Notepad2", "/g (line) (file)"))
        foundOne = true;

    if (CheckAndAddApplication(windowsPath + "\\system32\\notepad.exe", "Notepad", "(file)"))
        foundOne = true;

    QString regPath = "HKEY_CLASSES_ROOT\\Applications\\QtProject.QtCreator.pro\\shell\\Open\\command";
    QSettings registry(regPath, QSettings::NativeFormat);
    QString qtCreatorRegistry = registry.value("Default", QString()).toString();
    QString qtCreatorPath = qtCreatorRegistry.left(qtCreatorRegistry.indexOf(".exe") + 4);
    if (!qtCreatorRegistry.isEmpty() && CheckAndAddApplication(qtCreatorPath, "Qt Creator", "-client (file):(line)")) {
        foundOne = true;
    }
    return foundOne;
}
Example #17
0
// This performs the rest of initialization
void __attribute__((constructor)) sigcheck_init_2(void) {
    if(!sigcheck_initialized)
        sigcheck_init_1();

    char *sigcheck_fd_ = getenv("SIGCHECK_OUTPUT_FILENO");
    if(sigcheck_fd_)
        sigcheck_fd = atoi(sigcheck_fd_);

    char *verbose_ = getenv("SIGCHECK_VERBOSE");
    if(verbose_)
        verbose = atoi(verbose_);

    char *max_errors_ = getenv("SIGCHECK_MAX_ERRORS");
    if(max_errors_)
        max_errors = atoi(max_errors_);

    char *fork_tests_ = getenv("SIGCHECK_FORK_TESTS");
    if(!fork_tests_ || 0 == strcmp(fork_tests_, "none"))
        fork_tests = FORK_TESTS_NONE;
    else if(0 == strcmp(fork_tests_, "atexit"))
        fork_tests = FORK_TESTS_ATEXIT;
    else if(0 == strcmp(fork_tests_, "onset"))
        fork_tests = FORK_TESTS_ONSET;
    else
        DIE("unknown value for SIGCHECK_FORK_TESTS: ", fork_tests_);

    // TODO: can we force this to be run _before_ all other handlers?
    atexit(sigcheck_finalize);
}
Example #18
0
static bool
allow_gpm_mouse(void)
{
    bool result = FALSE;

    /* GPM does printf's without checking if stdout is a terminal */
    if (isatty(fileno(stdout))) {
	char *list = getenv("NCURSES_GPM_TERMS");
	char *env = getenv("TERM");
	if (list != 0) {
	    if (env != 0) {
		result = _nc_name_match(list, env, "|:");
	    }
	} else {
	    /* GPM checks the beginning of the $TERM variable to decide if it
	     * should pass xterm events through.  There is no real advantage in
	     * allowing GPM to do this.  Recent versions relax that check, and
	     * pretend that GPM can work with any terminal having the kmous
	     * capability.  Perhaps that works for someone.  If so, they can
	     * set the environment variable (above).
	     */
	    if (env != 0 && strstr(env, "linux") != 0) {
		result = TRUE;
	    }
	}
    }
    return result;
}
Example #19
0
File: init.c Project: hfeeki/uwsgi
void uwsgi_autoload_plugins_by_name(char *argv_zero) {

	char *plugins_requested = NULL;

	char *original_proc_name = getenv("UWSGI_ORIGINAL_PROC_NAME");
	if (!original_proc_name) {
		// here we use argv[0];
		original_proc_name = argv_zero;
		setenv("UWSGI_ORIGINAL_PROC_NAME", original_proc_name, 1);
	}
	char *p = strrchr(original_proc_name, '/');
	if (p == NULL)
		p = original_proc_name;
	p = strstr(p, "uwsgi_");
	if (p != NULL) {
		plugins_requested = strtok(uwsgi_str(p + 6), "_");
		while (plugins_requested) {
			uwsgi_log("[uwsgi] implicit plugin requested %s\n", plugins_requested);
			uwsgi_load_plugin(-1, plugins_requested, NULL);
			plugins_requested = strtok(NULL, "_");
		}
	}

	plugins_requested = getenv("UWSGI_PLUGINS");
	if (plugins_requested) {
		plugins_requested = uwsgi_concat2(plugins_requested, "");
		char *p = strtok(plugins_requested, ",");
		while (p != NULL) {
			uwsgi_load_plugin(-1, p, NULL);
			p = strtok(NULL, ",");
		}
	}

}
Example #20
0
int startChildProc(void *args)
{
    int ret = 0;
    printf("child func\n");
    envDir = getenv(ENV_DIR);
    if(!envDir)
    {
	fprintf(stderr,"Error: env variable ENV_DIR not defined exit...");
	exit(1);
    }

    ret =  setenv(ENV_NAME, envDir,1);


    chroot(envDir);
    //    ret = unshare(CLONE_FS|CLONE_NEWNET);
    //   printf("ret: %d\n",ret);

    if (mount(NULL, "/", NULL, MS_PRIVATE|MS_REC, NULL) < 0) {
	printf("mount /");
    }

    if (mount("proc", "/proc", "proc",MS_REC, NULL) < 0) {
	perror("Mount error:");
        printf("++++++mount /proc %d\n",errno);
	exit(1);
    }

    if (mount("udev", "/dev", "devtmpfs",MS_REC, NULL) < 0) {
	perror("Mount error:");
        printf("++++++mount /dev %d\n",errno);
	exit(1);
    }

    char *envExec = getenv("EXEC");
    if(!envExec)
    {
	fprintf(stderr,"Error: env variable EXEC not defined exit...");
	exit(1);
    }

    char * goToEnv = getenv("GO_TO_ENV");
    if(goToEnv)
    {
	fprintf(stderr,"=====-----try exec /bin/bash");
	char *pp[] = {"/bin/bash",NULL};
	execv(pp[0],pp);
	perror("error: ");
    }else
    {

	printf("----try exec: %s\n",envExec);
	char ** params = splitStringBy(envExec,' ',0);


	execv(params[0],params);
    }

    return 0;
}
Example #21
0
void PATHMANAGER::Init(std::ostream & info_output, std::ostream & error_output)
{
	// Figure out the user's home directory.
	const char* homedir;
#ifndef _WIN32
	if ((homedir = getenv("HOME")) == NULL)
	{
		if ((homedir = getenv("USER")) == NULL)
			if ((homedir = getenv("USERNAME")) == NULL)
				error_output << "Could not find user's home directory!" << std::endl;
		home_directory = "/home/";
	}
#else
	if ((homedir = getenv("USERPROFILE")) == NULL)
		homedir = "data";	// WIN 9x/Me
#endif
	home_directory += homedir;

	// Find data dir.
	const char * datadir = getenv("VDRIFT_DATA_DIRECTORY");
	if (datadir == NULL)
#ifndef _WIN32
		if (FileExists("data/settings/options.config"))
			data_directory = "data";
        else
			data_directory = DATA_DIR;
#else
		data_directory = "data";
#endif
        else
Example #22
0
static const char *
get_search_path(void)
{
    static const char *search_path;

    if (!search_path) {
        static char buffer[1024];
        const char *p;
        int ret;

        p = getenv("DXGI_DRIVERS_PATH");
        if(!p)
            p = getenv("EGL_DRIVERS_PATH");
#ifdef __unix__
        if (p && (geteuid() != getuid() || getegid() != getgid())) {
            p = NULL;
        }
#endif

        if (p) {
            ret = snprintf(buffer, sizeof(buffer),
                           "%s:%s", p, DXGI_DRIVER_SEARCH_DIR);
            if (ret > 0 && ret < (int)sizeof(buffer))
                search_path = buffer;
        }
    }
    if (!search_path)
        search_path = DXGI_DRIVER_SEARCH_DIR;

    return search_path;
}
Example #23
0
File: display.c Project: JakeSc/tig
void
open_editor(const char *file, unsigned int lineno)
{
    const char *editor_argv[SIZEOF_ARG + 3] = { "vi", file, NULL };
    char editor_cmd[SIZEOF_STR];
    char lineno_cmd[SIZEOF_STR];
    const char *editor;
    int argc = 0;

    editor = getenv("GIT_EDITOR");
    if (!editor && *opt_editor)
        editor = opt_editor;
    if (!editor)
        editor = getenv("VISUAL");
    if (!editor)
        editor = getenv("EDITOR");
    if (!editor)
        editor = "vi";

    string_ncopy(editor_cmd, editor, strlen(editor));
    if (!argv_from_string_no_quotes(editor_argv, &argc, editor_cmd)) {
        report("Failed to read editor command");
        return;
    }

    if (lineno && opt_editor_line_number && string_format(lineno_cmd, "+%u", lineno))
        editor_argv[argc++] = lineno_cmd;
    editor_argv[argc] = file;
    if (!open_external_viewer(editor_argv, repo.cdup, FALSE, TRUE, EDITOR_LINENO_MSG))
        opt_editor_line_number = FALSE;
}
Example #24
0
const char *R_ExpandFileName(const char *s)
{
    char *p;

    if(s[0] != '~' || (s[0] && isalpha(s[1]))) return s;
    if(HaveHOME < 0) {
	HaveHOME = 0;
	p = getenv("R_USER"); /* should be set so the rest is a safety measure */
	if(p && strlen(p) && strlen(p) < PATH_MAX) {
	    strcpy(UserHOME, p);
	    HaveHOME = 1;
	} else {
	    p = getenv("HOME");
	    if(p && strlen(p) && strlen(p) < PATH_MAX) {
		strcpy(UserHOME, p);
		HaveHOME = 1;
	    } else {
		p = getenv("HOMEDRIVE");
		if(p && strlen(p) < PATH_MAX) {
		    strcpy(UserHOME, p);
		    p = getenv("HOMEPATH");
		    if(p && strlen(UserHOME) + strlen(p) < PATH_MAX) {
			strcat(UserHOME, p);
			HaveHOME = 1;
		    }
		}
	    }
	}
    }
    if(HaveHOME > 0 && strlen(UserHOME) + strlen(s+1) < PATH_MAX) {
	strcpy(newFileName, UserHOME);
	strcat(newFileName, s+1);
	return newFileName;
    } else return s;
}
Example #25
0
// echo command implementation
void executeEcho(Cmd c)
{
	int i=1;
	if (c->args[1] != NULL){
		if (c->args[1][0] == '$'){
			char *temp = strtok(c->args[1],"$");
			char *result = getenv(temp);
			if (result != NULL)
			  printf("%s", result);
			else
		  	  printf("No such environment variable found");
		}
		else if (!strcmp(c->args[1],"~")){
			char *homeDirPath = (char *)malloc(1000);
	  		strcpy(homeDirPath, getenv("HOME"));
			printf("%s",homeDirPath);
		}
		else{
			while(c->args[i]!=NULL)
			{
				printf("%s ",c->args[i]);
				i++;	
			}
		}
	}	
	printf("\n");
}
Example #26
0
/* Module initialisation */
_kernel_oserror *mod_init(const char *tail, int podule_base, void *pw)
{
    char *ucpath;
    const char *aliases;

    UNUSED(tail);
    UNUSED(podule_base);
    UNUSED(pw);

    /* ensure the !Unicode resource exists */
#ifdef __riscos__
    ucpath = getenv("Unicode$Path");
#else
    ucpath = getenv("UNICODE_DIR");
#endif

    if (ucpath == NULL) {
        strncpy(ErrorGeneric.errmess, "!Unicode resource not found.",
                252);
        return &ErrorGeneric;
    }

    aliases = get_aliases_path();

    if (iconv_initialise(aliases) == false) {
        strncpy(ErrorGeneric.errmess, "Unicode:Files.Aliases not "
                "found. Please read the Iconv installation "
                "instructions.", 252);
        return &ErrorGeneric;
    }

    return NULL;
}
Example #27
0
MSTickerPrio __ms_get_default_prio(bool_t is_video) {
	const char *penv = NULL;
	MSTickerPrio prio;

	if (is_video) {
#ifndef MS2_WINDOWS_UNIVERSAL
		penv = getenv("MS_VIDEO_PRIO");
#endif
		if(penv && _ms_ticker_prio_from_env(penv, &prio) == 0) return prio;

#ifdef __ios
		return MS_TICKER_PRIO_HIGH;
#else
		return MS_TICKER_PRIO_NORMAL;
#endif
	} else {
#ifndef MS2_WINDOWS_UNIVERSAL
		penv = getenv("MS_AUDIO_PRIO");
#endif
		if (penv && _ms_ticker_prio_from_env(penv, &prio) == 0) return prio;

		return MS_TICKER_PRIO_HIGH;

	}
}
static int
initJanitorClient()
{    
    GVshmptr janitorShm;
    int      janitorShmFd   = atoi(getenv("GV_JANITOR_SHM_FD"));
    int      janitorShmSize = atoi(getenv("GV_JANITOR_SHM_SIZE"));
    
    TRY
    {
	if ((janitorShm = malloc(sizeof(struct GVshm))) == NULL)
	{
	    THROW(e0, "malloc");
	}

	janitorShm->id   = janitorShmFd;
	janitorShm->size = janitorShmSize;

	if ((transport
	     = gvCreateShmStreamTransport(janitorShm,
					  0,
					  janitorShmSize)) == NULL)
	{
	    THROW(e0, "gvCreateTransport");
	}

	ocLock = transport->callChanel->exclusiveAccess;
	icLock = transport->returnChanel->exclusiveAccess;
    }
    CATCH (e0)
    {
	return -1;
    }

    return 0;
}
int GL2Decoder::initGL(get_proc_func_t getProcFunc, void *getProcFuncData)
{
    if (getProcFunc == NULL) {
        const char *libname = GLES2_LIBNAME;
        if (getenv(GLES2_LIBNAME_VAR) != NULL) {
            libname = getenv(GLES2_LIBNAME_VAR);
        }

        m_GL2library = osUtils::dynLibrary::open(libname);
        if (m_GL2library == NULL) {
            fprintf(stderr, "%s: Couldn't find %s \n", __FUNCTION__, libname);
            return -1;
        }
        this->initDispatchByName(s_getProc, this);
    } else {
        this->initDispatchByName(getProcFunc, getProcFuncData);
    }

    set_glGetCompressedTextureFormats(s_glGetCompressedTextureFormats);
    set_glVertexAttribPointerData(s_glVertexAttribPointerData);
    set_glVertexAttribPointerOffset(s_glVertexAttribPointerOffset);

    set_glDrawElementsOffset(s_glDrawElementsOffset);
    set_glDrawElementsData(s_glDrawElementsData);
    set_glShaderString(s_glShaderString);
    set_glFinishRoundTrip(s_glFinishRoundTrip);
    return 0;

}
Example #30
0
const char*
anp_system_getApplicationDataDirectory(NPP instance)
{
    static const char *dir = nullptr;
    static const char *privateDir = nullptr;

    bool isPrivate = false;

    if (!dir) {
        dir = getenv("ANDROID_PLUGIN_DATADIR");
    }

    if (!privateDir) {
        privateDir = getenv("ANDROID_PLUGIN_DATADIR_PRIVATE");
    }

    if (!instance) {
        return dir;
    }

    nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
    if (pinst && NS_SUCCEEDED(pinst->IsPrivateBrowsing(&isPrivate)) && isPrivate) {
        return privateDir;
    }

    return dir;
}