You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/04/23 20:54:16 UTC
svn commit: r768011 - in /commons/sandbox/runtime/trunk/src/main/native:
Makefile.in include/arch/unix/acr_arch.h os/unix/uutils.c
Author: mturk
Date: Thu Apr 23 18:54:16 2009
New Revision: 768011
URL: http://svn.apache.org/viewvc?rev=768011&view=rev
Log:
Add unix utils skeleton file
Added:
commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c (with props)
Modified:
commons/sandbox/runtime/trunk/src/main/native/Makefile.in
commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.in?rev=768011&r1=768010&r2=768011&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.in Thu Apr 23 18:54:16 2009
@@ -81,6 +81,7 @@
$(SRCDIR)/os/unix/file.$(OBJ) \
$(SRCDIR)/os/unix/main.$(OBJ) \
$(SRCDIR)/os/unix/uuid.$(OBJ) \
+ $(SRCDIR)/os/unix/uutils.$(OBJ) \
$(SRCDIR)/os/linux/platform.$(OBJ) \
$(SRCDIR)/os/linux/os.$(OBJ)
@@ -88,6 +89,7 @@
$(SRCDIR)/os/unix/file.$(OBJ) \
$(SRCDIR)/os/unix/main.$(OBJ) \
$(SRCDIR)/os/unix/uuid.$(OBJ) \
+ $(SRCDIR)/os/unix/uutils.$(OBJ) \
$(SRCDIR)/os/solaris/platform.$(OBJ) \
$(SRCDIR)/os/solaris/os.$(OBJ)
@@ -95,6 +97,7 @@
$(SRCDIR)/os/unix/file.$(OBJ) \
$(SRCDIR)/os/unix/main.$(OBJ) \
$(SRCDIR)/os/unix/uuid.$(OBJ) \
+ $(SRCDIR)/os/unix/uutils.$(OBJ) \
$(SRCDIR)/os/darwin/platform.$(OBJ) \
$(SRCDIR)/os/darwin/os.$(OBJ)
@@ -102,6 +105,7 @@
$(SRCDIR)/os/unix/file.$(OBJ) \
$(SRCDIR)/os/unix/main.$(OBJ) \
$(SRCDIR)/os/unix/uuid.$(OBJ) \
+ $(SRCDIR)/os/unix/uutils.$(OBJ) \
$(SRCDIR)/os/hpux/platform.$(OBJ) \
$(SRCDIR)/os/hpux/os.$(OBJ)
Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h?rev=768011&r1=768010&r2=768011&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/unix/acr_arch.h Thu Apr 23 18:54:16 2009
@@ -29,6 +29,19 @@
#define ACR_JNI_PLATFORM_DECLARE(RT, CL, FN) \
JNIEXPORT RT JNICALL Java_org_apache_commons_runtime_platform_unix_##CL##_##FN
+#define ACR_MAX_FREAD_LEN 65536
+
+/**
+ * Read the content of a txt file, up to the ACR_MAX_FREAD_LEN
+ * and remove all trailing space and control characters.
+ * @param name The file name to read.
+ * @return buffer with the content of the file. Use free() to
+ * deallocate the buffer when done.
+ * If the file cannot be read, function returns NULL.
+ */
+char *ACR_FileReadTxt(const char *name);
+
+
#ifdef __cplusplus
}
#endif
Added: commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c?rev=768011&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c Thu Apr 23 18:54:16 2009
@@ -0,0 +1,51 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 "acr.h"
+#include "acr_private.h"
+#include "acr_arch.h"
+#include "acr_error.h"
+#include "acr_string.h"
+#include "acr_file.h"
+
+char *ACR_FileReadTxt(const char *name)
+{
+ FILE *f;
+ size_t i, rd = ACR_MAX_FREAD_LEN;
+ char *b;
+
+ if (!(f = fopen(name, "r")))
+ return NULL;
+ if ((b = malloc(rd))) {
+ rd = fread(b, 1, rd - 2, f);
+
+ if (rd > 0) {
+ /* Remove all trailing zero and space characters */
+ for (i = rd - 1; i >= 0 && (acr_iscntrl(b[i]) ||
+ acr_isspace(b[i])); i--)
+ ;
+ b[i + 1] = '\0';
+ b[i + 2] = '\0';
+ }
+ else {
+ free(b);
+ fclose(f);
+ return NULL;
+ }
+ }
+ fclose(f);
+ return b;
+}
Propchange: commons/sandbox/runtime/trunk/src/main/native/os/unix/uutils.c
------------------------------------------------------------------------------
svn:eol-style = native