- Boolean isX11 = false, isPlain = true, isZero = true;
- // extensions returned: o, tool, x11app, pef, core, dylib, bundle, jpeg, jp2, tiff, gif, png, pict, icns, ico, rtf, pdf, ra, au, aiff, aifc, wav, avi, wmv, psd, mpeg, mid, zip, jar, sit, html, ps, mov, qtif, bmp, hqx, bin, class, tar, txt, gz, Z, uu, sh, pl, py, rb, dvi, sgi, mp3, xml, plist, xls, doc, ppt, mp4, m4a, m4b, m4p, dmg
- if (url && CFURLGetFileSystemRepresentation(url, true, path, CFMaxPathSize) && (fd = open(path, O_RDONLY, 0777)) >= 0 && fstat(fd, &statBuf) == 0 && (statBuf.st_mode & S_IFMT) == S_IFREG) {
- if ((length = read(fd, bytes, MAGIC_BYTES_TO_READ)) >= 4) {
+#if defined(BINARY_SUPPORT_DYLD)
+ Boolean isX11 = false;
+#endif /* BINARY_SUPPORT_DYLD */
+ Boolean isFile = false, isPlain = true, isZero = true, isHTML = false;
+ // extensions returned: o, tool, x11app, pef, core, dylib, bundle, elf, jpeg, jp2, tiff, gif, png, pict, icns, ico, rtf, pdf, ra, rm, au, aiff, aifc, wav, avi, wmv, ogg, flac, psd, mpeg, mid, zip, jar, sit, cpio, html, ps, mov, qtif, ttf, otf, sfont, bmp, hqx, bin, class, tar, txt, gz, Z, uu, bz, bz2, sh, pl, py, rb, dvi, sgi, tga, mp3, xml, plist, xls, doc, ppt, mp4, m4a, m4b, m4p, dmg, cwk, webarchive, dwg, dgn, pfa, pfb, afm, tfm, xcf, cpx, dwf, swf, swc, abw, bom
+ // ??? we do not distinguish between different wm types, returning wmv for any of wmv, wma, or asf
+ if (url && CFURLGetFileSystemRepresentation(url, true, path, CFMaxPathSize) && stat(path, &statBuf) == 0 && (statBuf.st_mode & S_IFMT) == S_IFREG && (fd = open(path, O_RDONLY, 0777)) >= 0) {
+ // cjk: It is not at clear that not caching would be a win here, since
+ // in most cases the sniffing of the executable is only done lazily,
+ // the executable is likely to be immediately used again; say, the
+ // bundle executable loaded. CFBundle does not need the data again,
+ // but for the system as a whole not caching could be a net win or lose.
+ // So, this is where the cache disablement would go, but I am not going
+ // to turn it on at this point.
+ // fcntl(fd, F_NOCACHE, 1);
+ length = read(fd, buffer, MAGIC_BYTES_TO_READ);
+ fileLength = statBuf.st_size;
+ bytes = buffer;
+ isFile = true;
+ } else if (data) {
+ length = CFDataGetLength(data);
+ fileLength = (off_t)length;
+ bytes = CFDataGetBytePtr(data);
+ if (length == 0) ext = "txt";
+ }
+ if (bytes) {
+ if (length >= 4) {