You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@corinthia.apache.org by ja...@apache.org on 2015/01/01 11:10:32 UTC
[10/19] incubator-corinthia git commit: work
work
Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/48a40e1c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/48a40e1c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/48a40e1c
Branch: refs/heads/RTC_platform
Commit: 48a40e1c1f91670f5930c9052f25b8f14e5ec0a2
Parents: f92c311
Author: jani <ja...@apache.org>
Authored: Tue Dec 30 16:29:51 2014 +0100
Committer: jani <ja...@apache.org>
Committed: Tue Dec 30 16:29:51 2014 +0100
----------------------------------------------------------------------
DocFormats/platform/src/Wrapper.c | 133 +++++++++++++++++++++++++++++++++
1 file changed, 133 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/48a40e1c/DocFormats/platform/src/Wrapper.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Wrapper.c b/DocFormats/platform/src/Wrapper.c
new file mode 100644
index 0000000..b9df21a
--- /dev/null
+++ b/DocFormats/platform/src/Wrapper.c
@@ -0,0 +1,133 @@
+// Copyright 2012-2014 UX Productivity Pty Ltd
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+#include <string.h>
+#include "DFPlatform.h"
+#include "unzip.h"
+#include "zip.h"
+
+
+// This file contains functions to isolate external libraries
+static unzFile myZipFile;
+static int myZipFlag;
+static int myZipFirst;
+
+
+int DFextZipOpen(const char *zipFilename, int doUnzip) {
+ // Check if already in use
+ if (myZipFile)
+ return 0;
+
+ // Open file
+ myZipFirst = 1;
+ myZipFlag = doUnzip;
+ if (myZipFlag)
+ myZipFile = unzOpen(zipFilename);
+ else
+ myZipFile = zipOpen(zipFilename, APPEND_STATUS_CREATE);
+
+ return (myZipFile == NULL) ? -1 : 1;
+}
+
+
+
+int DFextZipClose(void)
+{
+ int rc;
+
+ if (myZipFile) {
+ if (myZipFlag)
+ rc = (unzClose(myZipFile) == UNZ_OK);
+ else
+ rc = (zipClose(myZipFile, NULL) == ZIP_OK);
+ myZipFile = NULL;
+ }
+
+ return rc ? 0 : -1;
+}
+
+
+
+int DFextZipOpenNextFile(char *entryName, const int maxName)
+{
+ int rc;
+
+
+ if (myZipFlag) {
+ unz_file_info info;
+
+ // handling of first file and all others are different
+ if (myZipFirst) {
+ rc = unzGoToFirstFile(myZipFile);
+ myZipFirst = 0;
+ }
+ else
+ rc = unzGoToNextFile(myZipFile);
+
+ // Error or past last file
+ if (rc != UNZ_OK)
+ return (rc == UNZ_END_OF_LIST_OF_FILE) ? 0 : -1;
+
+ // get file name
+ if (unzGetCurrentFileInfo(myZipFile, &info, entryName, maxName, NULL, 0, NULL, 0) != UNZ_OK)
+ return -1;
+
+ // check for prefix "/" and if present skip file
+ if (entryName[strlen(entryName) - 1] == '/')
+ return DFextZipOpenNextFile(entryName, maxName);
+
+ // open Regular file
+ if (unzOpenCurrentFile(myZipFile) != UNZ_OK)
+ return -1;
+ }
+ else {
+ zip_fileinfo fileinfo;
+ memset(&fileinfo, 0, sizeof(fileinfo));
+
+ if (zipOpenNewFileInZip(myZipFile,
+ entryName,
+ &fileinfo,
+ NULL, 0,
+ NULL, 0,
+ NULL,
+ Z_DEFLATED,
+ Z_DEFAULT_COMPRESSION) != ZIP_OK)
+ return -1;
+ }
+
+ // ready to read
+ return 1;
+}
+
+
+
+int DFextZipCloseFile(void)
+{
+ if (myZipFlag)
+ return (unzCloseCurrentFile(myZipFile) != UNZ_OK) ? -1 : 1;
+ else
+ return (zipCloseFileInZip(myZipFile) != UNZ_OK) ? -1 : 1;
+}
+
+
+
+
+int DFextZipReadCurrentFile(char *buf, const int maxLen)
+{
+ return unzReadCurrentFile(myZipFile, buf, maxLen);
+}
+
+
+
+
+