[libc-commits] [libc] [libc][test] make `str_to_float_comparison_test` independent of C++ headers. (PR #133978)

Muhammad Bassiouni via libc-commits libc-commits at lists.llvm.org
Tue Apr 1 15:19:53 PDT 2025


================
@@ -59,30 +56,31 @@ int checkFile(char *inputFileName, int *totalFails, int *totalBitDiffs,
   int32_t curFails = 0;    // Only counts actual failures, not bitdiffs.
   int32_t curBitDiffs = 0; // A bitdiff is when the expected result and actual
                            // result are off by +/- 1 bit.
-  std::string line;
-  std::string num;
+  char line[100];
+  char num[100];
 
-  std::ifstream fileStream(inputFileName, std::ifstream::in);
+  auto *fileHandle = fopen(inputFileName, "r");
 
-  if (!fileStream.is_open()) {
-    std::cout << "file '" << inputFileName << "' failed to open. Exiting.\n";
+  if (!fileHandle) {
+    printf("file '%s' failed to open. Exiting.\n", inputFileName);
     return 1;
   }
-  while (getline(fileStream, line)) {
+
+  while (fgets(line, sizeof(line), fileHandle)) {
     if (line[0] == '#') {
       continue;
     }
     *total = *total + 1;
     uint32_t expectedFloatRaw;
     uint64_t expectedDoubleRaw;
 
-    expectedFloatRaw = fastHexToU32(line.c_str() + 5);
-    expectedDoubleRaw = fastHexToU64(line.c_str() + 14);
-    num = line.substr(31);
+    expectedFloatRaw = fastHexToU32(line + 5);
+    expectedDoubleRaw = fastHexToU64(line + 14);
+    sscanf(line + 31, "%s", num);
----------------
bassiounix wrote:

I had to change it to `const char *` instead of `char[100]` to make this possible

https://github.com/llvm/llvm-project/pull/133978


More information about the libc-commits mailing list