Browse Source

Fresh pull from upstream

RISCi_ATOM 4 years ago
parent
commit
f116137591
100 changed files with 2158 additions and 6054 deletions
  1. 0 114
      CONTRIBUTING.md
  2. 2 2
      admin/debootstrap/Makefile
  3. 119 0
      admin/openwisp-config/Makefile
  4. 2 2
      admin/sudo/Makefile
  5. 76 0
      admin/syslog-ng/Makefile
  6. 37 0
      admin/syslog-ng/files/syslog-ng.conf
  7. 19 0
      admin/syslog-ng/files/syslog-ng.init
  8. 0 51
      kernel/exfat-nofuse/Makefile
  9. 3 4
      lang/lua-bencode/Makefile
  10. 2 2
      lang/lualanes/Makefile
  11. 6 2
      lang/luarocks/Makefile
  12. 37 0
      lang/luarocks/patches/02_allow_configure_uname_siteconfig_adjustment.patch
  13. 1 1
      lang/node/Makefile
  14. 8 4
      lang/perl-cgi/Makefile
  15. 49 0
      lang/perl-www-curl/Makefile
  16. 74 0
      lang/perl-www-curl/patches/100-perl-www-curl_disable_curl-config_hack.patch
  17. 34 0
      lang/perl-www-curl/patches/101-skip-preprocessor-symbol.path
  18. 11 0
      lang/perl-www-curl/patches/200-fix_default_lflags.patch
  19. 2 2
      lang/perl-xml-parser/Makefile
  20. 11 0
      lang/perl/Config.in
  21. 4 3
      lang/perl/Makefile
  22. 10 6
      lang/perl/perlmod.mk
  23. 3 3
      lang/php7-pecl-dio/Makefile
  24. 0 3110
      lang/php7-pecl-dio/patches/0000-unify-line-endings.patch
  25. 0 32
      lang/php7-pecl-dio/patches/0001-fix-svn-prop.patch
  26. 0 39
      lang/php7-pecl-dio/patches/0002-fix-Wunused-variable.patch
  27. 0 39
      lang/php7-pecl-dio/patches/0003-Fix-Wmaybe-uninitialized.patch
  28. 0 42
      lang/php7-pecl-dio/patches/0004-Fix-last-build-warning-Wunused-but-set-variable-sorr.patch
  29. 0 91
      lang/php7-pecl-dio/patches/0005-Added-LICENCE-file-as-requested-in-Request-65869.patch
  30. 0 117
      lang/php7-pecl-dio/patches/0006-Replace-ZEND_FETCH_RESOURCE-macro-with-zend_fetch_re.patch
  31. 0 66
      lang/php7-pecl-dio/patches/0007-Replace-ZEND_REGISTER_RESOURCE-with-zend_register_re.patch
  32. 0 34
      lang/php7-pecl-dio/patches/0008-RETURN_STRINGL-takes-only-2-arguments.patch
  33. 0 125
      lang/php7-pecl-dio/patches/0009-Replace-zend_hash_find-with-zend_hash_str_find.patch
  34. 0 240
      lang/php7-pecl-dio/patches/0010-Replace-dio_convert_to_long.patch
  35. 0 89
      lang/php7-pecl-dio/patches/0011-Adopt-to-changed-stream-API-interface.patch
  36. 0 829
      lang/php7-pecl-dio/patches/0012-Remove-ancient-macros-TSRMLS_CC-and-TSRMLS_DC.patch
  37. 0 69
      lang/php7-pecl-dio/patches/0013-Fix-tests-for-legacy-interface.patch
  38. 0 54
      lang/php7-pecl-dio/patches/0014-Add-missing-changes-from-changed-stream-API-interfac.patch
  39. 0 48
      lang/php7-pecl-dio/patches/0015-Add-.gitignore.patch
  40. 0 44
      lang/php7-pecl-dio/patches/0016-Add-additional-baudrates.patch
  41. 16 5
      lang/php7-pecl-http/Makefile
  42. 0 0
      lang/php7-pecl-http/patches.old/100_config9-m4.patch
  43. 11 0
      lang/php7-pecl-http/patches/100_php_http_etag_bigendian_check.patch
  44. 3 2
      lang/php7/Makefile
  45. 27 16
      lang/php7/patches/0013-Add-support-for-use-of-the-system-timezone-database.patch
  46. 2 2
      lang/php7/patches/0032-Use-system-timezone.patch
  47. 24 41
      lang/php7/patches/0041-Add-patch-to-remove-build-timestamps-from-generated-.patch
  48. 29 0
      lang/php7/patches/1005-fix-asm-constraints-in-aarch64-multiply-macro.patch
  49. 3 0
      lang/php7/pecl.mk
  50. 1 1
      lang/python-cffi/Makefile
  51. 0 44
      lang/python-gmpy/Makefile
  52. 2 2
      lang/python-packages/Makefile
  53. 1 1
      lang/python-pip/Makefile
  54. 1 1
      lang/python-ply/Makefile
  55. 1 1
      lang/python-pycparser/Makefile
  56. 1 1
      lang/python-setuptools/Makefile
  57. 24 13
      lang/python/Makefile
  58. 7 6
      lang/python/files/python-host.mk
  59. 1 1
      lang/python/files/python-package-dev.mk
  60. 19 16
      lang/python/files/python-package.mk
  61. 1 1
      lang/python/files/python-version.mk
  62. 0 31
      lang/python/patches/005-fix-libffi-x86-64-configure.patch
  63. 0 15
      lang/python/patches/011-do-not-prefer-ncursesw.patch
  64. 12 0
      lang/python/patches/011-remove-setupterm-definition.patch
  65. 31 8
      lang/python3/Makefile
  66. 90 0
      lang/python3/files/python3-host.mk
  67. 3 1
      lang/python3/files/python3-package-dev.mk
  68. 2 0
      lang/python3/files/python3-package-lib2to3.mk
  69. 41 32
      lang/python3/files/python3-package.mk
  70. 13 0
      lang/python3/files/python3-version.mk
  71. 24 0
      lang/python3/patches/011-fix-ncursesw-definition-colisions.patch
  72. 72 0
      lang/python3/patches/016-adjust-config-paths.patch
  73. 226 223
      lang/ruby/Makefile
  74. 0 152
      lang/ruby/patches/001-acinclude.m4_rename_aclocal.m4.patch
  75. 2 2
      lang/ruby/ruby_find_pkgsdeps
  76. 1 1
      lang/ruby/ruby_missingfiles
  77. 13 11
      libs/boost/Makefile
  78. 5 4
      libs/boost/patches/01_fiber_fix.patch
  79. 74 0
      libs/dtc/Makefile
  80. 44 0
      libs/eventlog/Makefile
  81. 4 4
      libs/expat/Makefile
  82. 2 2
      libs/fftw3/Makefile
  83. 8 8
      libs/fftw3/patches/001-makefile.patch
  84. 8 6
      libs/glib2/Makefile
  85. 4 2
      libs/gnutls/Makefile
  86. 41 28
      libs/icu/Makefile
  87. 1 1
      libs/icu/patches/000-dont-cpy-files-from-topdirs.patch
  88. 26 0
      libs/icu/patches/001-disable-strtod_l.patch
  89. 176 0
      libs/icu/patches/CVE-2017-7867_CVE-2017-7868.patch
  90. 71 0
      libs/libcanfestival/Makefile
  91. 11 0
      libs/libcanfestival/patches/001-sigval-ref-fix.patch
  92. 33 0
      libs/libcanfestival/patches/002-makefile-gcc-linker.patch
  93. 20 0
      libs/libcanfestival/patches/003-makefile-skip-examples.patch
  94. 64 0
      libs/libcoap/Makefile
  95. 0 51
      libs/libevhtp/Makefile
  96. 0 49
      libs/libevhtp/patches/010-strcmp-endianness-fix.patch
  97. 1 0
      libs/libexif/Makefile
  98. 3 4
      libs/libextractor/Makefile
  99. 347 0
      libs/libextractor/patches/002-ffmpeg2.9_api_backport.patch
  100. 1 1
      libs/libgd/Makefile

+ 0 - 114
CONTRIBUTING.md

