Skip to content

Use S_ISDIR()/S_ISREG() instead of S_IFDIR/S_IFREG#30

Open
cvanaret wants to merge 1 commit into
ampl:masterfrom
cvanaret:file_kind
Open

Use S_ISDIR()/S_ISREG() instead of S_IFDIR/S_IFREG#30
cvanaret wants to merge 1 commit into
ampl:masterfrom
cvanaret:file_kind

Conversation

@cvanaret

Copy link
Copy Markdown

file_kind() tests file type with the raw S_IFDIR/S_IFREG constants. On FreeBSD those constants are declared only under #if __XSI_VISIBLE in <sys/stat.h>, whereas the S_ISDIR()/S_ISREG() macros are defined unconditionally.

How to reproduce the error:

// fk.c
#include <sys/types.h>
#include <sys/stat.h>

static int file_kind(const char* name) {
    struct stat sb;
    if (stat(name,&sb)) return 0;
    if (sb.st_mode & S_IFDIR) return 2;   // raw constant
    if (sb.st_mode & S_IFREG) return 1;
    return 0;
}

int main(void) {
  return file_kind(".");
}

then:

clang -std=c99 -D_POSIX_C_SOURCE=200809L fk.c -o /dev/null
# fk.c:6:22: error: use of undeclared identifier 'S_IFDIR'
# fk.c:7:22: error: use of undeclared identifier 'S_IFREG'

See JuliaPackaging/Yggdrasil#13950

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

Successfully merging this pull request may close these issues.

1 participant