]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: (helper) add "offset" parameter to ro-regular-file factory
authorMasatake YAMATO <yamato@redhat.com>
Thu, 14 Oct 2021 13:51:49 +0000 (22:51 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Thu, 21 Oct 2021 12:06:39 +0000 (21:06 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
tests/helpers/test_mkfds.c

index d318aff2b8c044c730ef5b519a5f09221fbbdc84..c5d67a0113322e50d95440a38d22d87e69583dda 100644 (file)
@@ -222,12 +222,23 @@ static void open_ro_regular_file(const struct factory *factory, struct fdesc fde
                                 int argc, char ** argv)
 {
        struct arg file = decode_arg("file", factory->params, argc, argv);
+       struct arg offset = decode_arg("offset", factory->params, argc, argv);
 
        int fd = open(ARG_STRING(file), O_RDONLY);
        if (fd < 0)
                err(EXIT_FAILURE, "failed to open: %s", ARG_STRING(file));
        free_arg(&file);
 
+       if (ARG_INTEGER(offset) != 0) {
+               if (lseek(fd, (off_t)ARG_INTEGER(offset), SEEK_CUR) < 0) {
+                       int e = errno;
+                       close(fd);
+                       errno = e;
+                       err(EXIT_FAILURE, "failed to seek 0 -> %ld", ARG_INTEGER(offset));
+               }
+       }
+       free_arg(&offset);
+
        if (dup2(fd, fdescs[0].fd) < 0) {
                int e = errno;
                close(fd);
@@ -305,6 +316,12 @@ static const struct factory factories[] = {
                                .desc = "file to be opened",
                                .defv.string = "/etc/passwd",
                        },
+                       {
+                               .name = "offset",
+                               .type = PTYPE_INTEGER,
+                               .desc = "seek bytes after open with SEEK_CUR",
+                               .defv.integer = 0,
+                       },
                        PARAM_END
                },
        },