@@ -1,114 +0,0 @@
-# Contributing Guidelines  
-(See <http://wiki.openwrt.org/doc/devel/packages> for overall format and construction)
-
-
-### Basic guidelines
-
-All packages you commit or submit by pull-request should follow these simple guidelines:
-* Package a version which is still maintained by the upstream author.
-* Will be updated regularly to maintained and supported versions.
-* Have no dependencies outside the OpenWrt core packages or this repository feed.
-* Have been tested to compile with the correct includes and dependencies. Please also test with "Compile with full language support" found under "General Build Settings" set if language support is relevant to your package.
-* Do NOT use a rolling source file (e.g. foo-latest.tar.gz) or the head of a branch as source for the package since that would create unpredictable builds which change over time.
-* Best of all -- it works as expected!
-
-#### Makefile contents should contain:
-
-* An up-to-date copyright notice. Use OpenWrt if no other present or supply your own.
-* A (PKG_)MAINTAINER definition listing either yourself or another person in the field.
-    (E.g.: PKG_MAINTAINER:= Joe D. Hacker `<jdh@jdhs-email-provider.org`>)
-* A PKG_LICENSE tag declaring the main license of the package.
-    (E.g.: PKG_LICENSE:=GPL-2.0+) Please use SPDX identifiers if possible (see list at the bottom).
-* An optional PKG_LICENSE_FILES tag including the filenames of the license-files in the source-package.
-    (E.g.: PKG_LICENSE_FILES:=COPYING)
-* PKG_RELEASE should be initially set to 1 or reset to 1 if the software version is changed. You should increment it if the package itself has changed. For example, modifying a support script, changing configure options like --disable* or --enable* switches, or if you changed something in the package which causes the resulting binaries to be different. Changes like correcting md5sums, changing mirror URLs, adding a maintainer field or updating a comment or copyright year in a Makefile do not require a change to PKG_RELEASE.
-
-#### Commits in your pull-requests should:
-
-* Have a useful description prefixed with the package name
-    (E.g.: "foopkg: Add libzot dependency")
-* Include Signed-off-by in the comment
-    (See <https://dev.openwrt.org/wiki/SubmittingPatches#a10.Signyourwork>)
-
-### Advice on pull requests:
-
-Pull requests are the easiest way to contribute changes to git repos at Github. They are the preferred contribution method, as they offer a nice way for commenting and amending the proposed changes.
-
-* You need a local "fork" of the Github repo.
-* Use a "feature branch" for your changes. That separates the changes in the pull request from your other changes and makes it easy to edit/amend commits in the pull request. Workflow using "feature_x" as the example:
-  - Update your local git fork to the tip (of the master, usually)
-  - Create the feature branch with `git checkout -b feature_x`
-  - Edit changes and commit them locally
-  - Push them to your Github fork by `git push -u origin feature_x`. That creates the "feature_x" branch at your Github fork and sets it as the remote of this branch
-  - When you now visit Github, you should see a proposal to create a pull request
-
-* If you later need to add new commits to the pull request, you can simply commit the changes to the local branch and then use `git push` to automatically update the pull request.
-
-* If you need to change something in the existing pull request (e.g. to add a missing signed-off-by line to the commit message), you can use `git push -f` to overwrite the original commits. That is easy and safe when using a feature branch. Example workflow:
-  - Checkout the feature branch by `git checkout feature_x`
-  - Edit changes and commit them locally. If you are just updating the commit message in the last commit, you can use `git commit --amend` to do that
-  - If you added several new commits or made other changes that require cleaning up, you can use `git rebase -i HEAD~X` (X = number of commits to edit) to possibly squash some commits
-  - Push the changed commits to Github with `git push -f` to overwrite the original commits in the "feature_x" branch with the new ones. The pull request gets automatically updated
-
-### If you have commit access:
-
-* Do NOT use git push --force.
-* Do NOT commit to other maintainer's packages without their consent.
-* Use Pull Requests if you are unsure and to suggest changes to other maintainers.
-
-#### Gaining commit access:
-
-* We will gladly grant commit access to responsible contributors who have made
-  useful pull requests and / or feedback or patches to this repository or
-  OpenWrt in general. Please include your request for commit access in your
-  next pull request or ticket.
-
-### Release Branches:
-
-* Branches named "for-XX.YY" (e.g. for-14.07) are release branches.
-* These branches are built with the respective OpenWrt release and are created
-  during the release stabilisation phase.
-* Please ONLY cherry-pick or commit security and bug-fixes to these branches.
-* Do NOT add new packages and do NOT do major upgrades of packages here.
-* If you are unsure if your change is suitable, please use a pull request.
-
-### Common LICENSE tags (short list)  
-(Complete list can be found at: <http://spdx.org/licenses>)
-
-| Full Name | Identifier  |
-|---|:---|
-|Apache License 1.0|Apache-1.0|
-|Apache License 1.1|Apache-1.1|
-|Apache License 2.0|Apache-2.0|
-|Artistic License 1.0|Artistic-1.0|
-|Artistic License 1.0 (Perl)|Artistic-1.0-Perl|
-|Artistic License 1.0 w/clause 8|Artistic-1.0-cl8|
-|Artistic License 2.0|Artistic-2.0|
-|BSD 2-clause "Simplified" License|BSD-2-Clause|
-|BSD 2-clause FreeBSD License|BSD-2-Clause-FreeBSD|
-|BSD 2-clause NetBSD License|BSD-2-Clause-NetBSD|
-|BSD 3-clause "New" or "Revised" License|BSD-3-Clause|
-|BSD 3-clause Clear License|BSD-3-Clause-Clear|
-|BSD 4-clause "Original" or "Old" License|BSD-4-Clause|
-|BSD Protection License|BSD-Protection|
-|BSD with attribution|BSD-3-Clause-Attribution|
-|BSD-4-Clause (University of California-Specific)|BSD-4-Clause-UC|
-|GNU General Public License v1.0 only|GPL-1.0|
-|GNU General Public License v1.0 or later|GPL-1.0+|
-|GNU General Public License v2.0 only|GPL-2.0|
-|GNU General Public License v2.0 or later|GPL-2.0+|
-|GNU General Public License v3.0 only|GPL-3.0|
-|GNU General Public License v3.0 or later|GPL-3.0+|
-|GNU Lesser General Public License v2.1 only|LGPL-2.1|
-|GNU Lesser General Public License v2.1 or later|LGPL-2.1+|
-|GNU Lesser General Public License v3.0 only|LGPL-3.0|
-|GNU Lesser General Public License v3.0 or later|LGPL-3.0+|
-|GNU Library General Public License v2 only|LGPL-2.0|
-|GNU Library General Public License v2 or later|LGPL-2.0+|
-|Fair License|Fair|
-|ISC License|ISC|
-|MIT License|MIT|
-|No Limit Public License|NLPL|
-|OpenSSL License|OpenSSL|
-|X11 License|X11|
-|zlib License|Zlib|

+ 2 - 2
admin/debootstrap/Makefile

@@ -9,13 +9,13 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=debootstrap
-PKG_VERSION:=1.0.83
+PKG_VERSION:=1.0.87
 PKG_RELEASE:=1
 PKG_MAINTAINER:=Daniel Golle <daniel@makrotopia.org>
 
 PKG_SOURCE:=$(PKG_NAME)-udeb_$(PKG_VERSION)_all.udeb
 PKG_SOURCE_URL:=http://ftp.debian.org/debian/pool/main/d/debootstrap
-PKG_MD5SUM:=877fe5281a0e424bd6c71d121cbb725b8f56694e66558cd47c20c3aa87ceff72
+PKG_MD5SUM:=784f5754f3287ae80715d9100a4ed04e7895be5f7b81b7b2295d335dd69d79fb
 PKG_LICENSE:=Unique
 PKG_LICENSE_FILES:=debian/copyright
 

+ 119 - 0
admin/openwisp-config/Makefile

@@ -0,0 +1,119 @@
+# openwisp.org
+#
+# This is free software, licensed under the GNU General Public License v3.
+# See /LICENSE for more information.
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=openwisp-config
+PKG_VERSION:=0.4.5
+PKG_RELEASE:=1
+
+PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
+PKG_SOURCE_PROTO:=git
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
+PKG_SOURCE_URL:=https://github.com/openwisp/openwisp-config.git
+PKG_SOURCE_VERSION:=0.4.5
+PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_SOURCE_VERSION)
+PKG_MIRROR_HASH:=017a8ed35ebfda2805426e7da02559d5cc2845ee9ded60fdae8e848d377424fb
+PKG_LICENSE:=GPL-3.0
+PKGARCH:=all
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/openwisp-config/default
+	TITLE:=Remote configuration management agent ($(2) variant)
+	CATEGORY:=Administration
+	SECTION:=admin
+	SUBMENU:=openwisp
+	DEPENDS:=+curl +lua +libuci-lua +luafilesystem $(3)
+	VARIANT:=$(1)
+	MAINTAINER:=Federico Capoano <f.capoano@cineca.it>
+	URL:=http://openwisp.org
+endef
+
+Package/openwisp-config-openssl=$(call Package/openwisp-config/default,openssl,OpenSSL,+ca-certificates +libopenssl)
+Package/openwisp-config-mbedtls=$(call Package/openwisp-config/default,mbedtls,mbedTLS,+ca-certificates +libmbedtls)
+Package/openwisp-config-cyassl=$(call Package/openwisp-config/default,cyassl,CyaSSL,+ca-certificates +libcyassl)
+# deprecated on recent versions of OpenWRT (>= Designated Driver) and LEDE (>= 17.01)
+Package/openwisp-config-polarssl=$(call Package/openwisp-config/default,polarssl,PolarSSL,+ca-certificates +libpolarssl)
+Package/openwisp-config-nossl=$(call Package/openwisp-config/default,nossl,No SSL)
+
+define Build/Compile
+endef
+
+define Package/openwisp-config-$(BUILD_VARIANT)/conffiles
+/etc/config/openwisp
+endef
+
+ifeq ($(BUILD_VARIANT),openssl)
+CONFIG_OPENWISP_UCI:=ssl
+endif
+ifeq ($(BUILD_VARIANT),mbedtls)
+CONFIG_OPENWISP_UCI:=ssl
+endif
+ifeq ($(BUILD_VARIANT),cyassl)
+CONFIG_OPENWISP_UCI:=ssl
+endif
+ifeq ($(BUILD_VARIANT),polarssl)
+CONFIG_OPENWISP_UCI:=ssl
+endif
+ifeq ($(BUILD_VARIANT),nossl)
+CONFIG_OPENWISP_UCI:=nossl
+endif
+
+
+define Package/openwisp-config-$(BUILD_VARIANT)/install
+	$(INSTALL_DIR) \
+		$(1)/usr/sbin \
+		$(1)/etc/init.d \
+		$(1)/etc/config \
+		$(1)/etc/openwisp \
+		$(1)/usr/lib/lua/openwisp
+
+	$(INSTALL_BIN) \
+		$(PKG_BUILD_DIR)/openwisp-config/files/openwisp.agent \
+		$(1)/usr/sbin/openwisp_config
+
+	$(INSTALL_BIN) \
+		$(PKG_BUILD_DIR)/openwisp-config/files/openwisp.init \
+		$(1)/etc/init.d/openwisp_config
+
+	$(INSTALL_CONF) $(PKG_BUILD_DIR)/openwisp-config/files/openwisp-$(CONFIG_OPENWISP_UCI).config \
+		$(1)/etc/config/openwisp
+
+	$(INSTALL_BIN) \
+		$(PKG_BUILD_DIR)/openwisp-config/files/sbin/openwisp-reload-config \
+		$(1)/usr/sbin/openwisp-reload-config
+
+	$(INSTALL_BIN) \
+		$(PKG_BUILD_DIR)/openwisp-config/files/lib/openwisp/utils.lua \
+		$(1)/usr/lib/lua/openwisp/utils.lua
+
+	$(INSTALL_BIN) \
+		$(PKG_BUILD_DIR)/openwisp-config/files/sbin/openwisp-store-unmanaged.lua \
+		$(1)/usr/sbin/openwisp-store-unmanaged
+
+	$(INSTALL_BIN) \
+		$(PKG_BUILD_DIR)/openwisp-config/files/sbin/openwisp-restore-unmanaged.lua \
+		$(1)/usr/sbin/openwisp-restore-unmanaged
+
+	$(INSTALL_BIN) \
+		$(PKG_BUILD_DIR)/openwisp-config/files/sbin/openwisp-remove-default-wifi.lua \
+		$(1)/usr/sbin/openwisp-remove-default-wifi
+
+	$(INSTALL_BIN) \
+		$(PKG_BUILD_DIR)/openwisp-config/files/sbin/openwisp-uci-autoname.lua \
+		$(1)/usr/sbin/openwisp-uci-autoname
+
+	$(INSTALL_BIN) \
+		$(PKG_BUILD_DIR)/openwisp-config/files/sbin/openwisp-update-config.lua \
+		$(1)/usr/sbin/openwisp-update-config
+
+	$(CP) $(PKG_BUILD_DIR)/VERSION $(1)/etc/openwisp/
+endef
+
+$(eval $(call BuildPackage,openwisp-config-openssl))
+$(eval $(call BuildPackage,openwisp-config-mbedtls))
+$(eval $(call BuildPackage,openwisp-config-cyassl))
+$(eval $(call BuildPackage,openwisp-config-polarssl))
+$(eval $(call BuildPackage,openwisp-config-nossl))

+ 2 - 2
admin/sudo/Makefile

@@ -64,8 +64,8 @@ define Host/Compile
 endef
 
 define Host/Install
-	$(INSTALL_DIR) $(HOST_BUILD_PREFIX)/bin
-	$(CP) $(HOST_BUILD_DIR)/lib/util/mksig{list,name} $(HOST_BUILD_PREFIX)/bin/
+	$(INSTALL_DIR) $(STAGING_DIR_HOSTPKG)/bin
+	$(CP) $(HOST_BUILD_DIR)/lib/util/mksig{list,name} $(STAGING_DIR_HOSTPKG)/bin/
 endef
 
 $(eval $(call HostBuild))

+ 76 - 0
admin/syslog-ng/Makefile

@@ -0,0 +1,76 @@
+include  $(TOPDIR)/rules.mk
+
+PKG_NAME:=syslog-ng
+PKG_VERSION:=3.8.1
+PKG_RELEASE:=3
+
+PKG_MAINTAINER:=W. Michael Petullo <mike@flyn.org>
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=https://github.com/balabit/syslog-ng/releases/download/$(PKG_NAME)-$(PKG_VERSION)/
+PKG_MD5SUM:=acf14563cf5ce435db8db35486ce66af
+
+PKG_INSTALL:=1
+
+include $(INCLUDE_DIR)/package.mk
+include $(INCLUDE_DIR)/nls.mk
+
+define Package/syslog-ng
+  SECTION:=admin
+  CATEGORY:=Administration
+  DEPENDS:=+libpcre +glib2 +libeventlog +libopenssl +libuuid +libcurl
+  TITLE:=A powerful syslog daemon
+  URL:=http://www.balabit.com/network-security/syslog-ng/opensource-logging-system/
+endef
+
+define Package/syslog-ng/description
+  syslog-ng reads and logs messages to the system console, log
+  files, other machines and/or users as specified by its
+  configuration file.
+endef
+
+define Package/syslog-ng/conffiles
+  /etc/syslog-ng.conf
+endef
+
+define Build/Configure
+	$(SED) 's,-I/usr/include,,' $(PKG_BUILD_DIR)/configure
+	$(Build/Configure/Default)
+endef
+
+CONFIGURE_ARGS += \
+  $(call autoconf_bool,CONFIG_IPV6,ipv6) \
+         --disable-dependency-tracking \
+         --disable-ampq \
+         --disable-tcp-wrapper \
+         --disable-glibtest \
+         --disable-mongodb \
+         --disable-java \
+         --disable-json \
+         --disable-python \
+         --disable-spoof-source \
+         --disable-sql \
+         --disable-linux-caps \
+	 --disable-smtp \
+	 --disable-redis \
+         --enable-prce \
+
+TARGET_CPPFLAGS += \
+  -I$(STAGING_DIR)/usr/include/eventlog
+
+CONFIGURE_VARS += \
+  LIBDBI_CFLAGS="-I$(STAGING_DIR)/usr/include"
+
+define Package/syslog-ng/install
+	$(INSTALL_DIR) $(1)/usr/lib
+	$(MAKE) -C $(PKG_BUILD_DIR) \
+		install-sbinPROGRAMS install-libLTLIBRARIES \
+		install-moduleLTLIBRARIES DESTDIR="$(1)"
+	$(INSTALL_DIR) $(1)/etc/init.d
+	$(INSTALL_BIN) ./files/syslog-ng.init $(1)/etc/init.d/syslog-ng
+	$(INSTALL_DIR) $(1)/etc
+	$(INSTALL_DATA) ./files/syslog-ng.conf $(1)/etc
+	$(call libtool_remove_files,$(1))
+endef
+
+$(eval $(call BuildPackage,syslog-ng))

+ 37 - 0
admin/syslog-ng/files/syslog-ng.conf

@@ -0,0 +1,37 @@
+@version:3.8
+
+options {
+	chain_hostnames(no);
+	create_dirs(yes);
+	flush_lines(0);
+	keep_hostname(yes);
+	log_fifo_size(256);
+	log_msg_size(1024);
+	stats_freq(0);
+	flush_lines(0);
+	use_fqdn(no);
+};
+
+source src {
+	internal();
+	unix-stream("/dev/log");
+};
+
+source net {
+	udp(ip(0.0.0.0) port(514));
+};
+
+source kernel {
+        file("/proc/kmsg" program_override("kernel"));
+};
+
+destination messages {
+	file("/var/log/messages");
+};
+
+log {
+	source(src);
+	source(net);
+        source(kernel);
+	destination(messages);
+};

+ 19 - 0
admin/syslog-ng/files/syslog-ng.init

@@ -0,0 +1,19 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2006-2016 OpenWrt.org
+
+START=20
+
+SERVICE_USE_PID=1
+
+start() {
+	[ -f /etc/syslog-ng.conf ] || return 1
+	service_start /usr/sbin/syslog-ng
+}
+
+stop() {
+	service_stop /usr/sbin/syslog-ng
+}
+
+reload() {
+	service_reload /usr/sbin/syslog-ng
+}

+ 0 - 51
kernel/exfat-nofuse/Makefile

@@ -1,51 +0,0 @@
-#
-# Copyright (C) 2014 Bruno Randolf <br1@einfach.org>
-#
-# This is free software, licensed under the GNU General Public License v2.
-# See /LICENSE for more information.
-#
-
-include $(TOPDIR)/rules.mk
-include $(INCLUDE_DIR)/kernel.mk
-
-PKG_NAME:=exfat-nofuse
-PKG_VERSION=2016-09-26-$(PKG_SOURCE_VERSION)
-PKG_RELEASE:=1
-
-PKG_SOURCE=$(PKG_NAME)-$(PKG_VERSION).tar.gz
-PKG_SOURCE_URL:=https://github.com/dorimanx/exfat-nofuse.git
-PKG_SOURCE_PROTO:=git
-PKG_SOURCE_SUBDIR=$(PKG_NAME)-$(PKG_VERSION)
-PKG_SOURCE_VERSION:=051167ceccbe75d9d77fc4f5356f5a39a01779e8
-
-PKG_MAINTAINER:=Bruno Randolf <br1@einfach.org>
-PKG_LICENSE:=GPL-2.0
-PKG_LICENSE_FILES:=LICENSE
-
-include $(INCLUDE_DIR)/package.mk
-
-define KernelPackage/fs-exfat
-	SUBMENU:=Filesystems
-	TITLE:=ExFAT Kernel driver
-	FILES:=$(PKG_BUILD_DIR)/exfat.ko
-	AUTOLOAD:=$(call AutoLoad,30,exfat,1)
-	DEPENDS:=+kmod-nls-base @BUILD_PATENTED
-endef
-
-define KernelPackage/fs-exfat/description
-	Kernel module for ExFAT Filesytems
-endef
-
-MAKE_OPTS:= \
-	ARCH="$(LINUX_KARCH)" \
-	CROSS_COMPILE="$(TARGET_CROSS)" \
-	M="$(PKG_BUILD_DIR)"
-
-define Build/Compile
-	$(MAKE) -C "$(LINUX_DIR)" \
-		$(MAKE_OPTS) \
-		CONFIG_EXFAT_FS=m \
-		modules
-endef
-
-$(eval $(call KernelPackage,fs-exfat))

+ 3 - 4
lang/lua-bencode/Makefile

@@ -11,11 +11,10 @@ PKG_NAME:=lua-bencode
 PKG_VERSION:=2.1.0
 PKG_RELEASE:=1
 
-PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
-PKG_SOURCE_URL:=https://bitbucket.org/wilhelmy/lua-bencode
-PKG_SOURCE_PROTO:=hg
-PKG_SOURCE_VERSION:=500243383cb6acbddd3cf12aee6e4667aab53324
+PKG_SOURCE_URL:=https://bitbucket.org/wilhelmy/lua-bencode/downloads/
+PKG_HASH:=4624f33ff026bc62990a323ee4953e42d68430c38a1a4726c9cfd77c085b1422
 PKG_LICENSE:=MIT
 
 include $(INCLUDE_DIR)/package.mk

+ 2 - 2
lang/lualanes/Makefile

@@ -42,8 +42,8 @@ endef
 define Build/Compile
 	$(MAKE) -C $(PKG_BUILD_DIR) all \
         CC="$(TARGET_CC)" \
-        LUA="$(STAGING_DIR)/host/bin/lua" \
-        LUAC="$(STAGING_DIR)/host/bin/luac" \
+        LUA="$(STAGING_DIR_HOSTPKG)/bin/lua" \
+        LUAC="$(STAGING_DIR_HOSTPKG)/bin/luac" \
         OPT_FLAGS="$(TARGET_CFLAGS) --std=c99 -Dpthread_yield=sched_yield"
 endef
 

+ 6 - 2
lang/luarocks/Makefile

@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=luarocks
 PKG_VERSION:=2.2.2
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
 PKG_SOURCE_PROTO:=git
@@ -41,7 +41,11 @@ endef
 CONFIGURE_ARGS = \
     --prefix=$(CONFIGURE_PREFIX) \
     --sysconfdir=/etc \
-    --with-lua=$(STAGING_DIR)/host
+    --with-lua=$(STAGING_DIR_HOSTPKG)
+
+CONFIGURE_VARS = \
+	LUAROCKS_UNAME_S="Linux" \
+	LUAROCKS_UNAME_M="$(ARCH)"
 
 define Build/Compile
 	$(call Build/Compile/Default,build)

+ 37 - 0
lang/luarocks/patches/02_allow_configure_uname_siteconfig_adjustment.patch

@@ -0,0 +1,37 @@
+Index: luarocks-2.2.2/configure
+===================================================================
+--- luarocks-2.2.2.orig/configure
++++ luarocks-2.2.2/configure
+@@ -388,18 +388,22 @@ then
+ fi
+ 
+ echo_n "Configuring for system... "
+-if uname -s
+-then
+-   LUAROCKS_UNAME_S=`uname -s`
+-else
+-   die "Could not determine operating system. 'uname -s' failed."
++if [ -z "$LUAROCKS_UNAME_S" ]; then
++    if uname -s
++    then
++        LUAROCKS_UNAME_S=`uname -s`
++    else
++        die "Could not determine operating system. 'uname -s' failed."
++    fi
+ fi
+ echo_n "Configuring for architecture... "
+-if uname -m
+-then
+-   LUAROCKS_UNAME_M=`uname -m`
+-else
+-   die "Could not determine processor architecture. 'uname -m' failed."
++if [ -z "$LUAROCKS_UNAME_M" ]; then
++    if uname -m
++    then
++        LUAROCKS_UNAME_M=`uname -m`
++    else
++        die "Could not determine processor architecture. 'uname -m' failed."
++    fi
+ fi
+ 
+ for v in 5.1 5.2 5.3; do

+ 1 - 1
lang/node/Makefile

@@ -72,7 +72,7 @@ HOST_CONFIGURE_VARS:=
 HOST_CONFIGURE_ARGS:= \
 	--dest-os=linux \
 	--without-snapshot \
-	--prefix=$(HOST_BUILD_PREFIX)
+	--prefix=$(STAGING_DIR_HOSTPKG)
 
 HOST_CONFIGURE_CMD:=python ./configure
 

+ 8 - 4
lang/perl-cgi/Makefile

@@ -8,18 +8,22 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=perl-cgi
-PKG_VERSION:=4.28
-PKG_RELEASE:=1
+PKG_VERSION:=4.35
+PKG_RELEASE:=2
 
 PKG_SOURCE_URL:=http://www.cpan.org/authors/id/L/LE/LEEJO
 PKG_SOURCE:=CGI-$(PKG_VERSION).tar.gz
-PKG_MD5SUM:=28efb391377f6e98c19c23292d5fcc8c
+PKG_MD5SUM:=15e63942c02354426b25f056f2a4467c
 
 PKG_LICENSE:=GPL Artistic-2.0
-PKG_MAINTAINER:=Marcel Denia <naoir@gmx.net>
+PKG_MAINTAINER:=Marcel Denia <naoir@gmx.net>, \
+		Philip Prindeville <philipp@redfish-solutions.com>
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/perl/CGI-$(PKG_VERSION)
 
+# don't strip comments because that will mangle this module
+PKG_LEAVE_COMMENTS:=1
+
 include $(INCLUDE_DIR)/package.mk
 include ../perl/perlmod.mk
 

+ 49 - 0
lang/perl-www-curl/Makefile

@@ -0,0 +1,49 @@
+#
+# Copyright (C) 2014 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=perl-www-curl
+PKG_VERSION:=4.17
+PKG_RELEASE:=4
+
+PKG_SOURCE_URL:=http://www.cpan.org/authors/id/S/SZ/SZBALINT/
+PKG_SOURCE:=WWW-Curl-$(PKG_VERSION).tar.gz
+PKG_MD5SUM:=997ac81cd6b03b30b36f7cd930474845
+
+PKG_LICENSE:=GPL-1.0+ Artistic-1.0-Perl
+PKG_LICENSE_FILES:=LICENSE
+PKG_MAINTAINER:=Marcel Denia <naoir@gmx.net>
+
+PKG_BUILD_DIR:=$(BUILD_DIR)/perl/WWW-Curl-$(PKG_VERSION)
+
+include $(INCLUDE_DIR)/package.mk
+include ../perl/perlmod.mk
+
+define Package/perl-www-curl
+  SUBMENU:=Perl
+  SECTION:=lang
+  CATEGORY:=Languages
+  TITLE:=Perl bindings to libcurl
+  URL:=http://search.cpan.org/dist/WWW-Curl/
+  DEPENDS:=perl +libcurl +perlbase-essential +perlbase-xsloader
+endef
+
+define Build/Configure
+	$(call perlmod/Configure,$(STAGING_DIR)/usr/include,)
+endef
+
+define Build/Compile
+	$(call perlmod/Compile,,)
+endef
+
+define Package/perl-www-curl/install
+	$(call perlmod/Install,$(1),WWW/Curl WWW/Curl.pm auto/WWW/Curl)
+endef
+
+
+$(eval $(call BuildPackage,perl-www-curl))

+ 74 - 0
lang/perl-www-curl/patches/100-perl-www-curl_disable_curl-config_hack.patch

@@ -0,0 +1,74 @@
+--- a/Makefile.PL
++++ b/Makefile.PL
+@@ -12,31 +12,31 @@ no_index		directory => 'template';
+ repository		'http://github.com/szbalint/WWW--Curl';
+ # This is a hack. If you have libcurl installed, just specify curl.h below
+ # and comment out this line.
+-if ($^O ne 'MSWin32') {
+-    if (!$ENV{CURL_CONFIG}) {
+-	    requires_external_bin	'curl-config';
+-    }
+-} else {
+-	print	"Sorry, no automated install is available on Windows,\n".
+-		"please see the README.Win32 file on instructions for a manual install.\n";
+-	exit(0);
+-}
+-
+-my $curl_config = $ENV{CURL_CONFIG} || 'curl-config';
+-
+-my $vernum = `${curl_config} --vernum`; chomp $vernum;
+-my $version = `${curl_config} --version`; chomp $version; 
+-
+-my $minimum_ver = hex("070a08");
+-
+-if ($vernum && hex($vernum) <= $minimum_ver) {
+-	print	"Your currently installed libcurl version - $version - is too old.\n".
+-		"This module doesn't seek compatibility with versions older than 7.10.8\n".
+-		"Proceed manually if you know what you're doing.\n";
+-	exit(0);
+-}
+-
+-print "The version is $version\n";
++#if ($^O ne 'MSWin32') {
++#    if (!$ENV{CURL_CONFIG}) {
++#	    requires_external_bin	'curl-config';
++#    }
++#} else {
++#	print	"Sorry, no automated install is available on Windows,\n".
++#		"please see the README.Win32 file on instructions for a manual install.\n";
++#	exit(0);
++#}
++#
++#my $curl_config = $ENV{CURL_CONFIG} || 'curl-config';
++#
++#my $vernum = `${curl_config} --vernum`; chomp $vernum;
++#my $version = `${curl_config} --version`; chomp $version; 
++#
++#my $minimum_ver = hex("070a08");
++#
++#if ($vernum && hex($vernum) <= $minimum_ver) {
++#	print	"Your currently installed libcurl version - $version - is too old.\n".
++#		"This module doesn't seek compatibility with versions older than 7.10.8\n".
++#		"Proceed manually if you know what you're doing.\n";
++#	exit(0);
++#}
++#
++#print "The version is $version\n";
+ 
+ my @includes = qw();
+ my ($cflags,$lflags, $ldflags) = ('','','');
+@@ -58,10 +58,10 @@ if ($^O ne 'MSWin32') {
+ # Get curl to tell us where it is, if we can.
+ #
+ 
+-if ($^O ne 'MSWin32') {
+-	$cflags = `${curl_config} --cflags`;
+-	$lflags = `${curl_config} --libs`;
+-}
++#if ($^O ne 'MSWin32') {
++#	$cflags = `${curl_config} --cflags`;
++#	$lflags = `${curl_config} --libs`;
++#}
+ 
+ # can't find link flags, make some guesses
+ if (!defined($lflags)) {

+ 34 - 0
lang/perl-www-curl/patches/101-skip-preprocessor-symbol.path

@@ -0,0 +1,34 @@
+From 0be0223422e6e5f4091c6e4e058d213623eed105 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
+Date: Mon, 12 Sep 2016 14:40:44 +0200
+Subject: [PATCH] Skip preprocessor symbol only CURL_STRICTER
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+CURL_STRICTER leaked into curl-constants.c when building against
+curl-7.50.2. This is a preprocessor only macro without a value.
+
+CPAN RT#117793
+
+Signed-off-by: Petr Písař <ppisar@redhat.com>
+---
+ Makefile.PL | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/Makefile.PL b/Makefile.PL
+index f9170bb..ad2bd3d 100644
+--- a/Makefile.PL
++++ b/Makefile.PL
+@@ -127,7 +127,7 @@ if (!defined($curl_h)) {
+     close H;
+ 
+     for my $e (sort @syms) {
+-       if($e =~ /(OBSOLETE|^CURL_EXTERN|_LAST\z|_LASTENTRY\z)/) {
++       if($e =~ /(OBSOLETE|^CURL_EXTERN|^CURL_STRICTER\z|_LAST\z|_LASTENTRY\z)/) {
+           next;
+        }
+        my ($group) = $e =~ m/^([^_]+_)/;
+-- 
+2.7.4
+

+ 11 - 0
lang/perl-www-curl/patches/200-fix_default_lflags.patch

@@ -0,0 +1,11 @@
+--- a/Makefile.PL
++++ b/Makefile.PL
+@@ -39,7 +39,7 @@ repository		'http://github.com/szbalint/
+ #print "The version is $version\n";
+ 
+ my @includes = qw();
+-my ($cflags,$lflags, $ldflags) = ('','','');
++my ($cflags,$lflags, $ldflags) = ('','-lcurl','');
+ 
+ # You may need to specify where to find curl.h on your platform
+ # These are guesses only, in case curl-config is not telling us.

+ 2 - 2
lang/perl-xml-parser/Makefile

@@ -25,8 +25,8 @@ HOST_BUILD_DEPENDS:=perl/host expat/host
 
 EXPAT_LIBPATH:=$(STAGING_DIR)/usr/lib
 EXPAT_INCPATH=$(STAGING_DIR)/usr/include
-HOST_EXPAT_LIBPATH:=$(STAGING_DIR)/host/lib
-HOST_EXPAT_INCPATH=$(STAGING_DIR)/host/include
+HOST_EXPAT_LIBPATH:=$(STAGING_DIR_HOSTPKG)/lib
+HOST_EXPAT_INCPATH=$(STAGING_DIR_HOSTPKG)/include
 
 include $(INCLUDE_DIR)/package.mk
 include $(INCLUDE_DIR)/host-build.mk

+ 11 - 0
lang/perl/Config.in

@@ -17,4 +17,15 @@ config PERL_TESTS
 		Test support is still in development. Some tests will fail,
 		others are just missing completely.
 
+config PERL_NOCOMMENT
+	bool "Strip comments and pod sections from modules"
+	default y
+	help
+		Remove comments and pod sections for all perl packages.
+
+		This will descrease the size of perl libraries moderately.
+
+		Stripping occasionally gets confused and mangles valid code,
+		so disable this option if you're not pressed for space.
+
 endmenu

+ 4 - 3
lang/perl/Makefile

@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=perl
 PKG_VERSION:=5.22.1
-PKG_RELEASE:=3
+PKG_RELEASE:=4
 
 PKG_SOURCE_URL:=ftp://ftp.cpan.org/pub/CPAN/src/5.0 \
 		http://www.cpan.org/src/5.0 \
@@ -24,7 +24,8 @@ PKG_MD5SUM:=19295bbb775a3c36123161b9bf4892f1
 
 PKG_LICENSE:=GPL-1.0+ Artistic-1.0-Perl
 PKG_LICENSE_FILES:=Copying Artistic README
-PKG_MAINTAINER:=Marcel Denia <naoir@gmx.net>
+PKG_MAINTAINER:=Marcel Denia <naoir@gmx.net>, \
+		Philip Prindeville <philipp@redfish-solutions.com>
 
 # Build settings
 PKG_BUILD_DIR:=$(BUILD_DIR)/perl/$(PKG_NAME)-$(PKG_VERSION)
@@ -35,7 +36,7 @@ PKG_BUILD_PARALLEL:=1
 HOST_BUILD_PARALLEL:=1
 
 # Variables used during configuration/build
-HOST_PERL_PREFIX:=$(STAGING_DIR)/host/usr
+HOST_PERL_PREFIX:=$(STAGING_DIR_HOSTPKG)/usr
 
 # Filter -g3, it will break Compress-Raw-Zlib
 TARGET_CFLAGS_PERL:=$(patsubst -g3,-g,$(TARGET_CFLAGS))

+ 10 - 6
lang/perl/perlmod.mk

@@ -4,12 +4,12 @@
 PERL_VERSION:=5.22
 
 # Build environment
-HOST_PERL_PREFIX:=$(STAGING_DIR)/host/usr
+HOST_PERL_PREFIX:=$(STAGING_DIR_HOSTPKG)/usr
 ifneq ($(CONFIG_USE_GLIBC),)
 	EXTRA_LIBS:=bsd
 	EXTRA_LIBDIRS:=$(STAGING_DIR)/lib
 endif
-PERL_CMD:=$(STAGING_DIR)/host/usr/bin/perl$(PERL_VERSION).0
+PERL_CMD:=$(STAGING_DIR_HOSTPKG)/usr/bin/perl$(PERL_VERSION).0
 
 MOD_CFLAGS_PERL:=-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 $(TARGET_CFLAGS) $(TARGET_CPPFLAGS)
 ifdef CONFIG_PERL_THREADS
@@ -26,7 +26,7 @@ define perlmod/host/relink
 	rm -f $(1)/Makefile.aperl
 	$(MAKE) -C $(1) perl
 	$(CP) $(1)/perl $(PERL_CMD)
-	$(CP) $(1)/perl $(STAGING_DIR)/host/usr/bin/perl
+	$(CP) $(1)/perl $(STAGING_DIR_HOSTPKG)/usr/bin/perl
 endef
 
 define perlmod/host/Configure
@@ -129,9 +129,7 @@ define perlmod/Install/NoStrip
 endef
 
 
-define perlmod/Install
-	$(call perlmod/Install/NoStrip,$(1),$(2),$(3))
-
+define perlmod/_DoStrip
 	@echo "---> Stripping modules in: $(strip $(1))$(PERL_SITELIB)"
 	find $(strip $(1))$(PERL_SITELIB) -name \*.pm -or -name \*.pl | \
 	xargs -r sed -i \
@@ -141,6 +139,12 @@ define perlmod/Install
 		-e '/^#[^!"'"'"']/d'
 endef
 
+define perlmod/Install
+	$(call perlmod/Install/NoStrip,$(1),$(2),$(3))
+
+	$(if $(CONFIG_PERL_NOCOMMENT),$(if $(PKG_LEAVE_COMMENTS),,$(call perlmod/_DoStrip,$(1),$(2),$(3))))
+endef
+
 # You probably don't want to use this directly. Look at perlmod/InstallTests
 define perlmod/_InstallTests
 	$(INSTALL_DIR) $(strip $(1))

+ 3 - 3
lang/php7-pecl-dio/Makefile

@@ -8,9 +8,9 @@ include $(TOPDIR)/rules.mk
 PECL_NAME:=dio
 PECL_LONGNAME:=Direct I/O functions
 
-PKG_VERSION:=0.0.7
-PKG_RELEASE:=2
-PKG_MD5SUM:=a1a4df428a17dbe1ab4277b492dfa052
+PKG_VERSION:=0.0.9
+PKG_RELEASE:=1
+PKG_MD5SUM:=2c80b63fbbbaead856cb468955c14dc328d1262621b0c704b122d902053c8156
 
 PKG_NAME:=php7-pecl-$(PECL_NAME)
 PKG_SOURCE:=$(PECL_NAME)-$(PKG_VERSION).tgz

+ 0 - 3110
lang/php7-pecl-dio/patches/0000-unify-line-endings.patch

@@ -1,3110 +0,0 @@
---- a/dio_posix.c
-+++ b/dio_posix.c
-@@ -1,659 +1,659 @@
--/*
--   +----------------------------------------------------------------------+
--   | PHP Version 5                                                        |
--   +----------------------------------------------------------------------+
--   | Copyright (c) 2009 Melanie Rhianna Lewis                             |
--   +----------------------------------------------------------------------+
--   | This source file is subject to version 3.0 of the PHP license,       |
--   | that is bundled with this package in the file LICENSE, and is        |
--   | available through the world-wide-web at the following url:           |
--   | http://www.php.net/license/3_0.txt.                                  |
--   | If you did not receive a copy of the PHP license and are unable to   |
--   | obtain it through the world-wide-web, please send a note to          |
--   | license@php.net so we can mail you a copy immediately.               |
--   +----------------------------------------------------------------------+
--   | Author: Melanie Rhianna Lewis <cyberspice@php.net>                   |
--   +----------------------------------------------------------------------+
-- */
--
--#ifdef HAVE_CONFIG_H
--#include "config.h"
--#endif
--
--#include "php.h"
--
--#include "php_dio_common.h"
--
--/* {{{ dio_stream_mode_to_flags
-- * Convert an fopen() mode string to open() flags
-- */
--static int dio_stream_mode_to_flags(const char *mode) {
--	int  flags = 0, ch = 0, bin = 1;
--
--	switch(mode[ch++]) {
--		case 'r':
--			flags = 0;
--			break;
--		case 'w':
--			flags = O_TRUNC | O_CREAT;
--			break;
--		case 'a':
--			flags = O_APPEND | O_CREAT;
--			break;
--		case 'x':
--			flags = O_EXCL | O_CREAT;
--			break;
--	}
--
--	if (mode[ch] != '+') {
--		bin = (mode[ch++] == 'b');
--	}
--
--	if (mode[ch] == '+') {
--		flags |= O_RDWR;
--	} else if (flags) {
--		flags |= O_WRONLY;
--	} else {
--		flags |= O_RDONLY;
--	}
--
--#if defined(_O_TEXT) && defined(O_BINARY)
--	if (bin) {
--		flags |= O_BINARY;
--	} else {
--		flags |= _O_TEXT;
--	}
--#endif
--
--	return flags;
--}
--/* }}} */
--
--/* {{{ dio_data_rate_to_define
-- * Converts a numeric data rate to a termios define
-- */
--static int dio_data_rate_to_define(long rate, speed_t *def) {
--	speed_t val;
--
--	switch (rate) {
--		case 0:
--			val = 0;
--			break;
--		case 50:
--			val = B50;
--			break;
--		case 75:
--			val = B75;
--			break;
--		case 110:
--			val = B110;
--			break;
--		case 134:
--			val = B134;
--			break;
--		case 150:
--			val = B150;
--			break;
--		case 200:
--			val = B200;
--			break;
--		case 300:
--			val = B300;
--			break;
--		case 600:
--			val = B600;
--			break;
--		case 1200:
--			val = B1200;
--			break;
--		case 1800:
--			val = B1800;
--			break;
--		case 2400:
--			val = B2400;
--			break;
--		case 4800:
--			val = B4800;
--			break;
--		case 9600:
--			val = B9600;
--			break;
--		case 19200:
--			val = B19200;
--			break;
--		case 38400:
--			val = B38400;
--			break;
--#ifdef B57600
--		case 57600:
--			val = B57600;
--			break;
--#endif
--#ifdef B115200
--		case 115200:
--			val = B115200;
--			break;
--#endif
--#ifdef B230400
--		case 230400:
--			val = B230400;
--			break;
--#endif
--#ifdef B460800
--		case 460800:
--			val = B460800;
--			break;
--#endif
--		default:
--			return 0;
--	}
--
--	*def = val;
--	return 1;
--}
--
--/* {{{ dio_data_bits_to_define
-- * Converts a number of data bits to a termios define
-- */
--static int dio_data_bits_to_define(int data_bits, int *def) {
--	int val;
--
--	switch (data_bits) {
--		case 8:
--			val = CS8;
--			break;
--		case 7:
--			val = CS7;
--			break;
--		case 6:
--			val = CS6;
--			break;
--		case 5:
--			val = CS5;
--			break;
--		default:
--			return 0;
--	}
--
--	*def = val;
--	return 1;
--}
--/* }}} */
--
--/* {{{ dio_stop_bits_to_define
-- * Converts a number of stop bits to a termios define
-- */
--static int dio_stop_bits_to_define(int stop_bits, int *def) {
--	int val;
--
--	switch (stop_bits) {
--		case 1:
--			val = 0;
--			break;
--		case 2:
--			val = CSTOPB;
--			break;
--		default:
--			return 0;
--	}
--
--	*def = val;
--	return 1;
--}
--/* }}} */
--
--/* {{{ dio_parity_to_define
-- * Converts a parity type to a termios define
-- */
--static int dio_parity_to_define(int parity, int *def) {
--	int val;
--
--	switch (parity) {
--		case 0:
--			val = 0;
--			break;
--		case 1:
--			val = PARENB | PARODD;
--			break;
--		case 2:
--			val = PARENB;
--			break;
--		default:
--			return 0;
--	}
--
--	*def = val;
--	return 1;
--}
--/* }}} */
--
--/* {{{ dio_create_stream_data
-- * Creates an initialised stream data structure.  Free with efree().
-- */
--php_dio_stream_data * dio_create_stream_data(void) {
--	php_dio_posix_stream_data * data = emalloc(sizeof(php_dio_posix_stream_data));
--	dio_init_stream_data(&(data->common));
--	data->fd = -1;
--	data->flags = 0;
--
--	return (php_dio_stream_data *)data;
--}
--/* }}} */
--
--/* {{{ dio_common_write
-- * Writes count chars from the buffer to the stream described by the stream data.
-- */
--size_t dio_common_write(php_dio_stream_data *data, const char *buf, size_t count) {
--	size_t ret;
--
--	/* Blocking writes can be interrupted by signals etc. If
--	 * interrupted try again. Not sure about non-blocking
--	 * writes but it doesn't hurt to check. */
--	do {
--		ret = write(((php_dio_posix_stream_data*)data)->fd, buf, count);
--		if (ret > 0) {
--			return ret;
--		}
--	} while (errno == EINTR);
--	return 0;
--}
--/* }}} */
--
--#ifdef DIO_NONBLOCK
--/* {{{ dio_timeval_subtract
-- * Calculates the difference between two timevals returning the result in the
-- * structure pointed to by diffptr.  Returns -1 as error if late time is
-- * earlier than early time.
-- */
--static int dio_timeval_subtract(struct timeval *late, struct timeval *early, struct timeval *diff) {
--	struct timeval *tmp;
--
--	/* Handle negatives */
--	if (late->tv_sec < early->tv_sec) {
--		return 0;
--	}
--
--	if ((late->tv_sec == early->tv_sec) && (late->tv_usec < early->tv_usec)) {
--		return 0;
--	}
--
--	/* Handle any carry.  If later usec is smaller than earlier usec simple
--	 * subtraction will result in negative value.  Since usec has a maximum
--	 * of one second by adding another second before the subtraction the
--	 * result will always be positive. */
--	if (late->tv_usec < early->tv_usec) {
--		late->tv_usec  += 1000000;
--		late->tv_sec--;
--	}
--
--	/* Once adjusted can just subtract values. */
--	diff->tv_sec  = late->tv_sec  - early->tv_sec;
--	diff->tv_usec = late->tv_usec - early->tv_usec;
--
--	return 1;
--}
--#endif
--
--/* {{{ dio_common_read
-- * Reads count chars to the buffer to the stream described by the stream data.
-- */
--size_t dio_common_read(php_dio_stream_data *data, const char *buf, size_t count) {
--	int fd = ((php_dio_posix_stream_data*)data)->fd;
--	size_t ret, total = 0;
--	char *ptr = (char*)buf;
--
--	struct timeval timeout, timeouttmp, before, after, diff;
--	fd_set rfds;
--
--	if (!data->has_timeout) {
--		/* Blocking reads can be interrupted by signals etc. If
--		 * interrupted try again. Not sure about non-blocking
--		 * reads but it doesn't hurt to check. */
--		do {
--			ret = read(fd, (char*)ptr, count);
--			if (ret > 0) {
--				return ret;
--			} else if (!ret) {
--				data->end_of_file = 1;
--			}
--		} while ((errno == EINTR) && !data->end_of_file);
--		return 0;
--	}
--#ifdef DIO_NONBLOCK
--	else {
--		/* Clear timed out flag */
--		data->timed_out = 0;
--
--		/* The initial timeout value */
--		timeout.tv_sec  = data->timeout_sec;
--		timeout.tv_usec = data->timeout_usec;
--
--		do {
--			/* The semantics of select() are that you cannot guarantee
--			 * that the timeval structure passed in has not been changed by
--			 * the select call.  So you keep a copy. */
--			timeouttmp = timeout;
--
--			/* The time before we wait for data. */
--			(void) gettimeofday(&before, NULL);
--
--			/* Wait for an event on our file descriptor. */
--			FD_ZERO(&rfds);
--			FD_SET(fd, &rfds);
--
--			ret = select(fd + 1, &rfds, NULL, NULL, &timeouttmp);
--			/* An error. */
--			if ((ret < 0) && (errno != EINTR) && (errno != EAGAIN)) {
--				return 0;
--			}
--
--			/* We have data to read. */
--			if ((ret > 0) && FD_ISSET(fd, &rfds)) {
--				ret = read(fd, ptr, count);
--				/* Another error */
--				if ((ret < 0) && (errno != EINTR) && (errno != EAGAIN)) {
--					return 0;
--				}
--
--				if (ret > 0) {
--					/* Got data, add it to the buffer. */
--					ptr   += ret;
--					total += ret;
--					count -= ret;
--				} else if (!ret) {
--					/* This should never happen since how can we have
--					 * data to read at an end of file, but still
--					 * just in case! */
--					data->end_of_file = 1;
--					break;
--				}
--			}
--
--			/* If not timed out and not end of file and not all data read
--			 * calculate how long it took us and loop if we still have time
--			 * out time left. */
--			if (count) {
--				(void) gettimeofday(&after, NULL);
--
--				/* Diff the timevals */
--				(void) dio_timeval_subtract(&after, &before, &diff);
--
--				/* Now adjust the timeout. */
--				if (!dio_timeval_subtract(&timeout, &diff, &timeout)) {
--					/* If it errors we've run out of time. */
--					data->timed_out = 1;
--					break;
--				} else if (!timeout.tv_sec && !(timeout.tv_usec / 1000)) {
--					/* Check for rounding issues (millisecond accuracy) */
--					data->timed_out = 1;
--					break;
--				}
--			}
--		} while (count); /* Until time out or end of file or all data read. */
--
--		return total;
--	}
--#endif
--}
--/* }}} */
--
--/* {{{ php_dio_stream_data
-- * Closes the php_stream.
-- */
--int dio_common_close(php_dio_stream_data *data) {
--	if (close(((php_dio_posix_stream_data*)data)->fd) < 0) {
--		return 0;
--	}
--
--	return 1;
--}
--/* }}} */
--
--/* {{{ dio_common_set_option
-- * Sets/gets stream options
-- */
--int dio_common_set_option(php_dio_stream_data *data, int option, int value, void *ptrparam) {
--	int fd = ((php_dio_posix_stream_data*)data)->fd;
--	int old_is_blocking;
--	int flags;
--
--	switch (option) {
--#ifdef DIO_NONBLOCK
--		case PHP_STREAM_OPTION_READ_TIMEOUT:
--			if (ptrparam) {
--				struct timeval *tv = (struct timeval*)ptrparam;
--
--				flags = fcntl(fd, F_GETFL, 0);
--
--				/* A timeout of zero seconds and zero microseconds disables
--				   any existing timeout. */
--				if (tv->tv_sec || tv->tv_usec) {
--					data->timeout_sec = tv->tv_sec;
--					data->timeout_usec = tv->tv_usec;
--					data->has_timeout = -1;
--					(void) fcntl(fd, F_SETFL, flags & ~DIO_NONBLOCK);
--				} else {
--					data->timeout_sec = 0;
--					data->timeout_usec = 0;
--					data->has_timeout = 0;
--					data->timed_out = 0;
--					(void) fcntl(fd, F_SETFL, flags | DIO_NONBLOCK);
--				}
--
--				return PHP_STREAM_OPTION_RETURN_OK;
--			} else {
--				return PHP_STREAM_OPTION_RETURN_ERR;
--			}
--
--		case PHP_STREAM_OPTION_BLOCKING:
--			flags = fcntl(fd, F_GETFL, 0);
--			if (value) {
--				flags &= ~DIO_NONBLOCK;
--			} else {
--				flags |= DIO_NONBLOCK;
--			}
--			(void) fcntl(fd, F_SETFL, flags);
--
--			old_is_blocking = data->is_blocking;
--			data->is_blocking = value;
--			return old_is_blocking ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR;
--#endif /* O_NONBLOCK */
--
--		default:
--			break;
--	}
--
--	return 1;
--}
--/* }}} */
--
--/* {{{ dio_raw_open_stream
-- * Opens the underlying stream.
-- */
--int dio_raw_open_stream(char *filename, char *mode, php_dio_stream_data *data TSRMLS_DC) {
--	php_dio_posix_stream_data *pdata = (php_dio_posix_stream_data*)data;
--	pdata->flags = dio_stream_mode_to_flags(mode);
--
--#ifdef DIO_NONBLOCK
--	if (!data->is_blocking || data->has_timeout) {
--		pdata->flags |= DIO_NONBLOCK;
--	}
--#endif
--
--	/* Open the file and handle any errors. */
--#ifdef DIO_HAS_FILEPERMS
--	if (data->has_perms) {
--		pdata->fd = open(filename, pdata->flags, (mode_t)data->perms);
--	} else {
--		pdata->fd = open(filename, pdata->flags);
--	}
--#else
--	pdata->fd = open(filename, pdata->flags);
--#endif
--
--	if (pdata->fd < 0) {
--		switch (errno) {
--			case EEXIST:
--				php_error_docref(NULL TSRMLS_CC, E_WARNING, "File exists!");
--				return 0;
--			default:
--				return 0;
--		}
--	}
--
--	return 1;
--}
--/* }}} */
--
--/* {{{ dio_serial_init
-- * Initialises the serial settings storing the original settings before hand.
-- */
--static int dio_serial_init(php_dio_stream_data *data TSRMLS_DC) {
--	php_dio_posix_stream_data *pdata = (php_dio_posix_stream_data*)data;
--	int ret = 0, data_bits_def, stop_bits_def, parity_def;
--	struct termios tio;
--	speed_t rate_def;
--
--	if (!dio_data_rate_to_define(data->data_rate, &rate_def)) {
--		php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid data_rate value (%ld)", data->data_rate);
--		return 0;
--	}
--
--	if (!dio_data_bits_to_define(data->data_bits, &data_bits_def)) {
--		php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid data_bits value (%d)", data->data_bits);
--		return 0;
--	}
--
--	if (!dio_stop_bits_to_define(data->stop_bits, &stop_bits_def)) {
--		php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid stop_bits value (%d)", data->stop_bits);
--		return 0;
--	}
--
--	if (!dio_parity_to_define(data->parity, &parity_def)) {
--		php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid parity value (%d)", data->parity);
--		return 0;
--	}
--
--	ret = tcgetattr(pdata->fd, &(pdata->oldtio));
--	if (ret < 0) {
--		if ((errno == ENOTTY) || (errno == ENODEV)) {
--			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not a serial port or terminal!");
--		}
--		return 0;
--	}
--
--	ret = tcgetattr(pdata->fd, &tio);
--	if (ret < 0) {
--		return 0;
--	}
--
--	if (data->canonical) {
--		tio.c_iflag = IGNPAR | ICRNL;
--		tio.c_oflag = 0;
--		tio.c_lflag = ICANON;
--	} else {
--		cfmakeraw(&tio);
--	}
--
--	cfsetispeed(&tio, rate_def);
--	cfsetospeed(&tio, rate_def);
--
--	tio.c_cflag &= ~CSIZE;
--	tio.c_cflag |= data_bits_def;
--	tio.c_cflag &= ~CSTOPB;
--	tio.c_cflag |= stop_bits_def;
--	tio.c_cflag &= ~(PARENB|PARODD);
--	tio.c_cflag |= parity_def;
--
--#ifdef CRTSCTS
--	tio.c_cflag &= ~(CLOCAL | CRTSCTS);
--#else
--	tio.c_cflag &= ~CLOCAL;
--#endif
--	if (!data->flow_control) {
--		tio.c_cflag |= CLOCAL;
--#ifdef CRTSCTS
--	} else {
--		tio.c_cflag |= CRTSCTS;
--#endif
--	}
--
--	ret = tcsetattr(pdata->fd, TCSANOW, &tio);
--	if (ret < 0) {
--		return 0;
--	}
--
--	return 1;
--}
--/* }}} */
--
--/* {{{ dio_serial_uninit
-- * Restores the serial settings back to their original state.
-- */
--int dio_serial_uninit(php_dio_stream_data *data) {
--	php_dio_posix_stream_data *pdata = (php_dio_posix_stream_data*)data;
--	int ret;
--
--	do {
--		ret = tcsetattr(pdata->fd, TCSANOW, &(pdata->oldtio));
--	} while ((ret < 0) && (errno == EINTR));
--
--	return 1;
--}
--/* }}} */
--
--/* {{{ dio_serial_flush
-- * Purges the serial buffers of data.
-- */
--int dio_serial_purge(php_dio_stream_data *data) {
--	php_dio_posix_stream_data *pdata = (php_dio_posix_stream_data*)data;
--	int ret;
--
--	if ((pdata->flags & O_RDWR) == O_RDWR) {
--		ret = tcflush(pdata->fd, TCIOFLUSH);
--	} else if ((pdata->flags & O_WRONLY) == O_WRONLY) {
--		ret = tcflush(pdata->fd, TCOFLUSH);
--	} else if ((pdata->flags & O_RDONLY) == O_RDONLY) {
--		ret = tcflush(pdata->fd, TCIFLUSH);
--	}
--
--	if (ret < 0) {
--		return 0;
--	}
--
--	return 1;
--}
--/* }}} */
--
--/* {{{ dio_serial_open_stream
-- * Opens the underlying stream.
-- */
--int dio_serial_open_stream(char *filename, char *mode, php_dio_stream_data *data TSRMLS_DC) {
--	php_dio_posix_stream_data *pdata = (php_dio_posix_stream_data*)data;
--
--#ifdef O_NOCTTY
--	/* We don't want a controlling TTY */
--	pdata->flags |= O_NOCTTY;
--#endif
--
--	if (!dio_raw_open_stream(filename, mode, data TSRMLS_CC)) {
--		return 0;
--	}
--
--	if (!dio_serial_init(data TSRMLS_CC)) {
--		close(pdata->fd);
--		return 0;
--	}
--
--	return 1;
--}
--/* }}} */
--
--/*
-- * Local variables:
-- * c-basic-offset: 4
-- * tab-width: 4
-- * End:
-- * vim600: fdm=marker
-- * vim: sw=4 ts=4 noet
-- */
-+/*
-+   +----------------------------------------------------------------------+
-+   | PHP Version 5                                                        |
-+   +----------------------------------------------------------------------+
-+   | Copyright (c) 2009 Melanie Rhianna Lewis                             |
-+   +----------------------------------------------------------------------+
-+   | This source file is subject to version 3.0 of the PHP license,       |
-+   | that is bundled with this package in the file LICENSE, and is        |
-+   | available through the world-wide-web at the following url:           |
-+   | http://www.php.net/license/3_0.txt.                                  |
-+   | If you did not receive a copy of the PHP license and are unable to   |
-+   | obtain it through the world-wide-web, please send a note to          |
-+   | license@php.net so we can mail you a copy immediately.               |
-+   +----------------------------------------------------------------------+
-+   | Author: Melanie Rhianna Lewis <cyberspice@php.net>                   |
-+   +----------------------------------------------------------------------+
-+ */
-+
-+#ifdef HAVE_CONFIG_H
-+#include "config.h"
-+#endif
-+
-+#include "php.h"
-+
-+#include "php_dio_common.h"
-+
-+/* {{{ dio_stream_mode_to_flags
-+ * Convert an fopen() mode string to open() flags
-+ */
-+static int dio_stream_mode_to_flags(const char *mode) {
-+	int  flags = 0, ch = 0, bin = 1;
-+
-+	switch(mode[ch++]) {
-+		case 'r':
-+			flags = 0;
-+			break;
-+		case 'w':
-+			flags = O_TRUNC | O_CREAT;
-+			break;
-+		case 'a':
-+			flags = O_APPEND | O_CREAT;
-+			break;
-+		case 'x':
-+			flags = O_EXCL | O_CREAT;
-+			break;
-+	}
-+
-+	if (mode[ch] != '+') {
-+		bin = (mode[ch++] == 'b');
-+	}
-+
-+	if (mode[ch] == '+') {
-+		flags |= O_RDWR;
-+	} else if (flags) {
-+		flags |= O_WRONLY;
-+	} else {
-+		flags |= O_RDONLY;
-+	}
-+
-+#if defined(_O_TEXT) && defined(O_BINARY)
-+	if (bin) {
-+		flags |= O_BINARY;
-+	} else {
-+		flags |= _O_TEXT;
-+	}
-+#endif
-+
-+	return flags;
-+}
-+/* }}} */
-+
-+/* {{{ dio_data_rate_to_define
-+ * Converts a numeric data rate to a termios define
-+ */
-+static int dio_data_rate_to_define(long rate, speed_t *def) {
-+	speed_t val;
-+
-+	switch (rate) {
-+		case 0:
-+			val = 0;
-+			break;
-+		case 50:
-+			val = B50;
-+			break;
-+		case 75:
-+			val = B75;
-+			break;
-+		case 110:
-+			val = B110;
-+			break;
-+		case 134:
-+			val = B134;
-+			break;
-+		case 150:
-+			val = B150;
-+			break;
-+		case 200:
-+			val = B200;
-+			break;
-+		case 300:
-+			val = B300;
-+			break;
-+		case 600:
-+			val = B600;
-+			break;
-+		case 1200:
-+			val = B1200;
-+			break;
-+		case 1800:
-+			val = B1800;
-+			break;
-+		case 2400:
-+			val = B2400;
-+			break;
-+		case 4800:
-+			val = B4800;
-+			break;
-+		case 9600:
-+			val = B9600;
-+			break;
-+		case 19200:
-+			val = B19200;
-+			break;
-+		case 38400:
-+			val = B38400;
-+			break;
-+#ifdef B57600
-+		case 57600:
-+			val = B57600;
-+			break;
-+#endif
-+#ifdef B115200
-+		case 115200:
-+			val = B115200;
-+			break;
-+#endif
-+#ifdef B230400
-+		case 230400:
-+			val = B230400;
-+			break;
-+#endif
-+#ifdef B460800
-+		case 460800:
-+			val = B460800;
-+			break;
-+#endif
-+		default:
-+			return 0;
-+	}
-+
-+	*def = val;
-+	return 1;
-+}
-+
-+/* {{{ dio_data_bits_to_define
-+ * Converts a number of data bits to a termios define
-+ */
-+static int dio_data_bits_to_define(int data_bits, int *def) {
-+	int val;
-+
-+	switch (data_bits) {
-+		case 8:
-+			val = CS8;
-+			break;
-+		case 7:
-+			val = CS7;
-+			break;
-+		case 6:
-+			val = CS6;
-+			break;
-+		case 5:
-+			val = CS5;
-+			break;
-+		default:
-+			return 0;
-+	}
-+
-+	*def = val;
-+	return 1;
-+}
-+/* }}} */
-+
-+/* {{{ dio_stop_bits_to_define
-+ * Converts a number of stop bits to a termios define
-+ */
-+static int dio_stop_bits_to_define(int stop_bits, int *def) {
-+	int val;
-+
-+	switch (stop_bits) {
-+		case 1:
-+			val = 0;
-+			break;
-+		case 2:
-+			val = CSTOPB;
-+			break;
-+		default:
-+			return 0;
-+	}
-+
-+	*def = val;
-+	return 1;
-+}
-+/* }}} */
-+
-+/* {{{ dio_parity_to_define
-+ * Converts a parity type to a termios define
-+ */
-+static int dio_parity_to_define(int parity, int *def) {
-+	int val;
-+
-+	switch (parity) {
-+		case 0:
-+			val = 0;
-+			break;
-+		case 1:
-+			val = PARENB | PARODD;
-+			break;
-+		case 2:
-+			val = PARENB;
-+			break;
-+		default:
-+			return 0;
-+	}
-+
-+	*def = val;
-+	return 1;
-+}
-+/* }}} */
-+
-+/* {{{ dio_create_stream_data
-+ * Creates an initialised stream data structure.  Free with efree().
-+ */
-+php_dio_stream_data * dio_create_stream_data(void) {
-+	php_dio_posix_stream_data * data = emalloc(sizeof(php_dio_posix_stream_data));
-+	dio_init_stream_data(&(data->common));
-+	data->fd = -1;
-+	data->flags = 0;
-+
-+	return (php_dio_stream_data *)data;
-+}
-+/* }}} */
-+
-+/* {{{ dio_common_write
-+ * Writes count chars from the buffer to the stream described by the stream data.
-+ */
-+size_t dio_common_write(php_dio_stream_data *data, const char *buf, size_t count) {
-+	size_t ret;
-+
-+	/* Blocking writes can be interrupted by signals etc. If
-+	 * interrupted try again. Not sure about non-blocking
-+	 * writes but it doesn't hurt to check. */
-+	do {
-+		ret = write(((php_dio_posix_stream_data*)data)->fd, buf, count);
-+		if (ret > 0) {
-+			return ret;
-+		}
-+	} while (errno == EINTR);
-+	return 0;
-+}
-+/* }}} */
-+
-+#ifdef DIO_NONBLOCK
-+/* {{{ dio_timeval_subtract
-+ * Calculates the difference between two timevals returning the result in the
-+ * structure pointed to by diffptr.  Returns -1 as error if late time is
-+ * earlier than early time.
-+ */
-+static int dio_timeval_subtract(struct timeval *late, struct timeval *early, struct timeval *diff) {
-+	struct timeval *tmp;
-+
-+	/* Handle negatives */
-+	if (late->tv_sec < early->tv_sec) {
-+		return 0;
-+	}
-+
-+	if ((late->tv_sec == early->tv_sec) && (late->tv_usec < early->tv_usec)) {
-+		return 0;
-+	}
-+
-+	/* Handle any carry.  If later usec is smaller than earlier usec simple
-+	 * subtraction will result in negative value.  Since usec has a maximum
-+	 * of one second by adding another second before the subtraction the
-+	 * result will always be positive. */
-+	if (late->tv_usec < early->tv_usec) {
-+		late->tv_usec  += 1000000;
-+		late->tv_sec--;
-+	}
-+
-+	/* Once adjusted can just subtract values. */
-+	diff->tv_sec  = late->tv_sec  - early->tv_sec;
-+	diff->tv_usec = late->tv_usec - early->tv_usec;
-+
-+	return 1;
-+}
-+#endif
-+
-+/* {{{ dio_common_read
-+ * Reads count chars to the buffer to the stream described by the stream data.
-+ */
-+size_t dio_common_read(php_dio_stream_data *data, const char *buf, size_t count) {
-+	int fd = ((php_dio_posix_stream_data*)data)->fd;
-+	size_t ret, total = 0;
-+	char *ptr = (char*)buf;
-+
-+	struct timeval timeout, timeouttmp, before, after, diff;
-+	fd_set rfds;
-+
-+	if (!data->has_timeout) {
-+		/* Blocking reads can be interrupted by signals etc. If
-+		 * interrupted try again. Not sure about non-blocking
-+		 * reads but it doesn't hurt to check. */
-+		do {
-+			ret = read(fd, (char*)ptr, count);
-+			if (ret > 0) {
-+				return ret;
-+			} else if (!ret) {
-+				data->end_of_file = 1;
-+			}
-+		} while ((errno == EINTR) && !data->end_of_file);
-+		return 0;
-+	}
-+#ifdef DIO_NONBLOCK
-+	else {
-+		/* Clear timed out flag */
-+		data->timed_out = 0;
-+
-+		/* The initial timeout value */
-+		timeout.tv_sec  = data->timeout_sec;
-+		timeout.tv_usec = data->timeout_usec;
-+
-+		do {
-+			/* The semantics of select() are that you cannot guarantee
-+			 * that the timeval structure passed in has not been changed by
-+			 * the select call.  So you keep a copy. */
-+			timeouttmp = timeout;
-+
-+			/* The time before we wait for data. */
-+			(void) gettimeofday(&before, NULL);
-+
-+			/* Wait for an event on our file descriptor. */
-+			FD_ZERO(&rfds);
-+			FD_SET(fd, &rfds);
-+
-+			ret = select(fd + 1, &rfds, NULL, NULL, &timeouttmp);
-+			/* An error. */
-+			if ((ret < 0) && (errno != EINTR) && (errno != EAGAIN)) {
-+				return 0;
-+			}
-+
-+			/* We have data to read. */
-+			if ((ret > 0) && FD_ISSET(fd, &rfds)) {
-+				ret = read(fd, ptr, count);
-+				/* Another error */
-+				if ((ret < 0) && (errno != EINTR) && (errno != EAGAIN)) {
-+					return 0;
-+				}
-+
-+				if (ret > 0) {
-+					/* Got data, add it to the buffer. */
-+					ptr   += ret;
-+					total += ret;
-+					count -= ret;
-+				} else if (!ret) {
-+					/* This should never happen since how can we have
-+					 * data to read at an end of file, but still
-+					 * just in case! */
-+					data->end_of_file = 1;
-+					break;
-+				}
-+			}
-+
-+			/* If not timed out and not end of file and not all data read
-+			 * calculate how long it took us and loop if we still have time
-+			 * out time left. */
-+			if (count) {
-+				(void) gettimeofday(&after, NULL);
-+
-+				/* Diff the timevals */
-+				(void) dio_timeval_subtract(&after, &before, &diff);
-+
-+				/* Now adjust the timeout. */
-+				if (!dio_timeval_subtract(&timeout, &diff, &timeout)) {
-+					/* If it errors we've run out of time. */
-+					data->timed_out = 1;
-+					break;
-+				} else if (!timeout.tv_sec && !(timeout.tv_usec / 1000)) {
-+					/* Check for rounding issues (millisecond accuracy) */
-+					data->timed_out = 1;
-+					break;
-+				}
-+			}
-+		} while (count); /* Until time out or end of file or all data read. */
-+
-+		return total;
-+	}
-+#endif
-+}
-+/* }}} */
-+
-+/* {{{ php_dio_stream_data
-+ * Closes the php_stream.
-+ */
-+int dio_common_close(php_dio_stream_data *data) {
-+	if (close(((php_dio_posix_stream_data*)data)->fd) < 0) {
-+		return 0;
-+	}
-+
-+	return 1;
-+}
-+/* }}} */
-+
-+/* {{{ dio_common_set_option
-+ * Sets/gets stream options
-+ */
-+int dio_common_set_option(php_dio_stream_data *data, int option, int value, void *ptrparam) {
-+	int fd = ((php_dio_posix_stream_data*)data)->fd;
-+	int old_is_blocking;
-+	int flags;
-+
-+	switch (option) {
-+#ifdef DIO_NONBLOCK
-+		case PHP_STREAM_OPTION_READ_TIMEOUT:
-+			if (ptrparam) {
-+				struct timeval *tv = (struct timeval*)ptrparam;
-+
-+				flags = fcntl(fd, F_GETFL, 0);
-+
-+				/* A timeout of zero seconds and zero microseconds disables
-+				   any existing timeout. */
-+				if (tv->tv_sec || tv->tv_usec) {
-+					data->timeout_sec = tv->tv_sec;
-+					data->timeout_usec = tv->tv_usec;
-+					data->has_timeout = -1;
-+					(void) fcntl(fd, F_SETFL, flags & ~DIO_NONBLOCK);
-+				} else {
-+					data->timeout_sec = 0;
-+					data->timeout_usec = 0;
-+					data->has_timeout = 0;
-+					data->timed_out = 0;
-+					(void) fcntl(fd, F_SETFL, flags | DIO_NONBLOCK);
-+				}
-+
-+				return PHP_STREAM_OPTION_RETURN_OK;
-+			} else {
-+				return PHP_STREAM_OPTION_RETURN_ERR;
-+			}
-+
-+		case PHP_STREAM_OPTION_BLOCKING:
-+			flags = fcntl(fd, F_GETFL, 0);
-+			if (value) {
-+				flags &= ~DIO_NONBLOCK;
-+			} else {
-+				flags |= DIO_NONBLOCK;
-+			}
-+			(void) fcntl(fd, F_SETFL, flags);
-+
-+			old_is_blocking = data->is_blocking;
-+			data->is_blocking = value;
-+			return old_is_blocking ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR;
-+#endif /* O_NONBLOCK */
-+
-+		default:
-+			break;
-+	}
-+
-+	return 1;
-+}
-+/* }}} */
-+
-+/* {{{ dio_raw_open_stream
-+ * Opens the underlying stream.
-+ */
-+int dio_raw_open_stream(char *filename, char *mode, php_dio_stream_data *data TSRMLS_DC) {
-+	php_dio_posix_stream_data *pdata = (php_dio_posix_stream_data*)data;
-+	pdata->flags = dio_stream_mode_to_flags(mode);
-+
-+#ifdef DIO_NONBLOCK
-+	if (!data->is_blocking || data->has_timeout) {
-+		pdata->flags |= DIO_NONBLOCK;
-+	}
-+#endif
-+
-+	/* Open the file and handle any errors. */
-+#ifdef DIO_HAS_FILEPERMS
-+	if (data->has_perms) {
-+		pdata->fd = open(filename, pdata->flags, (mode_t)data->perms);
-+	} else {
-+		pdata->fd = open(filename, pdata->flags);
-+	}
-+#else
-+	pdata->fd = open(filename, pdata->flags);
-+#endif
-+
-+	if (pdata->fd < 0) {
-+		switch (errno) {
-+			case EEXIST:
-+				php_error_docref(NULL TSRMLS_CC, E_WARNING, "File exists!");
-+				return 0;
-+			default:
-+				return 0;
-+		}
-+	}
-+
-+	return 1;
-+}
-+/* }}} */
-+
-+/* {{{ dio_serial_init
-+ * Initialises the serial settings storing the original settings before hand.
-+ */
-+static int dio_serial_init(php_dio_stream_data *data TSRMLS_DC) {
-+	php_dio_posix_stream_data *pdata = (php_dio_posix_stream_data*)data;
-+	int ret = 0, data_bits_def, stop_bits_def, parity_def;
-+	struct termios tio;
-+	speed_t rate_def;
-+
-+	if (!dio_data_rate_to_define(data->data_rate, &rate_def)) {
-+		php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid data_rate value (%ld)", data->data_rate);
-+		return 0;
-+	}
-+
-+	if (!dio_data_bits_to_define(data->data_bits, &data_bits_def)) {
-+		php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid data_bits value (%d)", data->data_bits);
-+		return 0;
-+	}
-+
-+	if (!dio_stop_bits_to_define(data->stop_bits, &stop_bits_def)) {
-+		php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid stop_bits value (%d)", data->stop_bits);
-+		return 0;
-+	}
-+
-+	if (!dio_parity_to_define(data->parity, &parity_def)) {
-+		php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid parity value (%d)", data->parity);
-+		return 0;
-+	}
-+
-+	ret = tcgetattr(pdata->fd, &(pdata->oldtio));
-+	if (ret < 0) {
-+		if ((errno == ENOTTY) || (errno == ENODEV)) {
-+			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not a serial port or terminal!");
-+		}
-+		return 0;
-+	}
-+
-+	ret = tcgetattr(pdata->fd, &tio);
-+	if (ret < 0) {
-+		return 0;
-+	}
-+
-+	if (data->canonical) {
-+		tio.c_iflag = IGNPAR | ICRNL;
-+		tio.c_oflag = 0;
-+		tio.c_lflag = ICANON;
-+	} else {
-+		cfmakeraw(&tio);
-+	}
-+
-+	cfsetispeed(&tio, rate_def);
-+	cfsetospeed(&tio, rate_def);
-+
-+	tio.c_cflag &= ~CSIZE;
-+	tio.c_cflag |= data_bits_def;
-+	tio.c_cflag &= ~CSTOPB;
-+	tio.c_cflag |= stop_bits_def;
-+	tio.c_cflag &= ~(PARENB|PARODD);
-+	tio.c_cflag |= parity_def;
-+
-+#ifdef CRTSCTS
-+	tio.c_cflag &= ~(CLOCAL | CRTSCTS);
-+#else
-+	tio.c_cflag &= ~CLOCAL;
-+#endif
-+	if (!data->flow_control) {
-+		tio.c_cflag |= CLOCAL;
-+#ifdef CRTSCTS
-+	} else {
-+		tio.c_cflag |= CRTSCTS;
-+#endif
-+	}
-+
-+	ret = tcsetattr(pdata->fd, TCSANOW, &tio);
-+	if (ret < 0) {
-+		return 0;
-+	}
-+
-+	return 1;
-+}
-+/* }}} */
-+
-+/* {{{ dio_serial_uninit
-+ * Restores the serial settings back to their original state.
-+ */
-+int dio_serial_uninit(php_dio_stream_data *data) {
-+	php_dio_posix_stream_data *pdata = (php_dio_posix_stream_data*)data;
-+	int ret;
-+
-+	do {
-+		ret = tcsetattr(pdata->fd, TCSANOW, &(pdata->oldtio));
-+	} while ((ret < 0) && (errno == EINTR));
-+
-+	return 1;
-+}
-+/* }}} */
-+
-+/* {{{ dio_serial_flush
-+ * Purges the serial buffers of data.
-+ */
-+int dio_serial_purge(php_dio_stream_data *data) {
-+	php_dio_posix_stream_data *pdata = (php_dio_posix_stream_data*)data;
-+	int ret;
-+
-+	if ((pdata->flags & O_RDWR) == O_RDWR) {
-+		ret = tcflush(pdata->fd, TCIOFLUSH);
-+	} else if ((pdata->flags & O_WRONLY) == O_WRONLY) {
-+		ret = tcflush(pdata->fd, TCOFLUSH);
-+	} else if ((pdata->flags & O_RDONLY) == O_RDONLY) {
-+		ret = tcflush(pdata->fd, TCIFLUSH);
-+	}
-+
-+	if (ret < 0) {
-+		return 0;
-+	}
-+
-+	return 1;
-+}
-+/* }}} */
-+
-+/* {{{ dio_serial_open_stream
-+ * Opens the underlying stream.
-+ */
-+int dio_serial_open_stream(char *filename, char *mode, php_dio_stream_data *data TSRMLS_DC) {
-+	php_dio_posix_stream_data *pdata = (php_dio_posix_stream_data*)data;
-+
-+#ifdef O_NOCTTY
-+	/* We don't want a controlling TTY */
-+	pdata->flags |= O_NOCTTY;
-+#endif
-+
-+	if (!dio_raw_open_stream(filename, mode, data TSRMLS_CC)) {
-+		return 0;
-+	}
-+
-+	if (!dio_serial_init(data TSRMLS_CC)) {
-+		close(pdata->fd);
-+		return 0;
-+	}
-+
-+	return 1;
-+}
-+/* }}} */
-+
-+/*
-+ * Local variables:
-+ * c-basic-offset: 4
-+ * tab-width: 4
-+ * End:
-+ * vim600: fdm=marker
-+ * vim: sw=4 ts=4 noet
-+ */
---- a/dio_win32.c
-+++ b/dio_win32.c
-@@ -1,759 +1,759 @@
--/*
--   +----------------------------------------------------------------------+
--   | PHP Version 5                                                        |
--   +----------------------------------------------------------------------+
--   | Copyright (c) 2009 Melanie Rhianna Lewis                             |
--   +----------------------------------------------------------------------+
--   | This source file is subject to version 3.0 of the PHP license,       |
--   | that is bundled with this package in the file LICENSE, and is        |
--   | available through the world-wide-web at the following url:           |
--   | http://www.php.net/license/3_0.txt.                                  |
--   | If you did not receive a copy of the PHP license and are unable to   |
--   | obtain it through the world-wide-web, please send a note to          |
--   | license@php.net so we can mail you a copy immediately.               |
--   +----------------------------------------------------------------------+
--   | Author: Melanie Rhianna Lewis <cyberspice@php.net>                   |
--   +----------------------------------------------------------------------+
-- */
--
--#ifdef HAVE_CONFIG_H
--#include "config.h"
--#endif
--
--#include "php.h"
--#include "php_dio_common.h"
--
--#ifndef ZEND_WIN32
--#error ZEND_WIN32 not defined!
--#endif
--
--/* {{{ dio_last_error_php_error
-- * Generates a PHP error message based upon the last Windows error.
-- */
--static void dio_last_error_php_error(int level, char * message TSRMLS_DC) {
--	LPVOID msgbuf;
--	DWORD  msgbuflen;
--	char * errmsg;
--	DWORD  err;
--
--#ifdef UNICODE
--	DWORD  errmsglen;
--#endif
--
--	err = GetLastError();
--	msgbuflen = FormatMessage(
--		FORMAT_MESSAGE_ALLOCATE_BUFFER|
--		FORMAT_MESSAGE_FROM_SYSTEM|
--		FORMAT_MESSAGE_IGNORE_INSERTS,
--		NULL,
--		err,
--		MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
--		(LPTSTR)&msgbuf,
--		0,
--		NULL);
--
--#ifdef UNICODE
--
--	/* Get the length of the converted message */
--	errmsglen = WideCharToMultibyte(
--		CP_ACP,
--		0
--		(LPCWSTR)msgbuf,
--		-1,
--		(LPSTR)errmsg,
--		0,
--		NULL,
--		NULL);
--
--	/* Allocate a buffer */
--	errmsg = emalloc(errmsglen);
--	if (!errmsg) {
--		php_error_docref(NULL TSRMLS_CC, E_ERROR, "Out of memory in dio_last_error_php_error()!");
--		LocalFree(msgbuf);
--		return;
--	}
--
--	/* Convert the message */
--	errmsglen = WideCharToMultibyte(
--		CP_ACP,
--		0
--		(LPCWSTR)msgbuf,
--		-1,
--		(LPSTR)errmsg,
--		errmsglen,
--		NULL,
--		NULL);
--
--#else
--	errmsg = (char *)msgbuf;
--#endif
--
--	php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s[ERROR %d] %s", message, err, errmsg);
--
--	LocalFree(msgbuf);
--#ifdef UNICODE
--	efree(errmsg);
--#endif
--}
--
--/* {{{ dio_data_rate_to_define
-- * Converts a numeric data rate to a termios define
-- */
--static int dio_data_rate_to_define(long rate, DWORD *def) {
--	switch (rate) {
--		case 75:
--		case 110:
--		case 134:
--		case 150:
--		case 300:
--		case 600:
--		case 1200:
--		case 1800:
--		case 2400:
--		case 4800:
--		case 7200:
--		case 9600:
--		case 14400:
--		case 19200:
--		case 38400:
--		case 57600:
--		case 115200:
--		case 56000:
--		case 128000:
--		case 256000:
--			break;
--		default:
--			return 0;
--	}
--
--	*def = (DWORD)rate;
--	return 1;
--}
--/* }}} */
--
--
--/* {{{ dio_data_bits_to_define
-- * Converts a number of data bits to a termios define
-- */
--static int dio_data_bits_to_define(int data_bits, DWORD *def) {
--	switch (data_bits) {
--		case 8:
--		case 7:
--		case 6:
--		case 5:
--		case 4:
--			break;
--		default:
--			return 0;
--	}
--
--	*def = (DWORD)data_bits;
--	return 1;
--}
--/* }}} */
--
--/* {{{ dio_stop_bits_to_define
-- * Converts a number of stop bits to a termios define
-- */
--static int dio_stop_bits_to_define(int stop_bits, DWORD *def) {
--	DWORD val;
--
--	switch (stop_bits) {
--		case 1:
--			val = ONESTOPBIT;
--			break;
--		case 2:
--			val = TWOSTOPBITS;
--			break;
--		case 3:
--			val = ONE5STOPBITS;
--			break;
--		default:
--			return 0;
--	}
--
--	*def = val;
--	return 1;
--}
--/* }}} */
--
--/* {{{ dio_parity_to_define
-- * Converts a parity type to a termios define
-- */
--static int dio_parity_to_define(int parity, DWORD *def) {
--	DWORD val;
--
--	switch (parity) {
--		case 0:
--			val = NOPARITY;
--			break;
--		case 1:
--			val = ODDPARITY;
--			break;
--		case 2:
--			val = EVENPARITY;
--			break;
--		default:
--			return 0;
--	}
--
--	*def = val;
--	return 1;
--}
--/* }}} */
--
--/* {{{ dio_create_stream_data
-- * Creates an initialised stream data structure.  Free with efree().
-- */
--php_dio_stream_data * dio_create_stream_data(void) {
--	php_dio_win32_stream_data * data = emalloc(sizeof(php_dio_win32_stream_data));
--	memset(data, 0, sizeof(php_dio_win32_stream_data));
--	dio_init_stream_data(&(data->common));
--	data->handle = INVALID_HANDLE_VALUE;
--	data->desired_access = 0;
--	data->creation_disposition = 0;
--	data->olddcb.DCBlength = sizeof(DCB);
--
--	return (php_dio_stream_data *)data;
--}
--/* }}} */
--
--/* {{{ dio_common_write
-- * Writes count chars from the buffer to the stream described by the stream data.
-- */
--size_t dio_common_write(php_dio_stream_data *data, const char *buf, size_t count) {
--	php_dio_win32_stream_data *wdata = (php_dio_win32_stream_data*)data;
--	DWORD total = 0;
--
--	if (WriteFile(wdata->handle, buf, (DWORD)count, &total, NULL)) {
--		return (size_t)total;
--	}
--
--	return 0;
--}
--/* }}} */
--
--/* {{{ dio_buffer_read
-- * Reads any available chars from the canonical buffer.
-- */
--static size_t dio_buffer_read(php_dio_win32_stream_data *wdata, const char *buf, size_t count) {
--	php_dio_win32_canon_data *canon_data = wdata->canon_data;
--	size_t total = 0;
--
--	/* Read always follows write.  I.e. if read ptr > write ptr buffer has
--	   wrapped and so we need to copy two blocks of data. */
--	if (canon_data->read_pos > canon_data->write_pos) {
--
--		/* Check we actually need to copy both blocks */
--		if ((canon_data->size - canon_data->read_pos) > count) {
--
--			/* No we don't.  Just copy as much as we were asked for. */
--			memcpy((char*)buf, 
--				   &(canon_data->buf[canon_data->read_pos]), 
--				   count);
--			/* Update the read pointer. */
--			canon_data->read_pos += count;
--
--			/* Return the amount read. */
--			return count;
--		} else {
--
--			/* We need to copy both blocks so copy data up to the end of 
--			   the buffer. */
--			total = canon_data->size - canon_data->read_pos;
--			memcpy((char*)buf, 
--				   &(canon_data->buf[canon_data->read_pos]), 
--				   total);
--			canon_data->read_pos = 0;
--			count -= total;
--
--			/* Now copy the data from the start of the buffer either up
--			   count or the number of bytes in the buffer. */
--
--			if (canon_data->write_pos > count) {
--				memcpy((char*)buf, canon_data->buf, count);
--				canon_data->read_pos = count;
--				total += count;
--
--				return total;
--			} else {
--				memcpy((char*)buf, canon_data->buf, canon_data->write_pos);
--				canon_data->read_pos = canon_data->write_pos;
--				total += canon_data->write_pos;
--
--				return total;
--			}
--		}
--
--	/* Else if write follows read.  This is a simpler case.  We just copy 
--	   either all the data buffered or count, which ever is smaller. */
--	} else if (canon_data->write_pos > canon_data->read_pos) {
--		if ((canon_data->write_pos - canon_data->read_pos) > count) {
--			memcpy((char*)buf, 
--				   &(canon_data->buf[canon_data->read_pos]), 
--				   count);
--			canon_data->read_pos += count;
--
--			return count;
--		} else {
--			total = canon_data->write_pos - canon_data->read_pos;
--			memcpy((char*)buf, 
--				   &(canon_data->buf[canon_data->read_pos]), 
--				   total);
--			canon_data->read_pos += total;
--
--			return total;
--		}
--	}
--
--	/* Else we need to read more data from the data port. */
--	return 0;
--}
--
--/* {{{ dio_com_read
-- * Read chars from the data port.
-- */
--static size_t dio_com_read(php_dio_stream_data *data, const char *buf, size_t count) {
--	php_dio_win32_stream_data *wdata = (php_dio_win32_stream_data*)data;
--	DWORD err, total = 0;
--
--	if (ReadFile(wdata->handle, (void*)buf, (DWORD)count, &total, NULL)) {
--
--		if (total) {
--			return (size_t)total;
--		}
--
--		data->end_of_file = 1;
--	}
--
--	if (!data->end_of_file) {
--		err = GetLastError();
--
--		if (ERROR_HANDLE_EOF == err) {
--			data->end_of_file = 1;
--		}
--	}
--
--	return 0;
--}
--
--/* {{{ dio_canonical_read
-- * Reads chars from the input stream until the internal buffer is full or a new
-- * line is reached.
-- */
--static size_t dio_canonical_read(php_dio_win32_stream_data *wdata, const char *buf, size_t count) {
--	php_dio_win32_canon_data *canon_data = wdata->canon_data;
--	size_t total = 0;
--	char ch;
--
--	/* See if there's any buffered data and copy it. */
--	total = dio_buffer_read(wdata, buf, count);
--	if (total) {
--		return total;
--	}
--
--	/* Need to read more data from the data port.  Buffer should be empty(er)
--	   by now. */
--	do {
--		/* Is the buffer full? */
--		if (((canon_data->write_pos + 1) % canon_data->size) == 
--			canon_data->read_pos) {
--			break;
--		}
--
--		/* Read a byte from the input checking for EOF. */
--		if (!dio_com_read((php_dio_stream_data*)wdata, &ch, 1)) {
--			break;
--		}
--
--		/* Translate CR to newlines (same as ICRNL in POSIX) */
--		ch = (ch != '\r') ? ch : '\n';
--
--		/* We read a character!  So buffer it. */
--		canon_data->buf[canon_data->write_pos++] = ch;
--		if (canon_data->write_pos >= canon_data->size) {
--			canon_data->write_pos = 0;
--		}
--
--		/* End of line/input (^D)? */
--	} while ((ch != '\n') && (ch != 0x04));
--
--	return dio_buffer_read(wdata, buf, count);
--}
--/* }}} */
--
--/* {{{ dio_common_read
-- * Reads count chars to the buffer to the stream described by the stream data.
-- */
--size_t dio_common_read(php_dio_stream_data *data, const char *buf, size_t count) {
--
--	/* You ask for no bytes you'll get none :-) */
--	if (!count) {
--		return 0;
--	}
--
--	if (data->canonical) {
--		return dio_canonical_read((php_dio_win32_stream_data*)data, buf, count);
--	} else {
--		return dio_com_read(data, buf, count);
--	}
--}
--/* }}} */
--
--/* {{{ php_dio_stream_data
-- * Closes the php_stream.
-- */
--int dio_common_close(php_dio_stream_data *data) {
--	php_dio_win32_stream_data *wdata = (php_dio_win32_stream_data*)data;
--
--	if (data->canonical) {
--		efree(wdata->canon_data);
--	}
--
--	if (!CloseHandle(wdata->handle)) {
--		return 0;
--	}
--
--	return 1;
--}
--/* }}} */
--
--/* {{{ dio_common_set_option
-- * Sets/gets stream options
-- */
--int dio_common_set_option(php_dio_stream_data *data, int option, int value, void *ptrparam) {
--	COMMTIMEOUTS cto = { 0, 0, 0, 0, 0 };
--	int old_is_blocking = 0;
--
--	/* Can't do timeouts or non blocking with raw windows streams :-( */
--	if (DIO_STREAM_TYPE_SERIAL == data->stream_type) {
--		switch (option) {
--			case PHP_STREAM_OPTION_BLOCKING:
--				old_is_blocking   = data->is_blocking;
--				data->is_blocking = value ? 1 : 0;
--
--				/* Only change values if we need to change them. */
--				if (data->is_blocking != old_is_blocking) {
--					/* If we're not blocking but don't have a timeout
--					   set to return immediately */
--					if (!data->is_blocking && !data->has_timeout) {
--						cto.ReadIntervalTimeout = MAXDWORD;
--					}
--
--					/* If we have a timeout ignore the blocking and set
--					   the total time in which to read the data */
--					if (data->has_timeout) {
--						cto.ReadIntervalTimeout = MAXDWORD;
--						cto.ReadTotalTimeoutMultiplier  = MAXDWORD;
--						cto.ReadTotalTimeoutConstant = (data->timeout_usec / 1000) +
--							(data->timeout_sec * 1000);
--					}
--
--					if (!SetCommTimeouts(((php_dio_win32_stream_data*)data)->handle, &cto)) {
--						return PHP_STREAM_OPTION_RETURN_ERR;
--					}
--				}
--				return old_is_blocking ? PHP_STREAM_OPTION_RETURN_OK : PHP_STREAM_OPTION_RETURN_ERR;
--
--			case PHP_STREAM_OPTION_READ_TIMEOUT:
--				if (ptrparam) {
--					/* struct timeval is supported with PHP_WIN32 defined. */
--					struct timeval *tv = (struct timeval*)ptrparam;
--
--					/* A timeout of zero seconds and zero microseconds disables
--					   any existing timeout. */
--					if (tv->tv_sec || tv->tv_usec) {
--						data->timeout_sec = tv->tv_sec;
--						data->timeout_usec = tv->tv_usec;
--						data->has_timeout = -1;
--
--						cto.ReadIntervalTimeout = MAXDWORD;
--						cto.ReadTotalTimeoutMultiplier  = MAXDWORD;
--						cto.ReadTotalTimeoutConstant = (data->timeout_usec / 1000) +
--							(data->timeout_sec * 1000);
--					} else {
--						data->timeout_sec = 0;
--						data->timeout_usec = 0;
--						data->has_timeout = 0;
--						data->timed_out = 0;
--
--						/* If we're not blocking but don't have a timeout
--						   set to return immediately */
--						if (!data->is_blocking) {
--							cto.ReadIntervalTimeout = MAXDWORD;
--						}
--					}
--
--					if (!SetCommTimeouts(((php_dio_win32_stream_data*)data)->handle, &cto)) {
--						return PHP_STREAM_OPTION_RETURN_ERR;
--					} else {
--						return PHP_STREAM_OPTION_RETURN_OK;
--					}
--				} else {
--					return PHP_STREAM_OPTION_RETURN_ERR;
--				}
--
--			default:
--				break;
--		}
--	}
--
--	return 1;
--}
--/* }}} */
--
--/* {{{ dio_raw_open_stream
-- * Opens the underlying stream.
-- */
--int dio_raw_open_stream(char *filename, char *mode, php_dio_stream_data *data TSRMLS_DC) {
--	php_dio_win32_stream_data *wdata = (php_dio_win32_stream_data*)data;
--	DWORD err;
--
--	switch(*mode) {
--		case 'r':
--			wdata->creation_disposition = OPEN_EXISTING;
--			break;
--		case 'w':
--			wdata->creation_disposition = TRUNCATE_EXISTING;
--			break;
--		case 'a':
--			wdata->creation_disposition = OPEN_ALWAYS;
--			break;
--		case 'x':
--			wdata->creation_disposition = CREATE_NEW;
--			break;
--	}
--	mode ++;
--
--	if (*mode && (*mode != '+')) {
--		mode++;
--	}
--
--	if (*mode && (*mode == '+')) {
--		wdata->desired_access = GENERIC_READ | GENERIC_WRITE;
--	} else if (OPEN_EXISTING == wdata->creation_disposition) {
--		wdata->desired_access = GENERIC_READ;
--	} else {
--		wdata->desired_access = GENERIC_WRITE;
--	}
--
--	wdata->handle = CreateFile(filename, wdata->desired_access, 0,
--			NULL, wdata->creation_disposition, FILE_ATTRIBUTE_NORMAL, NULL);
--	if (INVALID_HANDLE_VALUE == wdata->handle) {
--		err = GetLastError();
--		switch (err) {
--			case ERROR_FILE_EXISTS:
--				php_error_docref(NULL TSRMLS_CC, E_WARNING, "File exists!");
--				return 0;
--
--			case ERROR_FILE_NOT_FOUND:
--				/* ERROR_FILE_NOT_FOUND with TRUNCATE_EXISTING means that
--				 * the file doesn't exist so now try to create it. */
--				if (TRUNCATE_EXISTING == wdata->creation_disposition) {
--					php_error_docref(NULL TSRMLS_CC, E_NOTICE, "File does not exist, creating new file!");
--
--					wdata->handle = CreateFile(filename, wdata->desired_access, 0,
--								NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
--					if (INVALID_HANDLE_VALUE == wdata->handle) {
--						dio_last_error_php_error(E_WARNING, "CreateFile() failed:" TSRMLS_CC);
--						return 0;
--					}
--				} else {
--					php_error_docref(NULL TSRMLS_CC, E_WARNING, "File not found!");
--					return 0;
--				}
--				break;
--
--			default:
--				dio_last_error_php_error(E_WARNING, "CreateFile() failed:" TSRMLS_CC);
--				return 0;
--		}
--	}
--
--	/* If canonical allocate the canonical buffer. */
--	if (data->canonical) {
--		wdata->canon_data = emalloc(sizeof(php_dio_win32_canon_data));
--		memset(wdata->canon_data, 0, sizeof(php_dio_win32_canon_data));
--		wdata->canon_data->size = DIO_WIN32_CANON_BUF_SIZE;
--	}
--
--	return 1;
--}
--/* }}} */