diff options
author | unknown <msvensson@pilot.blaudden> | 2007-02-20 14:20:49 +0100 |
---|---|---|
committer | unknown <msvensson@pilot.blaudden> | 2007-02-20 14:20:49 +0100 |
commit | 1009e0d3044c77512908f14633349c143d4093ca (patch) | |
tree | c6af5aae3e09e9d6e6bbd9f4e167e4441620e1c6 /client/mysqltest.c | |
parent | ca9944090771fb4a260d5ae5a222c11d4b48ab8c (diff) | |
download | mariadb-git-1009e0d3044c77512908f14633349c143d4093ca.tar.gz |
New version of 'do_cat_file' that will trim cr/lf to lf
Diffstat (limited to 'client/mysqltest.c')
-rw-r--r-- | client/mysqltest.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/client/mysqltest.c b/client/mysqltest.c index e1d793028a7..1a8e14a7244 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -2178,7 +2178,7 @@ void do_cat_file(struct st_command *command) { int fd; uint len; - byte buff[512]; + char buff[512]; static DYNAMIC_STRING ds_filename; const struct command_arg cat_file_args[] = { "filename", ARG_STRING, TRUE, &ds_filename, "File to read from" @@ -2195,10 +2195,27 @@ void do_cat_file(struct st_command *command) if ((fd= my_open(ds_filename.str, O_RDONLY, MYF(0))) < 0) die("Failed to open file %s", ds_filename.str); - while((len= my_read(fd, &buff, + while((len= my_read(fd, (byte*)&buff, sizeof(buff), MYF(0))) > 0) { - dynstr_append_mem(&ds_res, buff, len); + char *p= buff, *start= buff; + while (p < buff+len) + { + /* Convert cr/lf to lf */ + if (*p == '\r' && *(p+1) && *(p+1)== '\n') + { + /* Add fake newline instead of cr and output the line */ + *p= '\n'; + p++; /* Step past the "fake" newline */ + dynstr_append_mem(&ds_res, start, p-start); + p++; /* Step past the "fake" newline */ + start= p; + } + else + p++; + } + /* Output any chars that migh be left */ + dynstr_append_mem(&ds_res, start, p-start); } my_close(fd, MYF(0)); dynstr_free(&ds_filename); |