S_ISREG macro undefined

前端 未结 4 1962
眼角桃花
眼角桃花 2021-01-05 02:40

Questions

  • Are the posix macros S_ISREG, S_ISDIR etc linux only? I need to find out because i am trying to compile CURL and it is trying to use them on windows
  • Wh
相关标签:
4条回答
  • 2021-01-05 02:55

    Currently curl 7.21.5 defines in setup.h this:

    #if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
    #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
    #endif
    
    0 讨论(0)
  • 2021-01-05 03:04

    No such thing on windows, you can use the FindFirstFile, FindNextFile win32 api, the return structure contains something similar but not the same.

    If you use gcc/mingw library they have a stat() simulation. You need to include sys/stat.h for that macro.

    0 讨论(0)
  • 2021-01-05 03:10

    On windows try adding the underscore (_S_ISREG). In MinGW's lib the S_ISREG macro is also accessible in <sys/stat.h>

    Maybe you should just check your configuration macros.

    0 讨论(0)
  • 2021-01-05 03:10

    After having inspected Microsoft's sys/stat.h, I found that the following modification of @OliverZendel's answer worked for me, with Visual Studio 2017, and hopefully on other compilers as well:

    // Windows does not define the S_ISREG and S_ISDIR macros in stat.h, so we do.
    // We have to define _CRT_INTERNAL_NONSTDC_NAMES 1 before #including sys/stat.h
    // in order for Microsoft's stat.h to define names like S_IFMT, S_IFREG, and S_IFDIR,
    // rather than just defining  _S_IFMT, _S_IFREG, and _S_IFDIR as it normally does.
    #define _CRT_INTERNAL_NONSTDC_NAMES 1
    #include <sys/stat.h>
    #if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
      #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
    #endif
    #if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR)
      #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
    #endif
    
    0 讨论(0)
提交回复
热议问题