]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libxfs: save errno before possibly overwriting it
authorChristoph Hellwig <hch@infradead.org>
Tue, 20 Sep 2011 21:59:19 +0000 (21:59 +0000)
committerAlex Elder <aelder@sgi.com>
Wed, 21 Sep 2011 18:50:33 +0000 (13:50 -0500)
Save away errno for a later error return before possibly overwriting
it in fprintf.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Alex Elder <aelder@sgi.com>
libxfs/rdwr.c

index ec2675e22428a1ed3c408e79cdb7cfbc73514672..2c4da8c6b52df4c83128ca7db31203f8137e74be 100644 (file)
@@ -454,15 +454,17 @@ libxfs_readbufr(dev_t dev, xfs_daddr_t blkno, xfs_buf_t *bp, int len, int flags)
 {
        int     fd = libxfs_device_to_fd(dev);
        int     bytes = BBTOB(len);
+       int     error;
 
        ASSERT(BBTOB(len) <= bp->b_bcount);
 
        if (pread64(fd, bp->b_addr, bytes, LIBXFS_BBTOOFF64(blkno)) < 0) {
+               error = errno;
                fprintf(stderr, _("%s: read failed: %s\n"),
-                       progname, strerror(errno));
+                       progname, strerror(error));
                if (flags & LIBXFS_EXIT_ON_FAILURE)
                        exit(1);
-               return errno;
+               return error;
        }
 #ifdef IO_DEBUG
        printf("%lx: %s: read %u bytes, blkno=%llu(%llu), %p\n",
@@ -498,14 +500,16 @@ libxfs_writebufr(xfs_buf_t *bp)
 {
        int     sts;
        int     fd = libxfs_device_to_fd(bp->b_dev);
+       int     error;
 
        sts = pwrite64(fd, bp->b_addr, bp->b_bcount, LIBXFS_BBTOOFF64(bp->b_blkno));
        if (sts < 0) {
+               error = errno;
                fprintf(stderr, _("%s: pwrite64 failed: %s\n"),
-                       progname, strerror(errno));
+                       progname, strerror(error));
                if (bp->b_flags & LIBXFS_B_EXIT)
                        exit(1);
-               return errno;
+               return error;
        }
        else if (sts != bp->b_bcount) {
                fprintf(stderr, _("%s: error - wrote only %d of %d bytes\n"),