diff options
Diffstat (limited to 'libjava/classpath/native/jni/native-lib')
-rw-r--r-- | libjava/classpath/native/jni/native-lib/.cvsignore | 8 | ||||
-rw-r--r-- | libjava/classpath/native/jni/native-lib/Makefile.am | 13 | ||||
-rw-r--r-- | libjava/classpath/native/jni/native-lib/Makefile.in | 567 | ||||
-rw-r--r-- | libjava/classpath/native/jni/native-lib/cpio.c | 592 | ||||
-rw-r--r-- | libjava/classpath/native/jni/native-lib/cpio.h | 99 | ||||
-rw-r--r-- | libjava/classpath/native/jni/native-lib/cpnative.h | 49 | ||||
-rw-r--r-- | libjava/classpath/native/jni/native-lib/cpnet.c | 818 | ||||
-rw-r--r-- | libjava/classpath/native/jni/native-lib/cpnet.h | 221 | ||||
-rw-r--r-- | libjava/classpath/native/jni/native-lib/cpproc.c | 141 | ||||
-rw-r--r-- | libjava/classpath/native/jni/native-lib/cpproc.h | 52 |
10 files changed, 2560 insertions, 0 deletions
diff --git a/libjava/classpath/native/jni/native-lib/.cvsignore b/libjava/classpath/native/jni/native-lib/.cvsignore new file mode 100644 index 000000000..e9f2658a6 --- /dev/null +++ b/libjava/classpath/native/jni/native-lib/.cvsignore @@ -0,0 +1,8 @@ +*.o +*.a +*.lo +*.la +.libs +.deps +Makefile +Makefile.in diff --git a/libjava/classpath/native/jni/native-lib/Makefile.am b/libjava/classpath/native/jni/native-lib/Makefile.am new file mode 100644 index 000000000..0de723eb1 --- /dev/null +++ b/libjava/classpath/native/jni/native-lib/Makefile.am @@ -0,0 +1,13 @@ +noinst_LTLIBRARIES = libclasspathnative.la +libclasspathnative_la_SOURCES = cpnet.c \ + cpnet.h \ + cpio.c \ + cpio.h \ + cpnative.h \ + cpproc.h \ + cpproc.c + +AM_LDFLAGS = @CLASSPATH_CONVENIENCE@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ +AM_CFLAGS = @WARNING_CFLAGS@ @STRICT_WARNING_CFLAGS@ @ERROR_CFLAGS@ \ + @EXTRA_CFLAGS@ diff --git a/libjava/classpath/native/jni/native-lib/Makefile.in b/libjava/classpath/native/jni/native-lib/Makefile.in new file mode 100644 index 000000000..4f58dedaa --- /dev/null +++ b/libjava/classpath/native/jni/native-lib/Makefile.in @@ -0,0 +1,567 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = native/jni/native-lib +DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/../../config/depstand.m4 \ + $(top_srcdir)/../../config/lead-dot.m4 \ + $(top_srcdir)/../../config/lib-ld.m4 \ + $(top_srcdir)/../../config/lib-link.m4 \ + $(top_srcdir)/../../config/lib-prefix.m4 \ + $(top_srcdir)/../../config/multi.m4 \ + $(top_srcdir)/../../config/no-executables.m4 \ + $(top_srcdir)/../../config/override.m4 \ + $(top_srcdir)/../../libtool.m4 \ + $(top_srcdir)/../../ltoptions.m4 \ + $(top_srcdir)/../../ltsugar.m4 \ + $(top_srcdir)/../../ltversion.m4 \ + $(top_srcdir)/../../lt~obsolete.m4 \ + $(top_srcdir)/m4/ac_prog_antlr.m4 \ + $(top_srcdir)/m4/ac_prog_java.m4 \ + $(top_srcdir)/m4/ac_prog_java_works.m4 \ + $(top_srcdir)/m4/ac_prog_javac.m4 \ + $(top_srcdir)/m4/ac_prog_javac_works.m4 \ + $(top_srcdir)/m4/acattribute.m4 $(top_srcdir)/m4/accross.m4 \ + $(top_srcdir)/m4/acinclude.m4 \ + $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/ax_func_which_gethostbyname_r.m4 \ + $(top_srcdir)/m4/gcc_attribute.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs +CONFIG_HEADER = $(top_builddir)/include/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +LTLIBRARIES = $(noinst_LTLIBRARIES) +libclasspathnative_la_LIBADD = +am_libclasspathnative_la_OBJECTS = cpnet.lo cpio.lo cpproc.lo +libclasspathnative_la_OBJECTS = $(am_libclasspathnative_la_OBJECTS) +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include +depcomp = $(SHELL) $(top_srcdir)/../../depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libclasspathnative_la_SOURCES) +ETAGS = etags +CTAGS = ctags +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +ANTLR = @ANTLR@ +ANTLR_JAR = @ANTLR_JAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CAIRO_CFLAGS = @CAIRO_CFLAGS@ +CAIRO_LIBS = @CAIRO_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CLASSPATH_CONVENIENCE = @CLASSPATH_CONVENIENCE@ +CLASSPATH_INCLUDES = @CLASSPATH_INCLUDES@ +CLASSPATH_MODULE = @CLASSPATH_MODULE@ +COLLECTIONS_PREFIX = @COLLECTIONS_PREFIX@ +CP = @CP@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATE = @DATE@ +DEFAULT_PREFS_PEER = @DEFAULT_PREFS_PEER@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +ECJ_JAR = @ECJ_JAR@ +EGREP = @EGREP@ +ERROR_CFLAGS = @ERROR_CFLAGS@ +EXAMPLESDIR = @EXAMPLESDIR@ +EXEEXT = @EXEEXT@ +EXTRA_CFLAGS = @EXTRA_CFLAGS@ +FGREP = @FGREP@ +FIND = @FIND@ +FREETYPE2_CFLAGS = @FREETYPE2_CFLAGS@ +FREETYPE2_LIBS = @FREETYPE2_LIBS@ +GCONF_CFLAGS = @GCONF_CFLAGS@ +GCONF_LIBS = @GCONF_LIBS@ +GDK_CFLAGS = @GDK_CFLAGS@ +GDK_LIBS = @GDK_LIBS@ +GJDOC = @GJDOC@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_LIBS = @GLIB_LIBS@ +GMP_CFLAGS = @GMP_CFLAGS@ +GMP_LIBS = @GMP_LIBS@ +GREP = @GREP@ +GSTREAMER_BASE_CFLAGS = @GSTREAMER_BASE_CFLAGS@ +GSTREAMER_BASE_LIBS = @GSTREAMER_BASE_LIBS@ +GSTREAMER_CFLAGS = @GSTREAMER_CFLAGS@ +GSTREAMER_FILE_READER = @GSTREAMER_FILE_READER@ +GSTREAMER_LIBS = @GSTREAMER_LIBS@ +GSTREAMER_MIXER_PROVIDER = @GSTREAMER_MIXER_PROVIDER@ +GSTREAMER_PLUGINS_BASE_CFLAGS = @GSTREAMER_PLUGINS_BASE_CFLAGS@ +GSTREAMER_PLUGINS_BASE_LIBS = @GSTREAMER_PLUGINS_BASE_LIBS@ +GST_PLUGIN_LDFLAGS = @GST_PLUGIN_LDFLAGS@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_LIBS = @GTK_LIBS@ +INIT_LOAD_LIBRARY = @INIT_LOAD_LIBRARY@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAVA = @JAVA@ +JAVAC = @JAVAC@ +JAVAC_IS_GCJ = @JAVAC_IS_GCJ@ +JAVAC_MEM_OPT = @JAVAC_MEM_OPT@ +JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION = @JAVA_LANG_SYSTEM_EXPLICIT_INITIALIZATION@ +JAY = @JAY@ +JAY_SKELETON = @JAY_SKELETON@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBDEBUG = @LIBDEBUG@ +LIBICONV = @LIBICONV@ +LIBMAGIC = @LIBMAGIC@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBVERSION = @LIBVERSION@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MKDIR = @MKDIR@ +MKDIR_P = @MKDIR_P@ +MOC = @MOC@ +MOZILLA_CFLAGS = @MOZILLA_CFLAGS@ +MOZILLA_LIBS = @MOZILLA_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PANGOFT2_CFLAGS = @PANGOFT2_CFLAGS@ +PANGOFT2_LIBS = @PANGOFT2_LIBS@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PATH_TO_ESCHER = @PATH_TO_ESCHER@ +PATH_TO_GLIBJ_ZIP = @PATH_TO_GLIBJ_ZIP@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PLUGIN_DIR = @PLUGIN_DIR@ +QT_CFLAGS = @QT_CFLAGS@ +QT_LIBS = @QT_LIBS@ +RANLIB = @RANLIB@ +REMOVE = @REMOVE@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRICT_WARNING_CFLAGS = @STRICT_WARNING_CFLAGS@ +STRIP = @STRIP@ +TOOLSDIR = @TOOLSDIR@ +USER_JAVAH = @USER_JAVAH@ +VERSION = @VERSION@ +WANT_NATIVE_BIG_INTEGER = @WANT_NATIVE_BIG_INTEGER@ +WARNING_CFLAGS = @WARNING_CFLAGS@ +XMKMF = @XMKMF@ +XML_CFLAGS = @XML_CFLAGS@ +XML_LIBS = @XML_LIBS@ +XSLT_CFLAGS = @XSLT_CFLAGS@ +XSLT_LIBS = @XSLT_LIBS@ +XTEST_LIBS = @XTEST_LIBS@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +ZIP = @ZIP@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_ANTLR = @ac_ct_ANTLR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +default_toolkit = @default_toolkit@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +glibjdir = @glibjdir@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +multi_basedir = @multi_basedir@ +nativeexeclibdir = @nativeexeclibdir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +toolexeclibdir = @toolexeclibdir@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +uudecode = @uudecode@ +vm_classes = @vm_classes@ +noinst_LTLIBRARIES = libclasspathnative.la +libclasspathnative_la_SOURCES = cpnet.c \ + cpnet.h \ + cpio.c \ + cpio.h \ + cpnative.h \ + cpproc.h \ + cpproc.c + +AM_LDFLAGS = @CLASSPATH_CONVENIENCE@ +AM_CPPFLAGS = @CLASSPATH_INCLUDES@ +AM_CFLAGS = @WARNING_CFLAGS@ @STRICT_WARNING_CFLAGS@ @ERROR_CFLAGS@ \ + @EXTRA_CFLAGS@ + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu native/jni/native-lib/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu native/jni/native-lib/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libclasspathnative.la: $(libclasspathnative_la_OBJECTS) $(libclasspathnative_la_DEPENDENCIES) + $(LINK) $(libclasspathnative_la_OBJECTS) $(libclasspathnative_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpio.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpnet.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpproc.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-noinstLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags dvi dvi-am html html-am info info-am install \ + install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags uninstall uninstall-am + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/libjava/classpath/native/jni/native-lib/cpio.c b/libjava/classpath/native/jni/native-lib/cpio.c new file mode 100644 index 000000000..d8523680a --- /dev/null +++ b/libjava/classpath/native/jni/native-lib/cpio.c @@ -0,0 +1,592 @@ +/* cpio.c - Common java file IO native functions + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +/* do not move; needed here because of some macro definitions */ +#include <config.h> + +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <string.h> +#include <sys/types.h> +#include <dirent.h> + +#include <jni.h> + +#if defined(HAVE_SYS_IOCTL_H) +#define BSD_COMP /* Get FIONREAD on Solaris2 */ +#include <sys/ioctl.h> +#endif +#if defined(HAVE_SYS_FILIO_H) /* Get FIONREAD on Solaris 2.5 */ +#include <sys/filio.h> +#endif + +#if defined(HAVE_SYS_STAT_H) +#include <sys/stat.h> +#endif + +#if defined(HAVE_FCNTL_H) +#include <fcntl.h> +#endif + +#if defined(HAVE_UNISTD_H) +#include <unistd.h> +#endif + +#if defined(HAVE_SYS_SELECT_H) +#include <sys/select.h> +#endif + +#if defined(HAVE_STATVFS) +#include <sys/statvfs.h> +#endif + +#include <utime.h> + +#include "cpnative.h" +#include "cpio.h" + +/* Some POSIX systems don't have O_SYNC and O_DYSNC so we define them here. */ +#if !defined (O_SYNC) && defined (O_FSYNC) +#define O_SYNC O_FSYNC +#endif +#if !defined (O_DSYNC) && defined (O_FSYNC) +#define O_DSYNC O_FSYNC +#endif +/* If O_DSYNC is still not defined, use O_SYNC (needed for newlib). */ +#if !defined (O_DSYNC) +#define O_DSYNC O_SYNC +#endif + +JNIEXPORT int cpio_openFile (const char *filename, int *fd, int flags, int permissions) +{ + int sflags = 0; + int rwflags = flags & CPFILE_FLAG_READWRITE; + int perms; + + if (flags & CPFILE_FLAG_CREATE) + sflags |= O_CREAT; + if (flags & CPFILE_FLAG_APPEND) + sflags |= O_APPEND; + if (flags & CPFILE_FLAG_TRUNCATE) + sflags |= O_TRUNC; + if (flags & CPFILE_FLAG_SYNC) + sflags |= O_SYNC; + if (flags & CPFILE_FLAG_DSYNC) + sflags |= O_DSYNC; +#if defined(O_BINARY) + if (flags & CPFILE_FLAG_BINARY) + sflags |= O_BINARY; +#endif + + switch (rwflags) + { + case CPFILE_FLAG_READ: + sflags |= O_RDONLY; + break; + case CPFILE_FLAG_WRITE: + sflags |= O_WRONLY; + break; + case CPFILE_FLAG_READWRITE: + sflags |= O_RDWR; + break; + } + + if (permissions == CPFILE_PERMISSION_NORMAL) + perms = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); + else + perms = 0; + + *fd = open (filename, sflags, perms); + + if (*fd < 0) + return errno; + + return CPNATIVE_OK; +} + +JNIEXPORT int cpio_closeFile (int fd) +{ + if (close (fd) < 0) + return errno; + + return CPNATIVE_OK; +} + +JNIEXPORT int cpio_availableBytes (int fd, jlong *bytes_available) +{ +#if defined (FIONREAD) + ssize_t n; + + if (ioctl (fd, FIONREAD, (char *)&n) != 0) + return errno; + + *bytes_available = n; + return CPNATIVE_OK; +#elif defined(HAVE_FSTAT) + struct stat statBuffer; + off_t n; + int result; + + *bytes_available = 0; + if ((fstat (fd, &statBuffer) == 0) && S_ISREG (statBuffer.st_mode)) + { + n = lseek (fd, 0, SEEK_CUR); + if (n != -1) + { + *bytes_available = statBuffer.st_size - n; + result = CPNATIVE_OK; + } + else + { + result = errno; + } + } + else + { + result = errno; + } + + return result; +#elif defined(HAVE_SELECT) + fd_set filedescriptset; + struct timeval tv; + int result; + + *bytes_available = 0; + + FD_ZERO (&filedescriptset); + FD_SET (fd,&filedescriptset); + memset (&tv, 0, sizeof(tv)); + + switch (select (fd+1, &filedescriptset, NULL, NULL, &tv)) + { + case -1: + result=errno; + break; + case 0: + *bytes_available = 0; + result = CPNATIVE_OK; + break; + default: + *bytes_available = 1; + result = CPNATIVE_OK; + break; + } + return result; + +#else + *bytes_available = 0; + return ENOTSUP; +#endif +} + +JNIEXPORT int cpio_getFileSize (int fd, jlong *filesize) +{ + struct stat statBuffer; + + if (fstat(fd, &statBuffer) < 0) + return errno; + + *filesize = statBuffer.st_size; + return CPNATIVE_OK; +} + +JNIEXPORT int cpio_getFilePosition (int fd, jlong *offset) +{ + *offset = lseek (fd, 0, SEEK_CUR); + if (*offset < 0) + return errno; + + return CPNATIVE_OK; +} + +JNIEXPORT int cpio_setFilePosition (int fd, jlong position) +{ + if (lseek (fd, position, SEEK_SET) < 0) + return errno; + + return CPNATIVE_OK; +} + +JNIEXPORT int cpio_read (int fd, void *buffer, jint length, jint *bytes_read) +{ + *bytes_read = read (fd, buffer, length); + + if (*bytes_read < 0) + { + return errno; + } + + return CPNATIVE_OK; +} + +JNIEXPORT int cpio_write (int fd, const void *buffer, jint length, jint *bytes_written) +{ + *bytes_written = write (fd, buffer, length); + + if (*bytes_written < 0) + return errno; + + return CPNATIVE_OK; +} + +JNIEXPORT int cpio_fsync (int fd) +{ + if (fsync (fd) < 0) + return errno; + + return CPNATIVE_OK; +} + +JNIEXPORT int cpio_truncate (int fd, jlong size) +{ + if (ftruncate (fd, size) < 0) + return errno; + + return CPNATIVE_OK; +} + +JNIEXPORT int cpio_setFileSize (int native_fd, jlong new_size) +{ + jlong file_size; + jlong save_offset; + int result; + char data; + jint bytes_written; + + result = cpio_getFileSize (native_fd, &file_size); + if (result != CPNATIVE_OK) + return result; + + /* Save off current position */ + result = cpio_getFilePosition (native_fd, &save_offset); + if (result != CPNATIVE_OK) + return result; + + if (file_size < new_size) + { + /* File is too short -- seek to one byte short of where we want, + * then write a byte */ + + /* move to position n-1 */ + result = cpio_setFilePosition (native_fd, new_size-1); + if (result != CPNATIVE_OK) + return result; + + /* write a byte + Note: This will fail if we somehow get here in read only mode + * That shouldn't happen */ + data = '\0'; + result = cpio_write (native_fd, &data, 1, &bytes_written); + if (result != CPNATIVE_OK) + return result; + + /* Reposition file pointer to where we started if not beyond new len. */ + if (save_offset < new_size) + { + result = cpio_setFilePosition (native_fd, save_offset); + if (result != CPNATIVE_OK) + return result; + } + } + else if (new_size < file_size) + { + /* File is too long - use ftruncate if available */ + result = cpio_truncate (native_fd, new_size); + if (result != CPNATIVE_OK) + return result; + + /* Reposition file pointer when it now is beyond the end of file. */ + if (new_size < save_offset) + { + result = cpio_setFilePosition (native_fd, new_size); + if (result != CPNATIVE_OK) + return result; + } + } + + return CPNATIVE_OK; +} + +int cpio_setFileReadonly (const char *filename) +{ + struct stat statbuf; + + if (stat(filename, &statbuf) < 0) + return errno; + +#ifdef S_IWRITE + if (chmod(filename, statbuf.st_mode & ~(S_IWRITE | S_IWGRP | S_IWOTH)) < 0) + return errno; +#endif + + return 0; +} + +int cpio_chmod (const char *filename, int permissions) +{ + struct stat statbuf; + int perms = 0; + + if (stat(filename, &statbuf) < 0) + return errno; + + /* check for permission flags */ + if (permissions & CPFILE_FLAG_USR) + { + if (permissions & CPFILE_FLAG_READ) + perms |= S_IRUSR; + + if (permissions & CPFILE_FLAG_WRITE) + perms |= S_IWUSR; + + if (permissions & CPFILE_FLAG_EXEC) + perms |= S_IXUSR; + } + else + { + if (permissions & CPFILE_FLAG_READ) + perms |= (S_IRUSR | S_IRGRP | S_IROTH); + + if (permissions & CPFILE_FLAG_WRITE) + perms |= (S_IWUSR | S_IWGRP | S_IWOTH); + + if (permissions & CPFILE_FLAG_EXEC) + perms |= (S_IXUSR | S_IXGRP | S_IXOTH); + } + + if (permissions & CPFILE_FLAG_OFF) + perms = statbuf.st_mode & ~perms; + else + perms = statbuf.st_mode | perms; + + if (chmod(filename, perms) < 0) + return errno; + + return 0; +} + +JNIEXPORT long long +cpio_df (__attribute__((unused)) const char *path, + __attribute__((unused)) CPFILE_DF_TYPE type) +{ + long long result = 0L; + +#if defined(HAVE_STATVFS) + + long long scale_factor = 0L; + struct statvfs buf; + + if (statvfs (path, &buf) < 0) + return 0L; + + /* f_blocks, f_bfree and f_bavail are defined in terms of f_frsize */ + scale_factor = (long long) (buf.f_frsize); + + switch (type) + { + case TOTAL: + result = (long long) (buf.f_blocks * scale_factor); + break; + case FREE: + result = (long long) (buf.f_bfree * scale_factor); + break; + case USABLE: + result = (long long) (buf.f_bavail * scale_factor); + break; + default: + result = 0L; + break; + } + +#endif + + return result; +} + +int cpio_checkAccess (const char *filename, unsigned int flag) +{ + struct stat statbuf; + unsigned int perms = 0; + + if (stat(filename, &statbuf) < 0) + return errno; + + switch (flag) + { + case CPFILE_FLAG_READ: + perms = R_OK; + break; + + case CPFILE_FLAG_WRITE: + perms = W_OK; + break; + + case CPFILE_FLAG_EXEC: + default: + perms = X_OK; + break; + } + + return (access (filename, perms)); +} + +int cpio_isFileExists (const char *filename) +{ + struct stat statbuf; + + if (stat(filename, &statbuf) < 0) + { + return errno; + } + + return 0; +} + +int cpio_checkType (const char *filename, jint *entryType) +{ + struct stat statbuf; + + if (stat(filename, &statbuf) < 0) + return errno; + + if (S_ISDIR(statbuf.st_mode)) + *entryType = CPFILE_DIRECTORY; + else + *entryType = CPFILE_FILE; + + return 0; +} + +int cpio_getModificationTime (const char *filename, jlong *mtime) +{ + struct stat statbuf; + + if (stat(filename, &statbuf) < 0) + return errno; + + *mtime = (jlong)statbuf.st_mtime * (jlong)1000; + + return 0; +} + +int cpio_setModificationTime (const char *filename, jlong mtime) +{ + struct stat statbuf; + struct utimbuf buf; + + if (stat(filename, &statbuf) < 0) + return errno; + + buf.actime = statbuf.st_atime; + buf.modtime = mtime / 1000; + + if (utime(filename, &buf) < 0) + return errno; + + return 0; +} + +int cpio_removeFile (const char *filename) +{ + if (unlink(filename) < 0 && rmdir(filename) < 0) + return errno; + + return 0; +} + +int cpio_mkdir (const char *path) +{ + if (mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO) < 0) + return errno; + + return 0; +} + +int cpio_rename (const char *old_name, const char *new_name) +{ + if (rename(old_name, new_name) < 0) + return errno; + + return 0; +} + +int cpio_openDir (const char *dirname, void **handle) +{ + *handle = (void *)opendir(dirname); + if (*handle == NULL) + return errno; + + return 0; +} + +int cpio_closeDir (void *handle) +{ + closedir((DIR *)handle); + return 0; +} + + +int cpio_readDir (void *handle, char *filename) +{ + struct dirent *dBuf; + + errno = 0; + dBuf = readdir((DIR *)handle); + + if (dBuf == NULL) + { + /* Some OS's (OS X) return NULL on end-of-dir, but + don't set errno to anything. */ + if (errno == 0) + return ENOENT; /* Whatever. */ + return errno; + } + + strncpy (filename, dBuf->d_name, FILENAME_MAX - 1); + return 0; +} + +int +cpio_closeOnExec(int fd) +{ + if (fcntl (fd, F_SETFD, FD_CLOEXEC) == -1) + return errno; + + return 0; +} diff --git a/libjava/classpath/native/jni/native-lib/cpio.h b/libjava/classpath/native/jni/native-lib/cpio.h new file mode 100644 index 000000000..a42fe62db --- /dev/null +++ b/libjava/classpath/native/jni/native-lib/cpio.h @@ -0,0 +1,99 @@ +/* cpio.h - + Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#ifndef _CLASSPATH_IO_H_INCLUDED +#define _CLASSPATH_IO_H_INCLUDED + +#include <jni.h> + +#define CPFILE_FLAG_CREATE 0x0001 +#define CPFILE_FLAG_APPEND 0x0002 +#define CPFILE_FLAG_TRUNCATE 0x0004 +#define CPFILE_FLAG_SYNC 0x0008 +#define CPFILE_FLAG_DSYNC 0x0010 +#define CPFILE_FLAG_BINARY 0x0020 +#define CPFILE_FLAG_READ 0x0040 +#define CPFILE_FLAG_WRITE 0x0080 +#define CPFILE_FLAG_EXEC 0x0100 +#define CPFILE_FLAG_USR 0x0400 +#define CPFILE_FLAG_OFF 0x0800 + +#define CPFILE_PERMISSION_NORMAL 1 + +#define CPFILE_FLAG_READWRITE (CPFILE_FLAG_READ|CPFILE_FLAG_WRITE) + +JNIEXPORT int cpio_openFile (const char *filename, int *fd, int flags, int permissions); +JNIEXPORT int cpio_closeFile (int fd); +JNIEXPORT int cpio_availableBytes (int fd, jlong *avail); +JNIEXPORT int cpio_getFileSize (int fd, jlong *filesize); +JNIEXPORT int cpio_setFileSize (int fd, jlong filesize); +JNIEXPORT int cpio_getFilePosition (int fd, jlong *position); +JNIEXPORT int cpio_setFilePosition (int fd, jlong position); +JNIEXPORT int cpio_read (int fd, void *data, jint len, jint *bytes_read); +JNIEXPORT int cpio_write (int fd, const void *data, jint len, jint *bytes_written); +JNIEXPORT int cpio_fsync (int fd); +JNIEXPORT int cpio_truncate (int fd, jlong size); +JNIEXPORT int cpio_closeOnExec(int fd); + +#define CPFILE_FILE 0 +#define CPFILE_DIRECTORY 1 + +JNIEXPORT int cpio_setFileReadonly (const char *filename); +JNIEXPORT int cpio_chmod (const char *filename, int permissions); +JNIEXPORT int cpio_checkAccess (const char *filename, unsigned int flag); +JNIEXPORT int cpio_isFileExists (const char *filename); +JNIEXPORT int cpio_checkType (const char *filename, jint *entryType); +JNIEXPORT int cpio_getModificationTime (const char *filename, jlong *mtime); +JNIEXPORT int cpio_setModificationTime (const char *filename, jlong mtime); +JNIEXPORT int cpio_removeFile (const char *filename); +JNIEXPORT int cpio_mkdir (const char *filename); +JNIEXPORT int cpio_rename (const char *old_name, const char *new_name); + +/* to be used with cpio_df */ +typedef enum { + TOTAL = 0, + FREE, + USABLE +} CPFILE_DF_TYPE; + +JNIEXPORT long long cpio_df (const char *path, CPFILE_DF_TYPE type); + +JNIEXPORT int cpio_openDir (const char *dirname, void **handle); +JNIEXPORT int cpio_closeDir (void *handle); +JNIEXPORT int cpio_readDir (void *handle, char *filename); + +#endif diff --git a/libjava/classpath/native/jni/native-lib/cpnative.h b/libjava/classpath/native/jni/native-lib/cpnative.h new file mode 100644 index 000000000..4ba772603 --- /dev/null +++ b/libjava/classpath/native/jni/native-lib/cpnative.h @@ -0,0 +1,49 @@ +/* cpnative.h - + Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#ifndef _CLASSPATH_NATIVE_H_INCLUDED +#define _CLASSPATH_NATIVE_H_INCLUDED + +#include <errno.h> +#include <string.h> + +#define CPNATIVE_OK 0 +#define CPNATIVE_EINTR EINTR + +#define cpnative_getErrorString strerror + +#endif diff --git a/libjava/classpath/native/jni/native-lib/cpnet.c b/libjava/classpath/native/jni/native-lib/cpnet.c new file mode 100644 index 000000000..154a7dd7d --- /dev/null +++ b/libjava/classpath/native/jni/native-lib/cpnet.c @@ -0,0 +1,818 @@ +/* cpnet.c - + Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "config.h" +#include <jni.h> +#include <assert.h> +#include <sys/socket.h> +#include <sys/types.h> +#include <unistd.h> +#include <errno.h> +#include <fcntl.h> +#include <netinet/in.h> +#include <netinet/tcp.h> +#include <netdb.h> +#include <sys/time.h> +#include <unistd.h> +#include <arpa/inet.h> + +#if defined(HAVE_SYS_IOCTL_H) +#define BSD_COMP /* Get FIONREAD on Solaris2 */ +#include <sys/ioctl.h> +#endif +#if defined(HAVE_SYS_FILIO_H) /* Get FIONREAD on Solaris 2.5 */ +#include <sys/filio.h> +#endif + +#include "cpnet.h" + +#define SOCKET_DEFAULT_TIMEOUT -1 /* milliseconds */ + +static int socketTimeouts[FD_SETSIZE]; + +static jint waitForWritable(jint fd) +{ + struct timeval tv; + fd_set writeset; + int ret; + + + FD_ZERO(&writeset); + FD_SET(fd, &writeset); + if (socketTimeouts[fd] > 0) + { + tv.tv_sec = socketTimeouts[fd] / 1000; + tv.tv_usec = (socketTimeouts[fd] % 1000) * 1000; + ret = select(fd+1, NULL, &writeset, NULL, &tv); + } + else + ret = select(fd+1, NULL, &writeset, NULL, NULL); + + return (ret <= 0) ? -1 : 0; +} + +static jint waitForReadable(jint fd) +{ + struct timeval tv; + fd_set readset; + int ret; + + + FD_ZERO(&readset); + FD_SET(fd, &readset); + if (socketTimeouts[fd] > 0) + { + tv.tv_sec = socketTimeouts[fd] / 1000; + tv.tv_usec = (socketTimeouts[fd] % 1000) * 1000; + ret = select(fd+1, &readset, NULL, NULL, &tv); + } + else + ret = select(fd+1, &readset, NULL, NULL, NULL); + + return (ret <= 0) ? -1 : 0; +} + +jint cpnet_openSocketStream(JNIEnv *env UNUSED, jint *fd, jint family) +{ + *fd = socket(family, SOCK_STREAM, 0); + if (*fd == -1) + return errno; + + fcntl(*fd, F_SETFD, FD_CLOEXEC); + assert(*fd < FD_SETSIZE); + socketTimeouts[*fd] = SOCKET_DEFAULT_TIMEOUT; + return 0; +} + +jint cpnet_openSocketDatagram(JNIEnv *env UNUSED, jint *fd, jint family) +{ + *fd = socket(family, SOCK_DGRAM, 0); + if (*fd == -1) + return errno; + + fcntl(*fd, F_SETFD, FD_CLOEXEC); + assert(*fd < FD_SETSIZE); + socketTimeouts[*fd] = SOCKET_DEFAULT_TIMEOUT; + return 0; +} + +jint cpnet_shutdown (JNIEnv *env UNUSED, jint fd, jbyte flag) +{ + int ret; + int shut_flag = 0; + + if (flag == CPNET_SHUTDOWN_READ) + shut_flag = SHUT_RD; + else if (flag == CPNET_SHUTDOWN_WRITE) + shut_flag = SHUT_WR; + + ret = shutdown (fd, shut_flag); + if (ret != 0) + return errno; + return 0; +} + +jint cpnet_close(JNIEnv *env UNUSED, jint fd) +{ + if (close (fd) != 0) + return errno; + return 0; +} + +jint cpnet_listen(JNIEnv *env UNUSED, jint fd, jint queuelen) +{ + if (listen (fd, queuelen) != 0) + return errno; + return 0; +} + +jint cpnet_accept(JNIEnv *env UNUSED, jint fd, jint *newfd) +{ + if (waitForReadable (fd) < 0) + return ETIMEDOUT; + + *newfd = accept(fd, NULL, 0); + if (*newfd != 0) + return errno; + + return 0; +} + +jint cpnet_bind(JNIEnv *env UNUSED, jint fd, cpnet_address *addr) +{ + int ret; + + ret = bind(fd, (struct sockaddr *)addr->data, addr->len); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_connect(JNIEnv *env UNUSED, jint fd, cpnet_address *addr) +{ + int ret; + + /* TODO: implement socket time out */ + ret = connect(fd, (struct sockaddr *)addr->data, addr->len); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_getLocalAddr(JNIEnv *env, jint fd, cpnet_address **addr) +{ + socklen_t slen = 1024; + int ret; + + *addr = JCL_malloc(env, slen); + + slen -= sizeof(jint); + ret = getsockname(fd, (struct sockaddr *)(*addr)->data, &slen ); + if (ret != 0) + { + int err = errno; + JCL_free(env, *addr); + return err; + } + + (*addr)->len = slen; + + return 0; +} + +jint cpnet_getRemoteAddr(JNIEnv *env, jint fd, cpnet_address **addr) +{ + socklen_t slen = 1024; + int ret; + + *addr = JCL_malloc(env, slen); + + slen -= sizeof(jint); + ret = getpeername(fd, (struct sockaddr *)(*addr)->data, &slen ); + if (ret != 0) + { + int err = errno; + JCL_free(env, *addr); + return err; + } + + (*addr)->len = slen; + + return 0; +} + +jint cpnet_setBroadcast(JNIEnv *env UNUSED, jint fd, jint flag) +{ + int ret; + + ret = setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &flag, sizeof(flag)); + if (ret != 0) + return errno; + + return 0; +} + +#if defined (HAVE_MSG_NOSIGNAL) +#elif defined (HAVE_SO_NOSIGPIPE) +static int setsockopt_NOSIGPIPE (int fd) +{ + int setToTrue = 1; + return setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &setToTrue, sizeof(setToTrue)); +} +#endif + +jint cpnet_send (JNIEnv *env UNUSED, jint fd, jbyte *data, jint len, jint *bytes_sent) +{ + ssize_t ret; + + if (waitForWritable(fd) < 0) + return ETIMEDOUT; + +#if defined (HAVE_MSG_NOSIGNAL) + ret = send(fd, data, len, MSG_NOSIGNAL); +#elif defined (HAVE_SO_NOSIGPIPE) + ret = setsockopt_NOSIGPIPE(fd); + if (ret == 0) ret = send(fd, data, len, 0); +#else + /* We want SIGPIPE to be omitted. But this configuration does not have an + * option for that. + */ + ret = send(fd, data, len, 0); +#endif + if (ret < 0) + return errno; + + *bytes_sent = ret; + + return 0; +} + +jint cpnet_sendTo (JNIEnv *env UNUSED, jint fd, jbyte *data, jint len, cpnet_address *addr, jint *bytes_sent) +{ + ssize_t ret; + + if (waitForWritable(fd) < 0) + return ETIMEDOUT; + +#if defined (HAVE_MSG_NOSIGNAL) + ret = sendto(fd, data, len, MSG_NOSIGNAL, (struct sockaddr *)addr->data, + addr->len); +#elif defined (HAVE_SO_NOSIGPIPE) + ret = setsockopt_NOSIGPIPE(fd); + if (ret == 0) + { + ret = sendto(fd, data, len, 0, (struct sockaddr *)addr->data, + addr->len); + } +#else + /* We want SIGPIPE to be omitted. But this configuration does not have an + * option for that. + */ + ret = sendto(fd, data, len, 0, (struct sockaddr *)addr->data, + addr->len); +#endif + + if (ret < 0) + return errno; + + *bytes_sent = ret; + return 0; +} + +jint cpnet_recv (JNIEnv *env UNUSED, jint fd, jbyte *data, jint len, jint *bytes_recv) +{ + ssize_t ret; + + if (waitForReadable(fd) < 0) + return ETIMEDOUT; + + ret = recv(fd, data, len, 0); + if (ret < 0) + return errno; + + *bytes_recv = ret; + + return 0; +} + +jint cpnet_recvFrom (JNIEnv *env, jint fd, jbyte *data, jint len, cpnet_address **addr, jint *bytes_recv) +{ + socklen_t slen = 1024; + ssize_t ret; + + if (waitForReadable(fd) < 0) + return ETIMEDOUT; + + *addr = JCL_malloc(env, slen); + + slen -= sizeof(jint); + ret = recvfrom(fd, data, len, 0, (struct sockaddr *) (*addr)->data, &slen); + if (ret < 0) + { + int err = errno; + JCL_free(env, *addr); + return err; + } + + (*addr)->len = slen; + *bytes_recv = ret; + + return 0; +} + +jint cpnet_setSocketTCPNoDelay (JNIEnv *env UNUSED, jint fd, jint nodelay) +{ + socklen_t len = sizeof(jint); + int ret; + + ret = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &nodelay, len); + if (ret < 0) + return errno; + + return 0; +} + +jint cpnet_getSocketTCPNoDelay (JNIEnv *env UNUSED, jint fd, jint *nodelay) +{ + socklen_t len = sizeof(jint); + int ret; + + ret = getsockopt(fd, IPPROTO_TCP, TCP_NODELAY, nodelay, &len); + if (ret < 0) + return errno; + + return 0; +} + +jint cpnet_setLinger (JNIEnv *env UNUSED, jint fd, jint flag, jint value) +{ + socklen_t len = sizeof(struct linger); + int ret; + struct linger __linger; + + if (flag) + { + __linger.l_onoff = 0; + } + else + { + __linger.l_linger = value; + __linger.l_onoff = 1; + } + + ret = setsockopt(fd, SOL_SOCKET, SO_LINGER, &__linger, len); + if (ret < 0) + return errno; + + return 0; +} + +jint cpnet_getLinger (JNIEnv *env UNUSED, jint fd, jint *flag, jint *value) +{ + socklen_t slen = sizeof(struct linger); + struct linger __linger; + int ret; + + ret = getsockopt(fd, SOL_SOCKET, SO_LINGER, &__linger, &slen); + if (ret != 0) + return errno; + + *flag = __linger.l_onoff; + *value = __linger.l_linger; + + return ret; +} + +jint cpnet_setSocketTimeout (JNIEnv *env UNUSED, jint fd, jint value) +{ + socketTimeouts[fd] = value; + return 0; +} + +jint cpnet_getSocketTimeout (JNIEnv *env UNUSED, jint fd, jint *value) +{ + *value = socketTimeouts[fd]; + return 0; +} + +jint cpnet_setSendBuf (JNIEnv *env UNUSED, jint fd, jint value) +{ + int ret; + + ret = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &value, sizeof(value)); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_getSendBuf (JNIEnv *env UNUSED, jint fd, jint *value) +{ + int ret; + socklen_t slen = sizeof(*value); + + ret = getsockopt(fd, SOL_SOCKET, SO_SNDBUF, value, &slen); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_setRecvBuf (JNIEnv *env UNUSED, jint fd, jint value) +{ + int ret; + + ret = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &value, sizeof(value)); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_getRecvBuf (JNIEnv *env UNUSED, jint fd, jint *value) +{ + int ret; + socklen_t slen = sizeof(*value); + + ret = getsockopt(fd, SOL_SOCKET, SO_RCVBUF, value, &slen); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_setTTL (JNIEnv *env UNUSED, jint fd, jint value) +{ + int ret; + + ret = setsockopt(fd, IPPROTO_IP, IP_TTL, &value, sizeof(value)); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_getTTL (JNIEnv *env UNUSED, jint fd, jint *value) +{ + int ret; + socklen_t slen = sizeof(*value); + + ret = getsockopt(fd, IPPROTO_IP, IP_TTL, value, &slen); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_setMulticastIF (JNIEnv *env UNUSED, jint fd, cpnet_address *addr) +{ + int ret; + + ret = setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, (struct sockaddr *)addr->data, addr->len); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_getMulticastIF (JNIEnv *env, jint fd, cpnet_address **addr) +{ + socklen_t slen = 1024; + int ret; + + *addr = JCL_malloc(env, slen); + + slen -= sizeof(jint); + ret = getsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, (struct sockaddr *)(*addr)->data, &slen); + (*addr)->len = slen; + + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_setReuseAddress (JNIEnv *env UNUSED, jint fd, jint reuse) +{ + int ret; + + ret = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_getReuseAddress (JNIEnv *env UNUSED, jint fd, jint *reuse) +{ + int ret; + socklen_t slen = sizeof(*reuse); + + ret = getsockopt(fd, SOL_SOCKET, SO_REUSEADDR, reuse, &slen); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_setKeepAlive (JNIEnv *env UNUSED, jint fd, jint keep) +{ + int ret; + + ret = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &keep, sizeof(keep)); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_getKeepAlive (JNIEnv *env UNUSED, jint fd, jint *keep) +{ + int ret; + socklen_t slen = sizeof(*keep); + + ret = getsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, keep, &slen); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_addMembership (JNIEnv *env UNUSED, jint fd, cpnet_address *addr) +{ + struct ip_mreq req; + int ret; + struct sockaddr_in *sockaddr = (struct sockaddr_in *)addr->data; + + memset(&req, 0, sizeof(req)); + req.imr_multiaddr = sockaddr->sin_addr; + req.imr_interface.s_addr = INADDR_ANY; + ret = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &req, sizeof(req)); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_dropMembership (JNIEnv *env UNUSED, jint fd, cpnet_address *addr) +{ + struct ip_mreq req; + int ret; + struct sockaddr_in *sockaddr = (struct sockaddr_in *)addr->data; + + memset(&req, 0, sizeof(req)); + req.imr_multiaddr = sockaddr->sin_addr; + req.imr_interface.s_addr = INADDR_ANY; + ret = setsockopt(fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, &req, sizeof(req)); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_getAvailableBytes (JNIEnv *env UNUSED, jint fd, jint *availableBytes) +{ + int ret; + + ret = ioctl(fd, FIONREAD, availableBytes); + if (ret != 0) + return errno; + + return 0; +} + +jint cpnet_getHostname (JNIEnv *env UNUSED, char *hostname, jint hostname_len) +{ + int ret; + + ret = gethostname(hostname, hostname_len); + if (ret != 0) + return errno; + + hostname[hostname_len-1] = 0; + return 0; +} + +jint cpnet_getHostByName (JNIEnv *env, const char *hostname, cpnet_address ***addresses, jint *addresses_count) +{ + struct hostent hret; + struct hostent *result; + jint buflen = 1024; + int herr = 0; + int ret = 0; + int counter = 0; + cpnet_address **addr_arr; + int i; + char *buf; + + do + { + buf = (char *)JCL_malloc(env, buflen); + +#ifdef HAVE_GETHOSTBYNAME_R +# if defined(HAVE_FUNC_GETHOSTBYNAME_R_6) + ret = gethostbyname_r (hostname, &hret, buf, buflen, &result, &herr); +# elif defined(HAVE_FUNC_GETHOSTBYNAME_R_5) + result = gethostbyname_r(hostname, &hret, buf, buflen, &herr); +# elif defined(HAVE_FUNC_GETHOSTBYNAME_R_3) +# error IMPLEMENT ME! +# else +# error unknown number of arguments for gethostbyname_r +# endif +#else + hret.h_addr_list = NULL; + hret.h_addrtype = 0; + + result = gethostbyname (hostname); + if (result == NULL) + return -errno; + memcpy (&hret, result, sizeof (struct hostent)); +#endif + if (ret != 0 || result == NULL) + { + if (herr == ERANGE) + { + buflen *= 2; + JCL_free(env, buf); + continue; + } + JCL_free(env, buf); + + return -herr; + } + + break; + } + while (1); + + while (hret.h_addr_list[counter] != NULL) + counter++; + + *addresses_count = counter; + addr_arr = *addresses = JCL_malloc(env, sizeof(cpnet_address *) * counter); + switch (hret.h_addrtype) + { + case AF_INET: + for (i = 0; i < counter; i++) + { + addr_arr[i] = cpnet_newIPV4Address(env); + cpnet_bytesToIPV4Address(addr_arr[i], (jbyte *)hret.h_addr_list[i]); + } + break; +#ifdef HAVE_INET6 + case AF_INET6: + for (i = 0; i < counter; i++) + { + addr_arr[i] = cpnet_newIPV6Address(env); + cpnet_bytesToIPV6Address(addr_arr[i], (jbyte *)hret.h_addr_list[i]); + } + break; +#endif + default: + *addresses_count = 0; + JCL_free(env, addr_arr); + break; + } + + JCL_free(env, buf); + + return 0; +} + +jint cpnet_getHostByAddr (JNIEnv *env UNUSED, cpnet_address *addr, char *hostname, jint hostname_len) +{ + union + { + struct sockaddr_in *addr_v4; + struct sockaddr_in6 *addr_v6; + char *data; + } haddr; + void *raw_addr; + int addr_type; + struct hostent *ret; + int addr_len; + + haddr.data = addr->data; + + if (haddr.addr_v4->sin_family == AF_INET) + { + raw_addr = &haddr.addr_v4->sin_addr; + addr_len = sizeof(haddr.addr_v4->sin_addr); + addr_type = AF_INET; + } +#ifdef HAVE_INET6 + else if (haddr.addr_v6->sin6_family == AF_INET6) + { + raw_addr = &haddr.addr_v6->sin6_addr; + addr_type = AF_INET6; + addr_len = sizeof(haddr.addr_v6->sin6_addr); + } +#endif + else + return EINVAL; + + /* Here we do not have any thread safe call. VM implementors will have to + * do a big lock. Or it should be put on the Classpath VM interface. + */ + ret = gethostbyaddr(raw_addr, addr_len, addr_type); + if (ret == NULL) + { + /* The trouble here is how to distinguish the two cases ? */ + if (h_errno != 0) + return h_errno; + else + return errno; + + } + strncpy(hostname, ret->h_name, hostname_len); + + return 0; +} + +jint cpnet_aton (JNIEnv *env, const char *hostname, cpnet_address **addr) +{ + jbyte *bytes = NULL; + +#if defined(HAVE_INET_PTON) && defined(HAVE_INET6) + jbyte inet6_addr[16]; +#endif + +#ifdef HAVE_INET_ATON + struct in_addr laddr; + if (inet_aton (hostname, &laddr)) + { + bytes = (jbyte *) &laddr; + } +#elif defined(HAVE_INET_ADDR) +#if ! HAVE_IN_ADDR_T + typedef jint in_addr_t; +#endif + in_addr_t laddr = inet_addr (hostname); + if (laddr != (in_addr_t)(-1)) + { + bytes = (jbyte *) &laddr; + } +#endif + if (bytes) + { + *addr = cpnet_newIPV4Address(env); + cpnet_bytesToIPV4Address(*addr, bytes); + return 0; + } + +#if defined(HAVE_INET_PTON) && defined(HAVE_INET6) + if (inet_pton (AF_INET6, hostname, inet6_addr) > 0) + { + *addr = cpnet_newIPV6Address(env); + cpnet_bytesToIPV6Address(*addr, inet6_addr); + return 0; + } +#endif + + *addr = NULL; + return 0; +} + +void cpnet_freeAddresses(JNIEnv * env, cpnet_address **addr, jint addresses_count) +{ + jint i; + + for (i = 0; i < addresses_count; i++) + cpnet_freeAddress(env, addr[i]); +} diff --git a/libjava/classpath/native/jni/native-lib/cpnet.h b/libjava/classpath/native/jni/native-lib/cpnet.h new file mode 100644 index 000000000..979c363c2 --- /dev/null +++ b/libjava/classpath/native/jni/native-lib/cpnet.h @@ -0,0 +1,221 @@ +/* cpnet.h - + Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#ifndef _CLASSPATH_NET_H_INCLUDED +#define _CLASSPATH_NET_H_INCLUDED + +#include <jni.h> +#include <jcl.h> +#include <string.h> + +#include <sys/types.h> +#include <sys/socket.h> +#ifdef HAVE_NETINET_IN_SYSTM_H +#include <netinet/in_systm.h> +#endif /* HAVE_NETINET_IN_SYSTM_H */ +#include <netinet/in.h> +#ifdef HAVE_NETINET_IP_H +#include <netinet/ip.h> +#endif /* HAVE_NETINET_IP_H */ + +typedef struct { + jint len; + char data[1]; +} cpnet_address; + +#define CPNET_SHUTDOWN_READ 1 +#define CPNET_SHUTDOWN_WRITE 2 + +JNIEXPORT jint cpnet_openSocketStream(JNIEnv *env, jint *fd, jint family); +JNIEXPORT jint cpnet_openSocketDatagram(JNIEnv *env, jint *fd, jint family); +JNIEXPORT jint cpnet_shutdown (JNIEnv *env, jint fd, jbyte flag); +JNIEXPORT jint cpnet_close(JNIEnv *env, jint fd); +JNIEXPORT jint cpnet_listen(JNIEnv *env, jint fd, jint queuelen); +JNIEXPORT jint cpnet_accept(JNIEnv *env, jint fd, jint *newfd); +JNIEXPORT jint cpnet_bind(JNIEnv *env, jint fd, cpnet_address *addr); +JNIEXPORT jint cpnet_connect(JNIEnv *env, jint fd, cpnet_address *addr); +JNIEXPORT jint cpnet_getLocalAddr(JNIEnv *env, jint fd, cpnet_address **addr); +JNIEXPORT jint cpnet_getRemoteAddr(JNIEnv *env, jint fd, cpnet_address **addr); +JNIEXPORT jint cpnet_setBroadcast(JNIEnv *env, jint fd, jint flag); +JNIEXPORT jint cpnet_send (JNIEnv *env, jint fd, jbyte *data, jint len, jint *bytes_sent); +JNIEXPORT jint cpnet_sendTo (JNIEnv *env, jint fd, jbyte *data, jint len, cpnet_address *addr, jint *bytes_sent); +JNIEXPORT jint cpnet_recv (JNIEnv *env, jint fd, jbyte *data, jint len, jint *bytes_recv); +JNIEXPORT jint cpnet_recvFrom (JNIEnv *env, jint fd, jbyte *data, jint len, cpnet_address **addr, jint *bytes_recv); +JNIEXPORT jint cpnet_setSocketTCPNoDelay (JNIEnv *env, jint fd, jint nodelay); +JNIEXPORT jint cpnet_getSocketTCPNoDelay (JNIEnv *env, jint fd, jint *nodelay); +JNIEXPORT jint cpnet_setLinger (JNIEnv *env, jint fd, jint flag, jint value); +JNIEXPORT jint cpnet_getLinger (JNIEnv *env, jint fd, jint *flag, jint *value); +JNIEXPORT jint cpnet_setSocketTimeout (JNIEnv *env, jint fd, jint value); +JNIEXPORT jint cpnet_getSocketTimeout (JNIEnv *env, jint fd, jint *value); +JNIEXPORT jint cpnet_setSendBuf (JNIEnv *env, jint fd, jint value); +JNIEXPORT jint cpnet_getSendBuf (JNIEnv *env, jint fd, jint *value); +JNIEXPORT jint cpnet_setRecvBuf (JNIEnv *env, jint fd, jint value); +JNIEXPORT jint cpnet_getRecvBuf (JNIEnv *env, jint fd, jint *value); +JNIEXPORT jint cpnet_setTTL (JNIEnv *env, jint fd, jint value); +JNIEXPORT jint cpnet_getTTL (JNIEnv *env, jint fd, jint *value); +JNIEXPORT jint cpnet_setMulticastIF (JNIEnv *env, jint fd, cpnet_address *addr); +JNIEXPORT jint cpnet_getMulticastIF (JNIEnv *env, jint fd, cpnet_address **addr); +JNIEXPORT jint cpnet_setReuseAddress (JNIEnv *env, jint fd, jint reuse); +JNIEXPORT jint cpnet_getReuseAddress (JNIEnv *env, jint fd, jint *reuse); +JNIEXPORT jint cpnet_setKeepAlive (JNIEnv *env, jint fd, jint keep); +JNIEXPORT jint cpnet_getKeepAlive (JNIEnv *env, jint fd, jint *keep); +JNIEXPORT jint cpnet_getBindAddress (JNIEnv *env, jint fd, cpnet_address **addr); +JNIEXPORT jint cpnet_addMembership (JNIEnv *env, jint fd, cpnet_address *addr); +JNIEXPORT jint cpnet_dropMembership (JNIEnv *env, jint fd, cpnet_address *addr); +JNIEXPORT jint cpnet_getAvailableBytes (JNIEnv *env, jint fd, jint *availableBytes); +JNIEXPORT jint cpnet_getHostname (JNIEnv *env, char *hostname, jint hostname_len); +JNIEXPORT jint cpnet_getHostByName (JNIEnv *env, const char *hostname, cpnet_address ***adresses, jint *addresses_count); +JNIEXPORT jint cpnet_getHostByAddr (JNIEnv *env, cpnet_address *addr, char *hostname, jint hostname_len); +JNIEXPORT jint cpnet_aton (JNIEnv *env, const char *hostname, cpnet_address **addr); +JNIEXPORT void cpnet_freeAddresses(JNIEnv * env, cpnet_address **addr, jint addresses_count); + +static inline cpnet_address *cpnet_newIPV4Address(JNIEnv * env) +{ + cpnet_address *addr = (cpnet_address *)JCL_malloc(env, sizeof(cpnet_address) + sizeof(struct sockaddr_in)); + struct sockaddr_in *netaddr = (struct sockaddr_in *)&(addr->data[0]); + + addr->len = sizeof(struct sockaddr_in); + memset(netaddr, 0, addr->len); + netaddr->sin_family = AF_INET; + return addr; +} + +static inline void cpnet_setIPV4Any(cpnet_address *addr) +{ + struct sockaddr_in *netaddr = (struct sockaddr_in *)&(addr->data[0]); + + netaddr->sin_addr.s_addr = INADDR_ANY; +} + +#ifdef HAVE_INET6 +static inline cpnet_address *cpnet_newIPV6Address(JNIEnv * env) +{ + cpnet_address * addr = (cpnet_address *)JCL_malloc(env, sizeof(cpnet_address) + sizeof(struct sockaddr_in6)); + struct sockaddr_in6 *netaddr = (struct sockaddr_in6 *)&(addr->data[0]); + + addr->len = sizeof(struct sockaddr_in6); + memset(netaddr, 0, addr->len); + netaddr->sin6_family = AF_INET6; + + return addr; +} +#endif + +static inline void cpnet_freeAddress(JNIEnv * env, cpnet_address *addr) +{ + JCL_free(env, addr); +} + +static inline void cpnet_addressSetPort(cpnet_address *addr, jint port) +{ + struct sockaddr_in *ipaddr = (struct sockaddr_in *)&(addr->data[0]); + + ipaddr->sin_port = htons(port); +} + +static inline jint cpnet_addressGetPort(cpnet_address *addr) +{ + struct sockaddr_in *ipaddr = (struct sockaddr_in *)&(addr->data[0]); + + return ntohs(ipaddr->sin_port); +} + +static inline jboolean cpnet_isAddressEqual(cpnet_address *addr1, cpnet_address *addr2) +{ + if (addr1->len != addr2->len) + return JNI_FALSE; + + return memcmp(addr1->data, addr2->data, addr1->len) == 0; +} + +#ifdef HAVE_INET6 +static inline jboolean cpnet_isIPV6Address(cpnet_address *addr) +{ + struct sockaddr_in *ipaddr = (struct sockaddr_in *)&(addr->data[0]); + + return ipaddr->sin_family == AF_INET6; +} +#endif + +static inline jboolean cpnet_isIPV4Address(cpnet_address *addr) +{ + struct sockaddr_in *ipaddr = (struct sockaddr_in *)&(addr->data[0]); + + return ipaddr->sin_family == AF_INET; +} + +static inline void cpnet_IPV4AddressToBytes(cpnet_address *netaddr, jbyte *octets) +{ + struct sockaddr_in *ipaddr = (struct sockaddr_in *)&(netaddr->data[0]); + unsigned long sysaddr = ntohl(ipaddr->sin_addr.s_addr); + + octets[0] = ((sysaddr >> 24) & 0xff); + octets[1] = ((sysaddr >> 16) & 0xff); + octets[2] = ((sysaddr >> 8) & 0xff); + octets[3] = (sysaddr & 0xff); +} + +static inline void cpnet_bytesToIPV4Address(cpnet_address *netaddr, jbyte *octets) +{ + jint sysaddr; + struct sockaddr_in *ipaddr = (struct sockaddr_in *)&(netaddr->data[0]); + + sysaddr = ((jint)(unsigned char)octets[0]) << 24; + sysaddr |= ((jint)(unsigned char)octets[1]) << 16; + sysaddr |= ((jint)(unsigned char)octets[2]) << 8; + sysaddr |= ((jint)(unsigned char)octets[3]); + + ipaddr->sin_addr.s_addr = htonl(sysaddr); +} + +#ifdef HAVE_INET6 +static inline void cpnet_IPV6AddressToBytes(cpnet_address *netaddr, jbyte *octets) +{ + struct sockaddr_in6 *ipaddr = (struct sockaddr_in6 *)&(netaddr->data[0]); + + memcpy(octets, &ipaddr->sin6_addr, 16); +} + +static inline void cpnet_bytesToIPV6Address(cpnet_address *netaddr, jbyte *octets) +{ + struct sockaddr_in6 *ipaddr = (struct sockaddr_in6 *)&(netaddr->data[0]); + + memcpy(&ipaddr->sin6_addr, octets, 16); +} +#endif + +#endif diff --git a/libjava/classpath/native/jni/native-lib/cpproc.c b/libjava/classpath/native/jni/native-lib/cpproc.c new file mode 100644 index 000000000..0c80703d6 --- /dev/null +++ b/libjava/classpath/native/jni/native-lib/cpproc.c @@ -0,0 +1,141 @@ +/* cpproc.c - + Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +#include "config.h" +#include <jni.h> +#include "cpproc.h" +#include <signal.h> +#include <sys/types.h> +#include <sys/wait.h> +#include <unistd.h> +#include <errno.h> +#include <stdlib.h> + +static void close_all_fds(int *fds, int numFds) +{ + int i; + + for (i = 0; i < numFds; i++) + close(fds[i]); +} + +int cpproc_forkAndExec (char * const *commandLine, char * const * newEnviron, + int *fds, int pipe_count, pid_t *out_pid, const char *wd) +{ + int local_fds[6]; + int i; + pid_t pid; + + for (i = 0; i < (pipe_count * 2); i += 2) + { + if (pipe(&local_fds[i]) < 0) + { + int err = errno; + + close_all_fds(local_fds, i); + + return err; + } + } + + pid = fork(); + + switch (pid) + { + case 0: + dup2(local_fds[0], 0); + dup2(local_fds[3], 1); + if (pipe_count == 3) + dup2(local_fds[5], 2); + else + dup2(1, 2); + + close_all_fds(local_fds, pipe_count * 2); + + i = chdir(wd); + /* FIXME: Handle the return value */ + if (newEnviron == NULL) + execvp(commandLine[0], commandLine); + else + execve(commandLine[0], commandLine, newEnviron); + + abort(); + + break; + case -1: + { + int err = errno; + + close_all_fds(local_fds, pipe_count * 2); + return err; + } + default: + close(local_fds[0]); + close(local_fds[3]); + if (pipe_count == 3) + close(local_fds[5]); + + fds[0] = local_fds[1]; + fds[1] = local_fds[2]; + fds[2] = local_fds[4]; + *out_pid = pid; + return 0; + } + + /* keep compiler happy */ + + return 0; +} + +int cpproc_waitpid (pid_t pid, int *status, pid_t *outpid, int options) +{ + pid_t wp = waitpid(pid, status, options); + + if (wp < 0) + return errno; + + *outpid = wp; + return 0; +} + +int cpproc_kill (pid_t pid, int signal) +{ + if (kill(pid, signal) < 0) + return errno; + + return 0; +} diff --git a/libjava/classpath/native/jni/native-lib/cpproc.h b/libjava/classpath/native/jni/native-lib/cpproc.h new file mode 100644 index 000000000..5e8db5800 --- /dev/null +++ b/libjava/classpath/native/jni/native-lib/cpproc.h @@ -0,0 +1,52 @@ +/* cpproc.h - + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ +#ifndef _CLASSPATH_PROC_H_INCLUDED +#define _CLASSPATH_PROC_H_INCLUDED + +#include <sys/types.h> + +#define CPIO_EXEC_STDIN 0 +#define CPIO_EXEC_STDOUT 1 +#define CPIO_EXEC_STDERR 2 +#define CPIO_EXEC_NUM_PIPES 3 + +JNIEXPORT int cpproc_forkAndExec (char * const *commandLine, char * const * newEnviron, + int *fds, int pipe_count, pid_t *pid, const char *wd); +JNIEXPORT int cpproc_waitpid (pid_t pid, int *status, pid_t *outpid, int options); +JNIEXPORT int cpproc_kill (pid_t pid, int signal); + +#endif |