Project

General

Profile

Actions

Bug #12768

closed

12392 regressed ftello64 behavior

Added by Robert Mustacchi over 1 year ago. Updated over 1 year ago.

Status:
Closed
Priority:
High
Category:
lib - userland libraries
Start date:
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:

Description

In 12392 I refactored a bit of the way that the ftell code was implemented to try and centralize that. Unfortunately, while doing this a cast was left behind with the old return type. This resulted in truncation of the return value from the off64_t to a long. While in the 32-bit and 64-bit environments the types are the same; however, in lf64 environment that's no longer the case. An example that generates this is:

#include <stdio.h>
#include <err.h>

int
main(int argc, const char *argv[])
{
        FILE *f;
        off_t o;

        if (argc != 2) {
                (void) fprintf(stderr, "give me a path\n");
                return (1);
        }

        f = fopen(argv[1], "r+");
        if (f == NULL) {
                err(1, "failed to open %s\n", argv[1]);
        }

        if (fseeko(f, 0, SEEK_END) != 0) {
                err(1, "failed to see to end\n");
        }

        o = ftello(f);
        if (o == -1) {
                warn("ftell failed");
        } else {
                printf("ftell returned %llx\n", (long long)o);
        }

        return (0);
}

If compiled with lfs flags and run against a sparse file, you'll see that we get the wrong behavior:

rm@beowulf:~/ftell$ ./ftell.lfs ftell.3g
ftell returned ffffffffc0000000
rm@beowulf:~/ftell$ ./ftell.lfs ftell.5g 
ftell returned 40000000

Instead if you run this with a 64-bit file or with the fixed libc you'll see:

rm@beowulf:~/ftell$ ./ftell.lfs ./ftell.3g 
ftell returned c0000000
rm@beowulf:~/ftell$ ./ftell.lfs ./ftell.5g 
ftell returned 140000000

Related issues

Related to illumos gate - Bug #12392: ftello64 doesn't handle ungetc() correctly when unbufferedClosedRobert Mustacchi

Actions
Actions

Also available in: Atom PDF