]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.fastlz/native/fastlz_write.c
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.fastlz / native / fastlz_write.c
index 36b6458c960245a1c6a985d2e46971f9acfb6e20..d8142e83891753857296a9bf3acb51e732a26f2e 100644 (file)
@@ -1,74 +1,74 @@
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-#include "fastlz.h"\r
-\r
-#define BLOCKSIZE (128*1024)\r
-\r
-char* uncompressed;\r
-int uncompressedCapacity;\r
-int position;\r
-char* compressed;\r
-int compressedCapacity;\r
-\r
-FILE* handle;\r
-\r
-void initWrite(FILE* _handle) {\r
-    uncompressedCapacity = BLOCKSIZE;\r
-    uncompressed = malloc(uncompressedCapacity);\r
-    position = 0;\r
-    compressedCapacity = 8 + BLOCKSIZE + (BLOCKSIZE/20);\r
-    compressed = malloc(compressedCapacity);\r
-    handle = _handle;\r
-}\r
-\r
-void flushBuffer() {\r
-    int uncompressedSize = position;\r
-    int compressedSize = fastlz_compress(uncompressed, uncompressedSize, compressed+8);\r
-\r
-    ((int*)compressed)[0] = compressedSize;\r
-    ((int*)compressed)[1] = uncompressedSize;\r
-    \r
-    fwrite(compressed, compressedSize+8, 1, handle);\r
-    position = 0;\r
-}\r
-\r
-void deinitWrite() {\r
-    flushBuffer();\r
-\r
-    ((int*)compressed)[0] = 0;\r
-    ((int*)compressed)[1] = 0;    \r
-    fwrite(compressed, 8, 1, handle);\r
-\r
-    free(uncompressed);\r
-    uncompressed = 0;\r
-    free(compressed);\r
-    compressed = 0;\r
-    handle = 0;\r
-}\r
-\r
-void write(char* data, int offset, int length) {\r
-    int s;\r
-\r
-    while(length > uncompressedCapacity - position) {\r
-        s = uncompressedCapacity - position;\r
-        memcpy(uncompressed + position, data + offset, s);\r
-        offset += s;\r
-        length -= s;\r
-        position += s;\r
-        flushBuffer();\r
-    }\r
-    memcpy(uncompressed + position, data + offset, length);\r
-    position += length;\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "fastlz.h"
+
+#define BLOCKSIZE (128*1024)
+
+char* uncompressed;
+int uncompressedCapacity;
+int position;
+char* compressed;
+int compressedCapacity;
+
+FILE* handle;
+
+void initWrite(FILE* _handle) {
+    uncompressedCapacity = BLOCKSIZE;
+    uncompressed = malloc(uncompressedCapacity);
+    position = 0;
+    compressedCapacity = 8 + BLOCKSIZE + (BLOCKSIZE/20);
+    compressed = malloc(compressedCapacity);
+    handle = _handle;
+}
+
+void flushBuffer() {
+    int uncompressedSize = position;
+    int compressedSize = fastlz_compress(uncompressed, uncompressedSize, compressed+8);
+
+    ((int*)compressed)[0] = compressedSize;
+    ((int*)compressed)[1] = uncompressedSize;
+    
+    fwrite(compressed, compressedSize+8, 1, handle);
+    position = 0;
+}
+
+void deinitWrite() {
+    flushBuffer();
+
+    ((int*)compressed)[0] = 0;
+    ((int*)compressed)[1] = 0;    
+    fwrite(compressed, 8, 1, handle);
+
+    free(uncompressed);
+    uncompressed = 0;
+    free(compressed);
+    compressed = 0;
+    handle = 0;
+}
+
+void write(char* data, int offset, int length) {
+    int s;
+
+    while(length > uncompressedCapacity - position) {
+        s = uncompressedCapacity - position;
+        memcpy(uncompressed + position, data + offset, s);
+        offset += s;
+        length -= s;
+        position += s;
+        flushBuffer();
+    }
+    memcpy(uncompressed + position, data + offset, length);
+    position += length;
+}