]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - util.c
util_fopen...
[xonotic/gmqcc.git] / util.c
diff --git a/util.c b/util.c
index d105cfd5d631e0a1ed5ab328ad009a1f393ec6f6..d825ab2f5715d72cb57d7cb71ec8c2104097f616 100644 (file)
--- a/util.c
+++ b/util.c
@@ -329,7 +329,7 @@ int util_getline(char **lineptr, size_t *n, FILE *stream) {
     if (!lineptr || !n || !stream)
         return -1;
     if (!*lineptr) {
-        if (!(*lineptr = mem_a((*n=64))))
+        if (!(*lineptr = (char*)mem_a((*n=64))))
             return -1;
     }
 
@@ -340,12 +340,12 @@ int util_getline(char **lineptr, size_t *n, FILE *stream) {
         int c = getc(stream);
 
         if (chr < 2) {
-            char *tmp = mem_a((*n+=(*n>16)?*n:64));
+            char *tmp = (char*)mem_a((*n+=(*n>16)?*n:64));
             if  (!tmp)
                 return -1;
 
+            memcpy(tmp, *lineptr, pos - *lineptr);
             chr = *n + *lineptr - pos;
-            strcpy(tmp,*lineptr);
             if (!(*lineptr = tmp)) {
                 mem_d (tmp);
                 return -1;
@@ -398,3 +398,16 @@ size_t util_strtononcmd(const char *in, char *out, size_t outsz) {
     *out = 0;
     return sz-1;
 }
+
+FILE *util_fopen(const char *filename, const char *mode)
+{
+#ifdef WIN32
+    FILE *out;
+    if (fopen_s(&out, file, mode) != 0)
+        return NULL;
+    return out;
+#else
+    return fopen(file, mode);
+#endif
+}
+