aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/io/io_semihosting.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/io/io_semihosting.c')
-rw-r--r--drivers/io/io_semihosting.c36
1 files changed, 13 insertions, 23 deletions
diff --git a/drivers/io/io_semihosting.c b/drivers/io/io_semihosting.c
index 8e62be1d9..63d0f68ec 100644
--- a/drivers/io/io_semihosting.c
+++ b/drivers/io/io_semihosting.c
@@ -84,10 +84,9 @@ static const io_dev_info_t sh_dev_info = {
static int sh_dev_open(const uintptr_t dev_spec __unused,
io_dev_info_t **dev_info)
{
- int result = IO_SUCCESS;
assert(dev_info != NULL);
*dev_info = (io_dev_info_t *)&sh_dev_info; /* cast away const */
- return result;
+ return 0;
}
@@ -95,7 +94,7 @@ static int sh_dev_open(const uintptr_t dev_spec __unused,
static int sh_file_open(io_dev_info_t *dev_info __attribute__((unused)),
const uintptr_t spec, io_entity_t *entity)
{
- int result = IO_FAIL;
+ int result = -ENOENT;
long sh_result = -1;
const io_file_spec_t *file_spec = (const io_file_spec_t *)spec;
@@ -106,9 +105,7 @@ static int sh_file_open(io_dev_info_t *dev_info __attribute__((unused)),
if (sh_result > 0) {
entity->info = (uintptr_t)sh_result;
- result = IO_SUCCESS;
- } else {
- result = IO_FAIL;
+ result = 0;
}
return result;
}
@@ -117,7 +114,6 @@ static int sh_file_open(io_dev_info_t *dev_info __attribute__((unused)),
/* Seek to a particular file offset on the semi-hosting device */
static int sh_file_seek(io_entity_t *entity, int mode, ssize_t offset)
{
- int result = IO_FAIL;
long file_handle, sh_result;
assert(entity != NULL);
@@ -126,16 +122,14 @@ static int sh_file_seek(io_entity_t *entity, int mode, ssize_t offset)
sh_result = semihosting_file_seek(file_handle, offset);
- result = (sh_result == 0) ? IO_SUCCESS : IO_FAIL;
-
- return result;
+ return (sh_result == 0) ? 0 : -ENOENT;
}
/* Return the size of a file on the semi-hosting device */
static int sh_file_len(io_entity_t *entity, size_t *length)
{
- int result = IO_FAIL;
+ int result = -ENOENT;
assert(entity != NULL);
assert(length != NULL);
@@ -144,7 +138,7 @@ static int sh_file_len(io_entity_t *entity, size_t *length)
long sh_result = semihosting_file_length(sh_handle);
if (sh_result >= 0) {
- result = IO_SUCCESS;
+ result = 0;
*length = (size_t)sh_result;
}
@@ -156,7 +150,7 @@ static int sh_file_len(io_entity_t *entity, size_t *length)
static int sh_file_read(io_entity_t *entity, uintptr_t buffer, size_t length,
size_t *length_read)
{
- int result = IO_FAIL;
+ int result = -ENOENT;
long sh_result = -1;
size_t bytes = length;
long file_handle;
@@ -171,9 +165,8 @@ static int sh_file_read(io_entity_t *entity, uintptr_t buffer, size_t length,
if (sh_result >= 0) {
*length_read = (bytes != length) ? bytes : length;
- result = IO_SUCCESS;
- } else
- result = IO_FAIL;
+ result = 0;
+ }
return result;
}
@@ -197,14 +190,13 @@ static int sh_file_write(io_entity_t *entity, const uintptr_t buffer,
*length_written = length - bytes;
- return (sh_result == 0) ? IO_SUCCESS : IO_FAIL;
+ return (sh_result == 0) ? 0 : -ENOENT;
}
/* Close a file on the semi-hosting device */
static int sh_file_close(io_entity_t *entity)
{
- int result = IO_FAIL;
long sh_result = -1;
long file_handle;
@@ -214,9 +206,7 @@ static int sh_file_close(io_entity_t *entity)
sh_result = semihosting_file_close(file_handle);
- result = (sh_result >= 0) ? IO_SUCCESS : IO_FAIL;
-
- return result;
+ return (sh_result >= 0) ? 0 : -ENOENT;
}
@@ -225,11 +215,11 @@ static int sh_file_close(io_entity_t *entity)
/* Register the semi-hosting driver with the IO abstraction */
int register_io_dev_sh(const io_dev_connector_t **dev_con)
{
- int result = IO_FAIL;
+ int result;
assert(dev_con != NULL);
result = io_register_device(&sh_dev_info);
- if (result == IO_SUCCESS)
+ if (result == 0)
*dev_con = &sh_dev_connector;
return result;