summaryrefslogtreecommitdiff
path: root/src/fe-common/core/fe-core-commands.c
diff options
context:
space:
mode:
authorEmanuele Giaquinta <exg@irssi.org>2008-03-09 11:08:44 +0000
committerexg <exg@dbcabf3a-b0e7-0310-adc4-f8d773084564>2008-03-09 11:08:44 +0000
commita3021ccf5f41890e4204e413c76843c324752419 (patch)
treeef7db22b84be1a8195fa5a8bc2d6b0921a3cbb34 /src/fe-common/core/fe-core-commands.c
parent2b0ebef9112d1546672722d1f559cfccb867f191 (diff)
downloadirssi-a3021ccf5f41890e4204e413c76843c324752419.zip
Use GIOChannel API to read a file linewise.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@4736 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/fe-common/core/fe-core-commands.c')
-rw-r--r--src/fe-common/core/fe-core-commands.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/fe-common/core/fe-core-commands.c b/src/fe-common/core/fe-core-commands.c
index e20254ba..33c9d8aa 100644
--- a/src/fe-common/core/fe-core-commands.c
+++ b/src/fe-common/core/fe-core-commands.c
@@ -25,7 +25,6 @@
#include "commands.h"
#include "levels.h"
#include "misc.h"
-#include "line-split.h"
#include "settings.h"
#include "irssi-version.h"
#include "servers.h"
@@ -114,11 +113,12 @@ static void cmd_version(char *data)
/* SYNTAX: CAT <file> */
static void cmd_cat(const char *data)
{
- LINEBUF_REC *buffer = NULL;
char *fname, *fposstr;
- char tmpbuf[1024], *str;
void *free_arg;
- int f, ret, recvlen, fpos;
+ int fpos;
+ GIOChannel *handle;
+ GString *buf;
+ gsize tpos;
if (!cmd_get_params(data, &free_arg, 2, &fname, &fposstr))
return;
@@ -127,29 +127,26 @@ static void cmd_cat(const char *data)
fpos = atoi(fposstr);
cmd_params_free(free_arg);
- f = open(fname, O_RDONLY);
+ handle = g_io_channel_new_file(fname, "r", NULL);
g_free(fname);
- if (f == -1) {
+ if (handle == NULL) {
/* file not found */
printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
"%s", g_strerror(errno));
return;
}
- lseek(f, fpos, SEEK_SET);
- do {
- recvlen = read(f, tmpbuf, sizeof(tmpbuf));
-
- ret = line_split(tmpbuf, recvlen, &str, &buffer);
- if (ret > 0) {
+ 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", str);
+ MSGLEVEL_NEVER, "%s", buf->str);
}
- } while (ret > 0);
- line_split_free(buffer);
+ g_string_free(buf, TRUE);
- close(f);
+ g_io_channel_close(handle);
}
/* SYNTAX: BEEP */