Partially revert PR #2190

The core shouldn't depend on constants that are not defined by itself
diff --git a/system/core/Common.php b/system/core/Common.php
index 55f07a8..237bd42 100644
--- a/system/core/Common.php
+++ b/system/core/Common.php
@@ -94,17 +94,17 @@
 		if (is_dir($file))
 		{
 			$file = rtrim($file, '/').'/'.md5(mt_rand());
-			if (($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE)
+			if (($fp = @fopen($file, 'ab')) === FALSE)
 			{
 				return FALSE;
 			}
 
 			fclose($fp);
-			@chmod($file, DIR_WRITE_MODE);
+			@chmod($file, 0777);
 			@unlink($file);
 			return TRUE;
 		}
-		elseif ( ! is_file($file) OR ($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE)
+		elseif ( ! is_file($file) OR ($fp = @fopen($file, 'ab')) === FALSE)
 		{
 			return FALSE;
 		}
@@ -177,7 +177,7 @@
 			// self-referencing loop with the Exceptions class
 			set_status_header(503);
 			echo 'Unable to locate the specified class: '.$class.'.php';
-			exit(EXIT_UNKNOWN_CLASS);
+			exit(5); // EXIT_UNK_CLASS
 		}
 
 		// Keep track of what we just loaded
@@ -250,7 +250,7 @@
 			{
 				set_status_header(503);
 				echo 'The configuration file does not exist.';
-				exit(EXIT_CONFIG);
+				exit(3); // EXIT_CONFIG
 			}
 
 			// Does the $config array exist in the file?
@@ -258,7 +258,7 @@
 			{
 				set_status_header(503);
 				echo 'Your config file does not appear to be formatted correctly.';
-				exit(EXIT_CONFIG);
+				exit(3); // EXIT_CONFIG
 			}
 
 			// references cannot be directly assigned to static variables, so we use an array
@@ -397,16 +397,17 @@
 		$status_code = abs($status_code);
 		if ($status_code < 100)
 		{
-			$exit_status = $status_code + EXIT__AUTO_MIN;
-			if ($exit_status > EXIT__AUTO_MAX)
+			$exit_status = $status_code + 9; // 9 is EXIT__AUTO_MIN
+			if ($exit_status > 125) // 125 is EXIT__AUTO_MAX
 			{
-				$exit_status = EXIT_ERROR;
+				$exit_status = 1; // EXIT_ERROR
 			}
+
 			$status_code = 500;
 		}
 		else
 		{
-			$exit_status = EXIT_ERROR;
+			$exit_status = 1; // EXIT_ERROR
 		}
 
 		$_error =& load_class('Exceptions', 'core');
@@ -434,7 +435,7 @@
 	{
 		$_error =& load_class('Exceptions', 'core');
 		$_error->show_404($page, $log_error);
-		exit(EXIT_UNKNOWN_FILE);
+		exit(4); // EXIT_UNKNOWN_FILE
 	}
 }
 
@@ -612,7 +613,7 @@
 		// default error handling. See http://www.php.net/manual/en/errorfunc.constants.php
 		if ($is_error)
 		{
-			exit(EXIT_ERROR);
+			exit(1); // EXIT_ERROR
 		}
 	}
 }
diff --git a/system/core/Exceptions.php b/system/core/Exceptions.php
index 54a5bc4..0418696 100644
--- a/system/core/Exceptions.php
+++ b/system/core/Exceptions.php
@@ -125,7 +125,7 @@
 		}
 
 		echo $this->show_error($heading, $message, 'error_404', 404);
-		exit(EXIT_UNKNOWN_FILE);
+		exit(4); // EXIT_UNKNOWN_FILE
 	}
 
 	// --------------------------------------------------------------------
diff --git a/system/core/Input.php b/system/core/Input.php
index 1408da2..5ffe43d 100644
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -754,7 +754,7 @@
 			{
 				set_status_header(503);
 				echo 'Disallowed Key Characters.';
-				exit(EXIT_USER_INPUT);
+				exit(7); // EXIT_USER_INPUT
 			}
 		}
 
diff --git a/system/core/Log.php b/system/core/Log.php
index 707964c..a949c3f 100644
--- a/system/core/Log.php
+++ b/system/core/Log.php
@@ -108,7 +108,7 @@
 		$this->_file_ext = (isset($config['log_file_extension']) && $config['log_file_extension'] !== '')
 			? ltrim($config['log_file_extension'], '.') : 'php';
 
-		file_exists($this->_log_path) OR mkdir($this->_log_path, DIR_WRITE_MODE, TRUE);
+		file_exists($this->_log_path) OR mkdir($this->_log_path, 0777, TRUE);
 
 		if ( ! is_dir($this->_log_path) OR ! is_really_writable($this->_log_path))
 		{
@@ -170,7 +170,7 @@
 			}
 		}
 
-		if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE))
+		if ( ! $fp = @fopen($filepath, 'ab'))
 		{
 			return FALSE;
 		}
@@ -192,7 +192,7 @@
 
 		if (isset($newfile) && $newfile === TRUE)
 		{
-			@chmod($filepath, FILE_WRITE_MODE);
+			@chmod($filepath, 0666);
 		}
 
 		return is_int($result);
diff --git a/system/core/Output.php b/system/core/Output.php
index 7a35b02..df9ef07 100644
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -555,7 +555,7 @@
 
 		$cache_path .= md5($uri);
 
-		if ( ! $fp = @fopen($cache_path, FOPEN_WRITE_CREATE_DESTRUCTIVE))
+		if ( ! $fp = @fopen($cache_path, 'w+b'))
 		{
 			log_message('error', 'Unable to write cache file: '.$cache_path);
 			return;
@@ -606,7 +606,7 @@
 
 		if (is_int($result))
 		{
-			@chmod($cache_path, FILE_WRITE_MODE);
+			@chmod($cache_path, 0666);
 			log_message('debug', 'Cache file written: '.$cache_path);
 
 			// Send HTTP cache-control headers to browser to match file cache settings.
@@ -639,7 +639,7 @@
 		$uri =	$CFG->item('base_url').$CFG->item('index_page').$URI->uri_string;
 		$filepath = $cache_path.md5($uri);
 
-		if ( ! file_exists($filepath) OR ! $fp = @fopen($filepath, FOPEN_READ))
+		if ( ! file_exists($filepath) OR ! $fp = @fopen($filepath, 'rb'))
 		{
 			return FALSE;
 		}