misc/physfs/extras/physfsfgets.c
branchflibqtfrontend
changeset 8100 0e6fadf81a2c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/misc/physfs/extras/physfsfgets.c	Sun Nov 25 01:13:51 2012 +0400
@@ -0,0 +1,27 @@
+#include <stdlib.h>
+
+#include "physfsfgets.h"
+
+char * PHYSFS_fgets(char * str, int size, PHYSFS_file * f)
+{
+    int i = 0;
+    char c;
+
+    if(size <= 0 || PHYSFS_eof(f))
+        return NULL;
+
+    do
+    {
+        if (PHYSFS_readBytes(f, &c, 1) < 1)
+            break;
+
+        str[i] = c;
+        ++i;
+    } while(c != '\n' && i < size - 1);
+
+    str[i] = '\0';
+    if (i == 0)
+        return NULL;
+    else
+        return str;
+}