diff options
author | unknown <msvensson@pilot.blaudden> | 2007-02-20 18:21:14 +0100 |
---|---|---|
committer | unknown <msvensson@pilot.blaudden> | 2007-02-20 18:21:14 +0100 |
commit | da4abd2ecb8566671cb7f1fc51bf98ff4e0d0fdb (patch) | |
tree | 77ee9e3b4855dbc4963004304aa4c66045d0cd4f /client/mysqltest.c | |
parent | 485ab9a4d5329dea8cbba6de602da576b0467f7f (diff) | |
parent | f10cfb055a493def16503e90bae31ad0e3077238 (diff) | |
download | mariadb-git-da4abd2ecb8566671cb7f1fc51bf98ff4e0d0fdb.tar.gz |
Merge pilot.blaudden:/home/msvensson/mysql/mysql-4.1-maint
into pilot.blaudden:/home/msvensson/mysql/mysql-5.0-maint
client/mysqltest.c:
Auto merged
mysql-test/t/mysqltest.test:
Auto merged
Diffstat (limited to 'client/mysqltest.c')
-rw-r--r-- | client/mysqltest.c | 76 |
1 files changed, 75 insertions, 1 deletions
diff --git a/client/mysqltest.c b/client/mysqltest.c index 919f0f90e44..edcfa06359e 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -273,7 +273,7 @@ enum enum_commands { Q_DISABLE_PARSING, Q_ENABLE_PARSING, Q_REPLACE_REGEX, Q_REMOVE_FILE, Q_FILE_EXIST, Q_WRITE_FILE, Q_COPY_FILE, Q_PERL, Q_DIE, Q_EXIT, - Q_CHMOD_FILE, Q_APPEND_FILE, Q_CAT_FILE, + Q_CHMOD_FILE, Q_APPEND_FILE, Q_CAT_FILE, Q_DIFF_FILES, Q_UNKNOWN, /* Unknown command. */ Q_COMMENT, /* Comments, ignored. */ @@ -360,6 +360,7 @@ const char *command_names[]= "chmod", "append_file", "cat_file", + "diff_files", 0 }; @@ -2242,6 +2243,78 @@ void do_cat_file(struct st_command *command) } + +/* + SYNOPSIS + do_diff_files + command called command + + DESCRIPTION + diff_files <file1> <file2>; + + Fails if the two files differ. + +*/ + +void do_diff_files(struct st_command *command) +{ + int error= 0; + int fd, fd2; + uint len, len2; + char buff[512], buff2[512]; + static DYNAMIC_STRING ds_filename; + static DYNAMIC_STRING ds_filename2; + const struct command_arg diff_file_args[] = { + "file1", ARG_STRING, TRUE, &ds_filename, "First file to diff", + "file2", ARG_STRING, TRUE, &ds_filename2, "Second file to diff" + }; + DBUG_ENTER("do_diff_files"); + + check_command_args(command, + command->first_argument, + diff_file_args, + sizeof(diff_file_args)/sizeof(struct command_arg), + ' '); + + if ((fd= my_open(ds_filename.str, O_RDONLY, MYF(0))) < 0) + die("Failed to open first file %s", ds_filename.str); + if ((fd2= my_open(ds_filename2.str, O_RDONLY, MYF(0))) < 0) + { + my_close(fd, MYF(0)); + die("Failed to open second file %s", ds_filename2.str); + } + while((len= my_read(fd, (byte*)&buff, + sizeof(buff), MYF(0))) > 0) + { + if ((len2= my_read(fd2, (byte*)&buff2, + sizeof(buff2), MYF(0))) != len) + { + /* File 2 was smaller */ + error= 1; + break; + } + if ((memcmp(buff, buff2, len))) + { + /* Content of this part differed */ + error= 1; + break; + } + } + if (my_read(fd2, (byte*)&buff2, + sizeof(buff2), MYF(0)) > 0) + { + /* File 1 was smaller */ + error= 1; + } + + my_close(fd, MYF(0)); + my_close(fd2, MYF(0)); + dynstr_free(&ds_filename); + dynstr_free(&ds_filename2); + handle_command_error(command, error); + DBUG_VOID_RETURN; +} + /* SYNOPSIS do_perl @@ -6019,6 +6092,7 @@ int main(int argc, char **argv) case Q_FILE_EXIST: do_file_exist(command); break; case Q_WRITE_FILE: do_write_file(command); break; case Q_APPEND_FILE: do_append_file(command); break; + case Q_DIFF_FILES: do_diff_files(command); break; case Q_CAT_FILE: do_cat_file(command); break; case Q_COPY_FILE: do_copy_file(command); break; case Q_CHMOD_FILE: do_chmod_file(command); break; |