summaryrefslogtreecommitdiffstats
path: root/matchblox/common/textfile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'matchblox/common/textfile.cpp')
-rw-r--r--matchblox/common/textfile.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/matchblox/common/textfile.cpp b/matchblox/common/textfile.cpp
new file mode 100644
index 0000000..0b74282
--- /dev/null
+++ b/matchblox/common/textfile.cpp
@@ -0,0 +1,69 @@
+// textfile.cpp
+//
+// simple reading and writing for text files
+//
+// www.lighthouse3d.com
+//
+// You may use these functions freely.
+// they are provided as is, and no warranties, either implicit,
+// or explicit are given
+//////////////////////////////////////////////////////////////////////
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+char *textFileRead(char *fn) {
+
+
+ FILE *fp;
+ char *content = NULL;
+
+ int count=0;
+
+ if (fn != NULL) {
+ fp = fopen(fn,"rt");
+
+ if (fp != NULL) {
+
+ fseek(fp, 0, SEEK_END);
+ count = ftell(fp);
+ rewind(fp);
+
+ if (count > 0) {
+ content = (char *)malloc(sizeof(char) * (count+1));
+ count = fread(content,sizeof(char),count,fp);
+ content[count] = '\0';
+ }
+ fclose(fp);
+ }
+ }
+ return content;
+}
+
+int textFileWrite(char *fn, char *s) {
+
+ FILE *fp;
+ int status = 0;
+
+ if (fn != NULL) {
+ fp = fopen(fn,"w");
+
+ if (fp != NULL) {
+
+ if (fwrite(s,sizeof(char),strlen(s),fp) == strlen(s))
+ status = 1;
+ fclose(fp);
+ }
+ }
+ return(status);
+}
+
+
+
+
+
+
+