예제 #1
0
파일: rawlog.c 프로젝트: ailin-nemui/irssi
void rawlog_open(RAWLOG_REC *rawlog, const char *fname)
{
	char *path;

        g_return_if_fail(rawlog != NULL);
	g_return_if_fail(fname != NULL);

	if (rawlog->logging)
		return;

	path = convert_home(fname);
#ifdef HAVE_CAPSICUM
	rawlog->handle = capsicum_open_wrapper(path,
					       O_WRONLY | O_APPEND | O_CREAT,
					       log_file_create_mode);
#else
	rawlog->handle = open(path, O_WRONLY | O_APPEND | O_CREAT,
			      log_file_create_mode);
#endif

	g_free(path);

	if (rawlog->handle == -1) {
		g_warning("rawlog open() failed: %s", strerror(errno));
		return;
	}

	rawlog_dump(rawlog, rawlog->handle);
	rawlog->logging = TRUE;
}
예제 #2
0
파일: rawlog.c 프로젝트: ailin-nemui/irssi
void rawlog_save(RAWLOG_REC *rawlog, const char *fname)
{
	char *path, *dir;
	int f;

        dir = g_path_get_dirname(fname);
#ifdef HAVE_CAPSICUM
        capsicum_mkdir_with_parents_wrapper(dir, log_dir_create_mode);
#else
        g_mkdir_with_parents(dir, log_dir_create_mode);
#endif
        g_free(dir);

	path = convert_home(fname);
#ifdef HAVE_CAPSICUM
	f = capsicum_open_wrapper(path, O_WRONLY | O_APPEND | O_CREAT,
				  log_file_create_mode);
#else
	f = open(path, O_WRONLY | O_APPEND | O_CREAT, log_file_create_mode);
#endif
	g_free(path);

	if (f < 0) {
		g_warning("rawlog open() failed: %s", strerror(errno));
		return;
	}

	rawlog_dump(rawlog, f);
	close(f);
}
예제 #3
0
/* SYNTAX: CAT <file> */
static void cmd_cat(const char *data)
{
	char *fname, *fposstr;
	void *free_arg;
	int fpos;
	GIOChannel *handle;
	GString *buf;
	gsize tpos;
#ifdef HAVE_CAPSICUM
	int fd;
#endif

	if (!cmd_get_params(data, &free_arg, 2, &fname, &fposstr))
		return;

	fname = convert_home(fname);
	fpos = atoi(fposstr);
        cmd_params_free(free_arg);

#ifdef HAVE_CAPSICUM
	fd = capsicum_open_wrapper(fname, O_RDONLY, 0);
	if (fd > 0)
		handle = g_io_channel_unix_new(fd);
	else
		handle = NULL;
#else
	handle = g_io_channel_new_file(fname, "r", NULL);
#endif
	g_free(fname);

	if (handle == NULL) {
		/* file not found */
		printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
			  "%s", g_strerror(errno));
		return;
	}

	g_io_channel_set_encoding(handle, NULL, NULL);
	g_io_channel_seek_position(handle, fpos, G_SEEK_SET, NULL);
	buf = g_string_sized_new(512);
	while (g_io_channel_read_line_string(handle, buf, &tpos, NULL) == G_IO_STATUS_NORMAL) {
		buf->str[tpos] = '\0';
		printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP |
			  MSGLEVEL_NEVER, "%s", buf->str);
	}
	g_string_free(buf, TRUE);

	g_io_channel_unref(handle);
}