فهرست منبع

Move my_strdup() to text_utils.h

Evgeniy Parfenyuk 2 هفته پیش
والد
کامیت
4e60374eb6
3فایلهای تغییر یافته به همراه22 افزوده شده و 14 حذف شده
  1. 1 1
      Makefile
  2. 19 0
      src/text_utils.h
  3. 2 13
      src/ui/text_box.c

+ 1 - 1
Makefile

@@ -1,6 +1,6 @@
 CC       := gcc
 CFLAGS   := -Wall -Wextra -Wpedantic -Werror -std=c99
-INCLUDES := -Iext/raylib/src/
+INCLUDES := -Iext/raylib/src/ -Isrc/
 LDFLAGS  := -Lext/raylib/src/
 LIBS     := -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
 

+ 19 - 0
src/text_utils.h

@@ -0,0 +1,19 @@
+#ifndef TEXT_UTILS_H
+#define TEXT_UTILS_H
+#include <string.h>
+#include <stdlib.h>
+
+static char *my_strdup(const char *s)
+{
+    if (!s)
+        return NULL;
+    size_t n = strlen(s) + 1;
+    char *p = malloc(n);
+    if (!p)
+        return NULL;
+    memcpy(p, s, n);
+    return p;
+}
+
+#endif
+

+ 2 - 13
src/ui/text_box.c

@@ -1,19 +1,8 @@
 #include "text_box.h"
+#include "text_utils.h"
 #include <stdlib.h>
 #include <string.h>
 
-static char *strdup(const char *s)
-{
-    if (!s)
-        return NULL;
-    size_t n = strlen(s) + 1;
-    char *p = malloc(n);
-    if (!p)
-        return NULL;
-    memcpy(p, s, n);
-    return p;
-}
-
 void TextBoxInit(TextBox *tb, int screenWidth, int screenHeight)
 {
     tb->rect = (Rectangle){
@@ -49,7 +38,7 @@ void TextBoxSetText(TextBox *tb, const char *name, const char *text)
 
     if (tb->text)
         free(tb->text);
-    tb->text = strdup(text ? text : "");
+    tb->text = my_strdup(text ? text : "");
 }
 
 void TextBoxDraw(TextBox *tb)