Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(test suite) stat: illegal option -- c #710

Open
ryandesign opened this issue Apr 5, 2024 · 2 comments
Open

(test suite) stat: illegal option -- c #710

ryandesign opened this issue Apr 5, 2024 · 2 comments

Comments

@ryandesign
Copy link
Contributor

When running regress/runtests on macOS, this error occurs in one test:

Testing github-#0337: stat: illegal option -- c
usage: stat [-FLnq] [-f format | -l | -r | -s | -x] [-t timefmt] [file ...]
failed (on bad-EOF bad-len)

It's happening on this line:

size=`stat -c%s $1`

The -c flag is unique to the GNU flavor of stat and is not available in the BSD flavor of stat that is used on BSD-derived operating systems like macOS.

The BSD stat equivalent of the GNU -c%s is -f%z.

I'm not sure if there's a more portable way of discovering a file's size. If not, I'm not sure of the best way to distinguish BSD stat from GNU stat so that the right command could be used.

@ryandesign
Copy link
Contributor Author

Looks like there is a second occurrence of this code:

size=`stat -c%s $1`

@wdoekes
Copy link
Member

wdoekes commented Apr 29, 2024

I suppose one could write a stat wrapper:

get_filesize() {
    local f v
    f="$1"
    # GNU stat
    if v=$(stat -c%s "$f" 2>/dev/null) && echo "$v" | grep -q '^[0-9]\+$'; then
        echo "$v"
        return
    fi
    # BSD stat
    stat -f%z "$f"
}

Would you like to create a PR?

@wdoekes wdoekes changed the title stat: illegal option -- c (test suite) stat: illegal option -- c Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants