From 05374a6eded63894263a27886ef19056362967be Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 6 Mar 2019 23:49:10 -0800 Subject: libfile: Make failure path of open_and_lseek() consistent Change the code of open_and_lseek() to make sure that opened file is closed in every failure path as well. While at it make sure we don't mix returning function return code and returning errno by opting to always return the former. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- lib/libfile.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/libfile.c b/lib/libfile.c index 9a223d2328..089749253d 100644 --- a/lib/libfile.c +++ b/lib/libfile.c @@ -522,12 +522,12 @@ err_out1: * @mode: The file open mode * @pos: The position to lseek to * - * Return: If successful this function returns a positive filedescriptor - * number, otherwise a negative error code is returned + * Return: If successful this function returns a positive + * filedescriptor number, otherwise -1 is returned */ int open_and_lseek(const char *filename, int mode, loff_t pos) { - int fd, ret; + int fd; fd = open(filename, mode); if (fd < 0) { @@ -541,28 +541,26 @@ int open_and_lseek(const char *filename, int mode, loff_t pos) if (mode & (O_WRONLY | O_RDWR)) { struct stat s; - ret = fstat(fd, &s); - if (ret) { + if (fstat(fd, &s)) { perror("fstat"); - return ret; + goto out; } - if (s.st_size < pos) { - ret = ftruncate(fd, pos); - if (ret) { - perror("ftruncate"); - return ret; - } + if (s.st_size < pos && ftruncate(fd, pos)) { + perror("ftruncate"); + goto out; } } if (lseek(fd, pos, SEEK_SET) != pos) { perror("lseek"); - close(fd); - return -errno; + goto out; } return fd; +out: + close(fd); + return -1; } /** -- cgit v1.2.3 From 7c293700db4d1b14ba55bc221af9afc0ed233f01 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 6 Mar 2019 23:49:11 -0800 Subject: common: Always return enum filetype in file_name_detect_type_offset() None of the callers of file_name_detect_type_offset() are prepared to deal with negative error code. Change the code to return filetype_unknown if open_and_lseek() fails. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- common/filetype.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/filetype.c b/common/filetype.c index f8b6bc8954..fb029a7739 100644 --- a/common/filetype.c +++ b/common/filetype.c @@ -383,7 +383,7 @@ enum filetype file_name_detect_type_offset(const char *filename, loff_t pos) fd = open_and_lseek(filename, O_RDONLY, pos); if (fd < 0) - return fd; + goto out; buf = xzalloc(FILE_TYPE_SAFE_BUFSIZE); @@ -396,7 +396,7 @@ enum filetype file_name_detect_type_offset(const char *filename, loff_t pos) err_out: close(fd); free(buf); - +out: return type; } -- cgit v1.2.3 From 6bc098928799009119a6de3d8190329945283bae Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 6 Mar 2019 23:49:12 -0800 Subject: MIPS: ath79: Use errno to get error code from open_and_lseek() Open_and_lseek() return actual error code via errno, so change the code to use it instead of return value. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- arch/mips/mach-ath79/art.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/mips/mach-ath79/art.c b/arch/mips/mach-ath79/art.c index 984d087363..2a2099e9f5 100644 --- a/arch/mips/mach-ath79/art.c +++ b/arch/mips/mach-ath79/art.c @@ -44,8 +44,8 @@ static int art_read_mac(struct device_d *dev, const char *file) fd = open_and_lseek(file, O_RDONLY, AR93000_EPPROM_OFFSET); if (fd < 0) { dev_err(dev, "Failed to open eeprom path %s %d\n", - file, fd); - return fd; + file, -errno); + return -errno; } rbytes = read_full(fd, &eeprom, sizeof(eeprom)); -- cgit v1.2.3 From 98ceb5ff9198d47b5f20762feeea482bc945d747 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 6 Mar 2019 23:49:13 -0800 Subject: ARM: i.MX: bbu: Fix variable type in imx_bbu_external_nand_update() MEMGETBADBLOCK returns loff_t, so that's the type we should use to store its result. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- arch/arm/mach-imx/imx-bbu-external-nand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/mach-imx/imx-bbu-external-nand.c b/arch/arm/mach-imx/imx-bbu-external-nand.c index 52622ac4cb..440785ab7a 100644 --- a/arch/arm/mach-imx/imx-bbu-external-nand.c +++ b/arch/arm/mach-imx/imx-bbu-external-nand.c @@ -40,7 +40,7 @@ static int imx_bbu_external_nand_update(struct bbu_handler *handler, struct bbu_ int size_available, size_need; int ret; uint32_t num_bb = 0, bbt = 0; - uint64_t offset = 0; + loff_t offset = 0; int block = 0, len, now, blocksize; void *image = data->image; -- cgit v1.2.3 From 935beb58ca8d00560ee5318532e5b08127ba8b48 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 6 Mar 2019 23:49:14 -0800 Subject: ARM: i.MX: bbu: Fix lseek error check in imx_bbu_external_nand_update() Don't use 'int' to store lseek()'s return value to avoid problems with large seek offsets. While at it, make sure to populate return error code from 'errno'. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- arch/arm/mach-imx/imx-bbu-external-nand.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/arm/mach-imx/imx-bbu-external-nand.c b/arch/arm/mach-imx/imx-bbu-external-nand.c index 440785ab7a..fa43d2e8dc 100644 --- a/arch/arm/mach-imx/imx-bbu-external-nand.c +++ b/arch/arm/mach-imx/imx-bbu-external-nand.c @@ -147,10 +147,12 @@ static int imx_bbu_external_nand_update(struct bbu_handler *handler, struct bbu_ goto out; if (ret) { - ret = lseek(fd, offset + blocksize, SEEK_SET); - if (ret < 0) - goto out; offset += blocksize; + if (lseek(fd, offset, SEEK_SET) != offset) { + ret = -errno; + goto out; + } + continue; } -- cgit v1.2.3 From 8336f77c0bbe60a3cc4abf759fcba75475bae8f2 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 6 Mar 2019 23:49:15 -0800 Subject: ARM: i.MX: bbu: Fix lseek error check in imx_bbu_internal_v2_write_nand_dbbt() Don't use 'int' to store lseek()'s return value to avoid problems with large seek offsets. While at it, make sure to populate return error code from 'errno'. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- arch/arm/mach-imx/imx-bbu-internal.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/arm/mach-imx/imx-bbu-internal.c b/arch/arm/mach-imx/imx-bbu-internal.c index 188369fe34..1104303ff0 100644 --- a/arch/arm/mach-imx/imx-bbu-internal.c +++ b/arch/arm/mach-imx/imx-bbu-internal.c @@ -330,10 +330,12 @@ static int imx_bbu_internal_v2_write_nand_dbbt(struct imx_internal_bbu_handler * goto out; if (ret) { - ret = lseek(fd, offset + blocksize, SEEK_SET); - if (ret < 0) - goto out; offset += blocksize; + if (lseek(fd, offset, SEEK_SET) != offset) { + ret = -errno; + goto out; + } + continue; } -- cgit v1.2.3 From 41a5d444411b4f0dd7148b77a9533a5fdb4b5636 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 6 Mar 2019 23:49:16 -0800 Subject: ARM: i.MX: bbu: Fix variable type in imx_bbu_internal_v2_write_nand_dbbt() MEMGETBADBLOCK returns loff_t, so that's the type we should use to store its result. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- arch/arm/mach-imx/imx-bbu-internal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/mach-imx/imx-bbu-internal.c b/arch/arm/mach-imx/imx-bbu-internal.c index 1104303ff0..a563b3bc29 100644 --- a/arch/arm/mach-imx/imx-bbu-internal.c +++ b/arch/arm/mach-imx/imx-bbu-internal.c @@ -207,7 +207,7 @@ static int imx_bbu_internal_v2_write_nand_dbbt(struct imx_internal_bbu_handler * int size_available, size_need; int ret; uint32_t *ptr, *num_bb, *bb; - uint64_t offset; + loff_t offset; int block = 0, len, now, blocksize; int dbbt_start_page = 4; int firmware_start_page = 12; -- cgit v1.2.3 From cf6e01e07f0eb838c1a08756bd3cc575221d7730 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 6 Mar 2019 23:49:17 -0800 Subject: bpkfs: Fix lseek error check in bpkfs_probe() Don't use 'int' to store lseek()'s return value to avoid problems with large seek offsets. While at it, make sure to populate return error code from 'errno'. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- fs/bpkfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/bpkfs.c b/fs/bpkfs.c index 655cde09b7..90d3a6bf1b 100644 --- a/fs/bpkfs.c +++ b/fs/bpkfs.c @@ -455,9 +455,9 @@ static int bpkfs_probe(struct device_d *dev) list_add_tail(&d->list, &h->list_data); priv->nb_data_entries++; - ret = lseek(fd, d->size, SEEK_CUR); - if (ret < 0) { + if (lseek(fd, d->size, SEEK_CUR) != d->size) { dev_err(dev, "could not seek: %s\n", errno_str()); + ret = -errno; goto err; } -- cgit v1.2.3 From eae44ac6322312732a27e57d3cbfb78c5f2e13cc Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 6 Mar 2019 23:49:18 -0800 Subject: uimage: Fix lseek error check in uimage_verify() Don't use 'int' to store lseek()'s return value to avoid problems with large seek offsets. While at it, make sure to populate return error code from 'errno'. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- common/uimage.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/common/uimage.c b/common/uimage.c index 3273bc1871..72b668e898 100644 --- a/common/uimage.c +++ b/common/uimage.c @@ -265,11 +265,12 @@ int uimage_verify(struct uimage_handle *handle) { u32 crc = 0; int len, ret; + loff_t off; void *buf; - ret = lseek(handle->fd, sizeof(struct image_header), SEEK_SET); - if (ret < 0) - return ret; + off = sizeof(struct image_header); + if (lseek(handle->fd, off, SEEK_SET) != off) + return -errno; buf = xmalloc(PAGE_SIZE); -- cgit v1.2.3 From cb4b3d397361e04a5de1da71e84522f6bfba11ba Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 6 Mar 2019 23:49:19 -0800 Subject: uimage: Fix lseek error check in uimage_load() Don't use 'int' to store lseek()'s return value to avoid problems with large seek offsets. While at it, make sure to populate return error code from 'errno'. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- common/uimage.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/uimage.c b/common/uimage.c index 72b668e898..12c7e9e2c1 100644 --- a/common/uimage.c +++ b/common/uimage.c @@ -308,6 +308,7 @@ int uimage_load(struct uimage_handle *handle, unsigned int image_no, image_header_t *hdr = &handle->header; struct uimage_handle_data *iha; int ret; + loff_t off; int (*uncompress_fn)(unsigned char *inbuf, int len, int(*fill)(void*, unsigned int), int(*flush)(void*, unsigned int), @@ -320,10 +321,9 @@ int uimage_load(struct uimage_handle *handle, unsigned int image_no, iha = &handle->ihd[image_no]; - ret = lseek(handle->fd, iha->offset + handle->data_offset, - SEEK_SET); - if (ret < 0) - return ret; + off = iha->offset + handle->data_offset; + if (lseek(handle->fd, off, SEEK_SET) != off) + return -errno; /* if ramdisk U-Boot expect to ignore the compression type */ if (hdr->ih_comp == IH_COMP_NONE || hdr->ih_type == IH_TYPE_RAMDISK) -- cgit v1.2.3 From 7af10336201f9d458a4f7baefec4d0d8a8c60141 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 6 Mar 2019 23:49:20 -0800 Subject: uimage: Fix lseek error check in uimage_load_to_buf() Don't use 'int' to store lseek()'s return value to avoid problems with large seek offsets. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- common/uimage.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/common/uimage.c b/common/uimage.c index 12c7e9e2c1..35bfb10b06 100644 --- a/common/uimage.c +++ b/common/uimage.c @@ -457,6 +457,7 @@ void *uimage_load_to_buf(struct uimage_handle *handle, int image_no, { u32 size; int ret; + loff_t off; struct uimage_handle_data *ihd; char ftbuf[128]; enum filetype ft; @@ -467,9 +468,8 @@ void *uimage_load_to_buf(struct uimage_handle *handle, int image_no, ihd = &handle->ihd[image_no]; - ret = lseek(handle->fd, ihd->offset + handle->data_offset, - SEEK_SET); - if (ret < 0) + off = ihd->offset + handle->data_offset; + if (lseek(handle->fd, off, SEEK_SET) != off) return NULL; if (handle->header.ih_comp == IH_COMP_NONE) { @@ -497,10 +497,8 @@ void *uimage_load_to_buf(struct uimage_handle *handle, int image_no, if (ft != filetype_gzip) return NULL; - ret = lseek(handle->fd, ihd->offset + handle->data_offset + - ihd->len - 4, - SEEK_SET); - if (ret < 0) + off = ihd->offset + handle->data_offset + ihd->len - 4; + if (lseek(handle->fd, off, SEEK_SET) != off) return NULL; ret = read(handle->fd, &size, 4); @@ -509,9 +507,8 @@ void *uimage_load_to_buf(struct uimage_handle *handle, int image_no, size = le32_to_cpu(size); - ret = lseek(handle->fd, ihd->offset + handle->data_offset, - SEEK_SET); - if (ret < 0) + off = ihd->offset + handle->data_offset; + if (lseek(handle->fd, off, SEEK_SET) != off) return NULL; buf = malloc(size); -- cgit v1.2.3 From 219b954a11e82afbbd7b6ef13d8c5ba94a5b0ff3 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 6 Mar 2019 23:49:21 -0800 Subject: state: Fix lseek error check in state_backend_bucket_direct_read() Don't use 'int' to store lseek()'s return value to avoid problems with large seek offsets. While at it, make sure to populate return error code from 'errno'. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- common/state/backend_bucket_direct.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/common/state/backend_bucket_direct.c b/common/state/backend_bucket_direct.c index 1f00b0fb2f..1524312146 100644 --- a/common/state/backend_bucket_direct.c +++ b/common/state/backend_bucket_direct.c @@ -56,10 +56,9 @@ static int state_backend_bucket_direct_read(struct state_backend_storage_bucket void *buf; int ret; - ret = lseek(direct->fd, direct->offset, SEEK_SET); - if (ret < 0) { - dev_err(direct->dev, "Failed to seek file, %d\n", ret); - return ret; + if (lseek(direct->fd, direct->offset, SEEK_SET) != direct->offset) { + dev_err(direct->dev, "Failed to seek file, %d\n", -errno); + return -errno; } ret = read_full(direct->fd, &meta, sizeof(meta)); if (ret < 0) { @@ -77,10 +76,11 @@ static int state_backend_bucket_direct_read(struct state_backend_storage_bucket return -EINVAL; } read_len = direct->max_size; - ret = lseek(direct->fd, direct->offset, SEEK_SET); - if (ret < 0) { - dev_err(direct->dev, "Failed to seek file, %d\n", ret); - return ret; + if (lseek(direct->fd, direct->offset, SEEK_SET) != + direct->offset) { + dev_err(direct->dev, "Failed to seek file, %d\n", + -errno); + return -errno; } } -- cgit v1.2.3 From ec25ecfbcb47cb83b310b9e177a5b65de3781dec Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 6 Mar 2019 23:49:22 -0800 Subject: state: Fix lseek error check in state_backend_bucket_direct_write() Don't use 'int' to store lseek()'s return value to avoid problems with large seek offsets. While at it, make sure to populate return error code from 'errno'. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- common/state/backend_bucket_direct.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/common/state/backend_bucket_direct.c b/common/state/backend_bucket_direct.c index 1524312146..95ddb93106 100644 --- a/common/state/backend_bucket_direct.c +++ b/common/state/backend_bucket_direct.c @@ -113,10 +113,9 @@ static int state_backend_bucket_direct_write(struct state_backend_storage_bucket if (len > direct->max_size - sizeof(meta)) return -E2BIG; - ret = lseek(direct->fd, direct->offset, SEEK_SET); - if (ret < 0) { - dev_err(direct->dev, "Failed to seek file, %d\n", ret); - return ret; + if (lseek(direct->fd, direct->offset, SEEK_SET) != direct->offset) { + dev_err(direct->dev, "Failed to seek file, %d\n", -errno); + return -errno; } /* write the meta data only if there is head room */ -- cgit v1.2.3 From 8a6a9fbcecffab1b076edfad94d4f32bb2cc9435 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 6 Mar 2019 23:49:23 -0800 Subject: state: Fix lseek error check in state_mtd_peb_read() Don't use 'int' to store lseek()'s return value to avoid problems with large seek offsets. While at it, make sure to populate return error code from 'errno'. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- common/state/backend_bucket_circular.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/common/state/backend_bucket_circular.c b/common/state/backend_bucket_circular.c index da7c8421ae..791f39b9b6 100644 --- a/common/state/backend_bucket_circular.c +++ b/common/state/backend_bucket_circular.c @@ -162,11 +162,10 @@ static int state_mtd_peb_read(struct state_backend_storage_bucket_circular *circ offset += (off_t)circ->eraseblock * circ->mtd->erasesize; - ret = lseek(circ->fd, offset, SEEK_SET); - if (ret < 0) { + if (lseek(circ->fd, offset, SEEK_SET) != offset) { dev_err(circ->dev, "Failed to set circular read position to %lld, %d\n", - (long long) offset, ret); - return ret; + (long long) offset, -errno); + return -errno; } dev_dbg(circ->dev, "Read state from %lld length %d\n", (long long) offset, -- cgit v1.2.3 From 5eadd11d4795afb6b521b5c3249c6341c0be7117 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 6 Mar 2019 23:49:24 -0800 Subject: state: Fix lseek error check in state_mtd_peb_write() Don't use 'int' to store lseek()'s return value to avoid problems with large seek offsets. While at it, make sure to populate return error code from 'errno'. Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- common/state/backend_bucket_circular.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/common/state/backend_bucket_circular.c b/common/state/backend_bucket_circular.c index 791f39b9b6..4676730d05 100644 --- a/common/state/backend_bucket_circular.c +++ b/common/state/backend_bucket_circular.c @@ -190,11 +190,10 @@ static int state_mtd_peb_write(struct state_backend_storage_bucket_circular *cir offset += circ->eraseblock * circ->mtd->erasesize; - ret = lseek(circ->fd, offset, SEEK_SET); - if (ret < 0) { + if (lseek(circ->fd, offset, SEEK_SET) != offset) { dev_err(circ->dev, "Failed to set position for circular write %lld, %d\n", - (long long) offset, ret); - return ret; + (long long) offset, -errno); + return -errno; } ret = write_full(circ->fd, buf, len); -- cgit v1.2.3 From 64ecfeb65e49bddf5605328bc9da3980137acf23 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 6 Mar 2019 23:49:25 -0800 Subject: commands: loadxy: Make use of open_and_lseek() Save a bit of extra code by replacing explict calls to open() and lseek() with a single call to open_and_lseek(). Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- commands/loadxy.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/commands/loadxy.c b/commands/loadxy.c index 2bfe482fc5..85efad67c7 100644 --- a/commands/loadxy.c +++ b/commands/loadxy.c @@ -37,6 +37,7 @@ #include #include #include +#include #define DEF_FILE "image.bin" @@ -176,21 +177,11 @@ static int do_loadx(int argc, char *argv[]) output_file = DEF_FILE; /* File should exist */ - ofd = open(output_file, O_WRONLY | O_CREAT); + ofd = open_and_lseek(output_file, O_WRONLY | O_CREAT, offset); if (ofd < 0) { perror(argv[0]); return 3; } - /* Seek to the right offset */ - if (offset) { - int seek = lseek(ofd, offset, SEEK_SET); - if (seek != offset) { - close(ofd); - ofd = 0; - perror(argv[0]); - return 4; - } - } current_baudrate = console_get_baudrate(cdev); -- cgit v1.2.3 From 14ad13bfc3e83e7b9befb78b837d28427d8eacdf Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 6 Mar 2019 23:49:26 -0800 Subject: commands: loadb: Make use of open_and_lseek() Save a bit of extra code by replacing explict calls to open() and lseek() with a single call to open_and_lseek(). Signed-off-by: Andrey Smirnov Signed-off-by: Sascha Hauer --- commands/loadb.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/commands/loadb.c b/commands/loadb.c index 8c3906ca42..37c272f6c7 100644 --- a/commands/loadb.c +++ b/commands/loadb.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -661,21 +662,11 @@ static int do_load_serial_bin(int argc, char *argv[]) output_file = DEF_FILE; /* File should exist */ - ofd = open(output_file, O_WRONLY | O_CREAT); + ofd = open_and_lseek(output_file, O_WRONLY | O_CREAT, offset); if (ofd < 0) { perror(argv[0]); return 3; } - /* Seek to the right offset */ - if (offset) { - int seek = lseek(ofd, offset, SEEK_SET); - if (seek != offset) { - close(ofd); - ofd = 0; - perror(argv[0]); - return 4; - } - } printf("## Ready for binary (kermit) download " "to 0x%08lX offset on %s device at %d bps...\n", offset, -- cgit v1.2.3