From adba68c72478014b4e33ac762d08068c1485f065 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Sat, 2 Mar 2013 17:38:51 -0500 Subject: [PATCH] use finder info to check binary files (linkiigs errors) --- mpw/mpw_access.cpp | 5 +++-- toolbox/os.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/mpw/mpw_access.cpp b/mpw/mpw_access.cpp index 22d938c..d97b9f6 100644 --- a/mpw/mpw_access.cpp +++ b/mpw/mpw_access.cpp @@ -97,8 +97,9 @@ namespace MPW // adjust the binary flags... - // most apps are good about this but dumpobj doesn't set O_BINARY (but should) - // and MPW Assembler sets O_BINARY (but shouldn't) + // some apps are good about this but + // dumpobj, makelib, linkiigs don't set O_BINARY (but should) + // MPW Assembler sets O_BINARY (but shouldn't) if (OS::IsTextFile(sname)) f.flags &= ~kO_BINARY; if (OS::IsBinaryFile(sname)) f.flags |= kO_BINARY; diff --git a/toolbox/os.cpp b/toolbox/os.cpp index 9bd54e2..c047f39 100644 --- a/toolbox/os.cpp +++ b/toolbox/os.cpp @@ -174,12 +174,43 @@ namespace OS // known binary file extensions bool IsBinaryFile(const std::string &s) { + + // first -- check for a finder info extension. + { + uint8_t buffer[32]; + int rv; + + rv = ::getxattr(s.c_str(), XATTR_FINDERINFO_NAME, buffer, 32, 0, 0); + + if (rv >= 8 && ::memcmp(buffer + 4, "pdos",4) == 0) + { + // Bx__ ? + if (buffer[0] == 'B' && buffer[2] == ' ' && buffer[3] == ' ') + return true; + + // "p" $uv $wx $yz + if (buffer[0] == 'p') + { + uint8_t fileType = buffer[1]; + //uint16_t auxType = buffer[2] | (buffer[3] << 8); + + if (fileType >= 0xb1 && fileType <= 0xbf) + return true; + } + } + } + std::string ext = extension(s); if (ext.empty()) return false; char c = ext[0]; switch(c) { + case 'l': + if (ext == "lib") + return true; + break; + case 'o': if (ext == "o") return true;