Esempio n. 1
0
FILE *open_pager(void)
{
	FILE *outfile = 0;
	const char *pager = ss_safe_getenv("DEBUGFS_PAGER");
	char buf[80];

	signal(SIGPIPE, SIG_IGN);
	if (!isatty(1))
		return stdout;
	if (!pager)
		pager = ss_safe_getenv("PAGER");
	if (!pager)
		pager = find_pager(buf);
	if (!pager ||
	    (strcmp(pager, "__none__") == 0) ||
	    ((outfile = popen(pager, "w")) == 0))
		return stdout;
	return outfile;
}
void ss_get_readline(int sci_idx)
{
#ifdef HAVE_DLOPEN
	void	*handle = NULL;
	ss_data *info = ss_info(sci_idx);
	const char **t, *libpath = 0;
	char	*tmp, *cp, *next;
	char **(**completion_func)(const char *, int, int);

	if (info->readline_handle)
		return;

	libpath = ss_safe_getenv("SS_READLINE_PATH");
	if (!libpath)
		libpath = DEFAULT_LIBPATH;
	if (*libpath == 0 || !strcmp(libpath, "none"))
		return;

	tmp = malloc(strlen(libpath)+1);
	if (!tmp)
		return;
	strcpy(tmp, libpath);
	for (cp = tmp; cp; cp = next) {
		next = strchr(cp, ':');
		if (next)
			*next++ = 0;
		if (*cp == 0)
			continue;
		if ((handle = dlopen(cp, RTLD_NOW))) {
			/* printf("Using %s for readline library\n", cp); */
			break;
		}
	}
	free(tmp);
	if (!handle)
		return;

	info->readline_handle = handle;
	info->readline = (char *(*)(const char *))
		dlsym(handle, "readline");
	info->add_history = (void (*)(const char *))
		dlsym(handle, "add_history");
	info->redisplay = (void (*)(void))
		dlsym(handle, "rl_forced_update_display");
	info->rl_completion_matches = (char **(*)(const char *,
				    char *(*)(const char *, int)))
		dlsym(handle, "rl_completion_matches");
	if ((t = dlsym(handle, "rl_readline_name")) != NULL)
		*t = info->subsystem_name;
	if ((completion_func =
	     dlsym(handle, "rl_attempted_completion_function")) != NULL)
		*completion_func = ss_rl_completion;
	info->readline_shutdown = ss_release_readline;
#endif
}
Esempio n. 3
0
/*
 * This function takes a __u32 time value and converts it to a string,
 * using ctime
 */
char *time_to_string(__u32 cl)
{
	static int	do_gmt = -1;
	time_t		t = (time_t) cl;
	const char	*tz;

	if (do_gmt == -1) {
		/* The diet libc doesn't respect the TZ environemnt variable */
		tz = ss_safe_getenv("TZ");
		if (!tz)
			tz = "";
		do_gmt = !strcmp(tz, "GMT") | !strcmp(tz, "GMT0");
	}

	return asctime((do_gmt) ? gmtime(&t) : localtime(&t));
}