tree-wide: check if return value of lseek() and friends is negative

We usually check return value of syscalls or glibc functions by it is
negative or not, something like that `if (stat(path, &st) < 0)`.
Let's also use the same style for lseek() and friends even the type of
their return value is off_t.

Note, fseeko() returns int, instead of off_t.
This commit is contained in:
Yu Watanabe
2023-10-19 18:31:44 +09:00
parent 4820c9d417
commit 86cbbc6d05
15 changed files with 23 additions and 23 deletions
+2 -2
View File
@@ -303,7 +303,7 @@ static int raw_import_open_disk(RawImport *i) {
"Target file is not a regular file or block device");
if (i->offset != UINT64_MAX) {
if (lseek(i->output_fd, i->offset, SEEK_SET) == (off_t) -1)
if (lseek(i->output_fd, i->offset, SEEK_SET) < 0)
return log_error_errno(errno, "Failed to seek to offset: %m");
}
@@ -328,7 +328,7 @@ static int raw_import_try_reflink(RawImport *i) {
return 0;
p = lseek(i->input_fd, 0, SEEK_CUR);
if (p == (off_t) -1)
if (p < 0)
return log_error_errno(errno, "Failed to read file offset of input file: %m");
/* Let's only try a btrfs reflink, if we are reading from the beginning of the file */
+1 -1
View File
@@ -415,7 +415,7 @@ static int pull_job_open_disk(PullJob *j) {
return log_error_errno(errno, "Failed to stat disk file: %m");
if (j->offset != UINT64_MAX) {
if (lseek(j->disk_fd, j->offset, SEEK_SET) == (off_t) -1)
if (lseek(j->disk_fd, j->offset, SEEK_SET) < 0)
return log_error_errno(errno, "Failed to seek on file descriptor: %m");
}
}
+1 -1
View File
@@ -370,7 +370,7 @@ static int raw_pull_make_local_copy(RawPull *i) {
assert(i->raw_job->disk_fd >= 0);
assert(i->offset == UINT64_MAX);
if (lseek(i->raw_job->disk_fd, SEEK_SET, 0) == (off_t) -1)
if (lseek(i->raw_job->disk_fd, SEEK_SET, 0) < 0)
return log_error_errno(errno, "Failed to seek to beginning of vendor image: %m");
}