X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=lib%2Fpattern.c;h=2024f2e9cf364a2828d24184eecff4e0c19c9ecc;hb=1612c4a5eea3bc09f6f94115b028320bbc32ce4b;hp=0aeb935266fa129d2995a4c49f94b0f0c76b1bc2;hpb=fada2fcd693a2c7fde5ebd36ff9255b549b102ab;p=fio.git diff --git a/lib/pattern.c b/lib/pattern.c index 0aeb9352..2024f2e9 100644 --- a/lib/pattern.c +++ b/lib/pattern.c @@ -4,11 +4,72 @@ #include #include #include +#include +#include #include "strntol.h" #include "pattern.h" #include "../minmax.h" #include "../oslib/strcasestr.h" +#include "../oslib/strndup.h" + +/** + * parse_file() - parses binary file to fill buffer + * @beg - string input, extract filename from this + * @out - output buffer where parsed number should be put + * @out_len - length of the output buffer + * @filled - pointer where number of bytes successfully + * parsed will be put + * + * Returns the end pointer where parsing has been stopped. + * In case of parsing error or lack of bytes in output buffer + * NULL will be returned. + */ +static const char *parse_file(const char *beg, char *out, + unsigned int out_len, + unsigned int *filled) +{ + const char *end; + char *file; + int fd; + ssize_t count; + + if (!out_len) + goto err_out; + + assert(*beg == '\''); + beg++; + end = strchr(beg, '\''); + if (!end) + goto err_out; + + file = strndup(beg, end - beg); + if (file == NULL) + goto err_out; + + fd = open(file, O_RDONLY); + if (fd < 0) + goto err_free_out; + + count = read(fd, out, out_len); + if (count == -1) + goto err_free_close_out; + + *filled = count; + close(fd); + free(file); + + /* Catch up quote */ + return end + 1; + +err_free_close_out: + close(fd); +err_free_out: + free(file); +err_out: + return NULL; + +} /** * parse_string() - parses string in double quotes, like "abc" @@ -271,6 +332,9 @@ int parse_and_fill_pattern(const char *in, unsigned int in_len, parsed_fmt = 0; switch (*beg) { + case '\'': + end = parse_file(beg, out, out_len, &filled); + break; case '"': end = parse_string(beg, out, out_len, &filled); break;