Browse Source

Added GetLastErrorCode() and GetErrorForCode() functions.

Brucey 4 years ago
parent
commit
3cc6d74160
3 changed files with 65 additions and 6 deletions
  1. 36 1
      io.mod/common.bmx
  2. 10 2
      io.mod/glue.c
  3. 19 3
      io.mod/io.bmx

+ 36 - 1
io.mod/common.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2020 Bruce A Henderson
+' Copyright (c) 2020-2021 Bruce A Henderson
 ' 
 ' This software is provided 'as-is', without any express or implied
 ' warranty. In no event will the authors be held liable for any damages
@@ -28,7 +28,9 @@ Extern
 
 	Function bmx_PHYSFS_init:Int()
 	Function PHYSFS_deinit:Int()
+	Function bmx_PHYSFS_getErrorForCode:String(errorCode:EMaxIOErrorCode)
 	Function bmx_PHYSFS_getLastError:String()
+	Function bmx_PHYSFS_getLastErrorCode:EMaxIOErrorCode()
 	Function bmx_PHYSFS_mount:Int(newDir:String, mountPoint:String, appendToPath:Int)
 	Function bmx_PHYSFS_getBaseDir:String()
 	Function bmx_PHYSFS_getPrefDir:String(org:String, app:String)
@@ -73,3 +75,36 @@ Enum EMaxIOFileType:Int
 	SYMLINK
 	OTHER
 End Enum
+
+Enum EMaxIOErrorCode:Int
+	OK
+	OTHER_ERROR
+	OUT_OF_MEMORY
+	NOT_INITIALIZED
+	IS_INITIALIZED
+	ARGV0_IS_NULL
+	UNSUPPORTED
+	PAST_EOF
+	FILES_STILL_OPEN
+	INVALID_ARGUMENT
+	NOT_MOUNTED
+	NOT_FOUND
+	SYMLINK_FORBIDDEN
+	NO_WRITE_DIR
+	OPEN_FOR_READING
+	OPEN_FOR_WRITING
+	NOT_A_FILE
+	READ_ONLY
+	CORRUPT
+	SYMLINK_LOOP
+	IO
+	PERMISSION
+	NO_SPACE
+	BAD_FILENAME
+	BUSY
+	DIR_NOT_EMPTY
+	OS_ERROR
+	DUPLICATE
+	BAD_PASSWORD
+	APP_CALLBACK
+End Enum

+ 10 - 2
io.mod/glue.c

@@ -1,5 +1,5 @@
 /*
-  Copyright (c) 2020 Bruce A Henderson
+  Copyright (c) 2020-2021 Bruce A Henderson
   
   This software is provided 'as-is', without any express or implied
   warranty. In no event will the authors be held liable for any damages
@@ -29,12 +29,20 @@ int bmx_PHYSFS_init() {
 	return PHYSFS_init(bbArgv0);
 }
 
+int bmx_PHYSFS_getLastErrorCode() {
+	return PHYSFS_getLastErrorCode();
+}
+
+BBString * bmx_PHYSFS_getErrorForCode(int code) {
+	return bbStringFromUTF8String(PHYSFS_getErrorByCode(code));
+}
+
 BBString * bmx_PHYSFS_getLastError() {
 	int code = PHYSFS_getLastErrorCode();
 	if (code == PHYSFS_ERR_OK) {
 		return &bbEmptyString;
 	}
-	return bbStringFromUTF8String(PHYSFS_getErrorByCode(code));
+	return bmx_PHYSFS_getErrorForCode(code);
 }
 
 int bmx_PHYSFS_mount(BBString * newDir, BBString * mountPoint, int appendToPath) {

+ 19 - 3
io.mod/io.bmx

@@ -1,4 +1,4 @@
-' Copyright (c) 2020 Bruce A Henderson
+' Copyright (c) 2020-2021 Bruce A Henderson
 ' 
 ' This software is provided 'as-is', without any express or implied
 ' warranty. In no event will the authors be held liable for any damages
@@ -217,10 +217,26 @@ Type MaxIO
 	End Function
 
 	Rem
-	bbdoc: Return the last error message.
+	bbdoc: Returns the last error code.
+	about: Calling this function resets the last error code.
+	End Rem
+	Function GetLastErrorCode:EMaxIOErrorCode()
+		Return bmx_PHYSFS_getLastErrorCode()
+	End Function
+
+	Rem
+	bbdoc: Returns the message for the specified @errorCode.
+	End Rem
+	Function GetErrorForCode:String(errorCode:EMaxIOErrorCode)
+		Return bmx_PHYSFS_getErrorForCode(errorCode)
+	End Function
+
+	Rem
+	bbdoc: Returns the last error message, or #Null if there is none.
+	about: Calling this function resets the last error.
 	End Rem
 	Function GetLastError:String()
 		Return bmx_PHYSFS_getLastError()
 	End Function
-	
+
 End Type