diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..796c023 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.exe +*.user +/win32/.vs +/win32/bin +/win32/obj diff --git a/crc64.c b/crc64.c index f61fdfa..e8bbf39 100644 --- a/crc64.c +++ b/crc64.c @@ -139,19 +139,43 @@ static uint64_t crc64_update(uint64_t crc, const uint8_t *const buffer, const si return crc; } +/* ======================================================================== */ +/* Detect directory */ +/* ======================================================================== */ + +#ifdef _MSC_VER +#pragma warning(disable: 4100) +#endif + +static int is_directory(FILE *const file) +{ +#ifndef _WIN32 + struct stat statbuf; + if (!fstat(fileno(file), &statbuf)) + { + if ((statbuf.st_mode & S_IFMT) == S_IFDIR) + { + return 1; + } + } +#endif + return 0; +} + /* ======================================================================== */ /* Process File */ /* ======================================================================== */ const CHAR *const STR_STDIN = T("/dev/stdin"); +#define BUFF_SIZE 4096U + static int process(const CHAR *const file_name, const int options) { int retval = EXIT_FAILURE; FILE *input = NULL; uint64_t crc = CRC64_INITIALIZER, total_size = 0U; - struct stat properties; - uint8_t buffer[BUFSIZ]; + uint8_t buffer[BUFF_SIZE]; input = file_name ? FOPEN(file_name, T("rb")) : stdin; if (!input) @@ -164,21 +188,18 @@ static int process(const CHAR *const file_name, const int options) return EXIT_FAILURE; } - if (!fstat(fileno(input), &properties)) + if (is_directory(input)) { - if ((properties.st_mode & S_IFMT) == S_IFDIR) + if (!(options & OPT_SILENT)) { - if (!(options & OPT_SILENT)) - { - FPRINTF(stderr, T("Error: Input file \"%s\" is a directory!\n"), file_name ? file_name : STR_STDIN); - } - goto clean_up; + FPRINTF(stderr, T("Error: Input file \"%s\" is a directory!\n"), file_name ? file_name : STR_STDIN); } + goto clean_up; } while ((!feof(input)) && (!g_stop_flag)) { - const size_t count = fread(buffer, sizeof(uint8_t), BUFSIZ, input); + const size_t count = fread(buffer, sizeof(uint8_t), BUFF_SIZE, input); if (count > 0U) { total_size += count; diff --git a/crc64.exe b/crc64.exe deleted file mode 100644 index 3fefa5a..0000000 Binary files a/crc64.exe and /dev/null differ diff --git a/win32/crc64.sln b/win32/crc64.sln new file mode 100644 index 0000000..a76e95d --- /dev/null +++ b/win32/crc64.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.2092 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "crc64", "crc64.vcxproj", "{9D573175-F71F-45A8-8339-ED3CDAC17F72}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9D573175-F71F-45A8-8339-ED3CDAC17F72}.Release|x64.ActiveCfg = Release|x64 + {9D573175-F71F-45A8-8339-ED3CDAC17F72}.Release|x64.Build.0 = Release|x64 + {9D573175-F71F-45A8-8339-ED3CDAC17F72}.Release|x86.ActiveCfg = Release|Win32 + {9D573175-F71F-45A8-8339-ED3CDAC17F72}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FA183244-AE1B-40C3-A1A5-DA9D346282A0} + EndGlobalSection +EndGlobal diff --git a/win32/crc64.vcxproj b/win32/crc64.vcxproj new file mode 100644 index 0000000..713a7be --- /dev/null +++ b/win32/crc64.vcxproj @@ -0,0 +1,115 @@ + + + + + Release + Win32 + + + Release + x64 + + + + + + + 15.0 + {9D573175-F71F-45A8-8339-ED3CDAC17F72} + Win32Proj + crc64 + 7.0 + + + + Application + false + v141_xp + true + Unicode + + + Application + false + v141_xp + true + Unicode + + + + + + + + + + + + + + + false + $(SolutionDir)\bin\$(Platform)\$(Configuration)\ + $(SolutionDir)\obj\$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)\bin\$(Platform)\$(Configuration)\ + $(SolutionDir)\obj\$(Platform)\$(Configuration)\ + + + + NotUsing + Level4 + MaxSpeed + true + true + _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + MultiThreaded + false + AnySuitable + Speed + true + true + NoExtensions + + + Console + true + true + false + UseLinkTimeCodeGeneration + setargv.obj;%(AdditionalDependencies) + + + + + NotUsing + Level4 + MaxSpeed + true + true + _CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + MultiThreaded + false + AnySuitable + Speed + true + true + NotSet + + + Console + true + true + false + UseLinkTimeCodeGeneration + setargv.obj;%(AdditionalDependencies) + + + + + + \ No newline at end of file diff --git a/win32/crc64.vcxproj.filters b/win32/crc64.vcxproj.filters new file mode 100644 index 0000000..be10a08 --- /dev/null +++ b/win32/crc64.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file