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:
@@ -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 */
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user