]> www.git.momoyon.org Git - lang.git/commitdiff
[include/commonlib.h] Update...
authorahmedsamyh <ahmedsamyh10@gmail.com>
Wed, 28 May 2025 18:17:50 +0000 (23:17 +0500)
committerahmedsamyh <ahmedsamyh10@gmail.com>
Wed, 28 May 2025 18:17:50 +0000 (23:17 +0500)
- [Makefile] Ignore a warning.

Makefile
include/commonlib.h

index e8c32e4b82afe85228deb91ac457e8a8b976ed88..22a15e18d8d133ec7a71ebe99db6dff5164b7038 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
 CC=gcc
-CFLAGS=-Wall -Wextra -ggdb -I./include -Wswitch-enum -Wno-char-subscripts
+CFLAGS=-Wall -Wextra -ggdb -I./include -Wswitch-enum -Wno-char-subscripts -Wno-sign-compare
 LDFLAGS=-L./lib
 LIBS=
 
index 9b3e4d7aeeecfa9f81ee1f2fd5678b22f8496c99..bd0bf000597ef76c61da6aa2938ead94bcd0b1da 100644 (file)
 #include <assert.h>\r
 #include <limits.h>\r
 \r
+#if defined(_WIN32)\r
+// NOTE: Don't include unwanted files to speed up compilation\r
+#define WIN32_LEAN_AND_MEAN\r
+#define NOCOMM\r
+#include <windows.h>\r
+#undef C_ASSERT // Bruh\r
+#endif\r
+\r
 // Remove Prefix\r
 #ifdef COMMONLIB_REMOVE_PREFIX\r
 #define ASSERT C_ASSERT\r
@@ -115,12 +123,21 @@ typedef const wchar* wstr;
 \r
 \r
 // Macros\r
+#if defined(_MSC_VER) && !defined(__clang__) && !defined(__INTEL_COMPILER)\r
+#define C_ASSERT(condition, msg) do {\\r
+                if (!(condition)) {\\r
+                        fprintf(stderr, "%s:%d:0 [ASSERTION FAILED] %s: %s", __FILE__, __LINE__, #condition, msg);\\r
+                        DebugBreak();\\r
+                }\\r
+        } while (0)\r
+#else\r
 #define C_ASSERT(condition, msg) do {\\r
                 if (!(condition)) {\\r
                         fprintf(stderr, "%s:%d:0 [ASSERTION FAILED] %s: %s", __FILE__, __LINE__, #condition, msg);\\r
                         exit(1);\\r
                 }\\r
         } while (0)\r
+#endif // defined(_MSC_VER) && !defined(__clang__) && !defined(__INTEL_COMPILER)\r
 \r
 #define C_ARRAY_LEN(arr) (sizeof(arr) / sizeof(arr[0]))\r
 \r
@@ -393,10 +410,27 @@ const char *c_read_file(const char* filename, int *file_size) {
 \r
     size_t read = fread((char*)result, sizeof(char), fsize, f);\r
 \r
-    *file_size = (int)read;\r
+    // Process the result to remove '\r' characters\r
+    char* cleaned_result = malloc(read + 1); // Allocate memory for cleaned result\r
+    if (cleaned_result == NULL) {\r
+        fprintf(stderr, "Memory allocation failed\n");\r
+        free(result);\r
+        return NULL;\r
+    }\r
 \r
-    // set null-terminator\r
-    result[read] = '\0';\r
+    size_t j = 0; // Index for cleaned_result\r
+    for (size_t i = 0; i < read; i++) {\r
+        if (result[i] != '\r') { // Skip '\r' characters\r
+            cleaned_result[j++] = result[i];\r
+        }\r
+    }\r
+    cleaned_result[j] = '\0'; // Null-terminate the cleaned result\r
+\r
+    free(result); // Free the original result\r
+    *file_size = (int)j; // Update the file size without '\r'\r
+    return cleaned_result; // Return the cleaned result\r
+\r
+    *file_size = (int)read;\r
 \r
  defer:\r
     if (f) fclose(f);\r
@@ -732,7 +766,7 @@ c_String_view c_sv_get_part(c_String_view sv, int from, int to) {
     from = clampi(from, 0, sv.count);\r
     to   = clampi(to, from, sv.count);\r
 \r
-    String_view range = {\r
+    c_String_view range = {\r
         .data = (char*)(sv.data + from),\r
         .count = (size_t)(to - from),\r
     };\r