summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/kit/file.c6
-rw-r--r--source/kit/file.h12
-rw-r--r--source/kit/input_buffer.c12
-rw-r--r--source/kit/input_buffer.h3
-rw-r--r--source/test/unittests/input_buffer.test.c2
5 files changed, 19 insertions, 16 deletions
diff --git a/source/kit/file.c b/source/kit/file.c
index bb32cdb..ff3a18d 100644
--- a/source/kit/file.c
+++ b/source/kit/file.c
@@ -295,7 +295,7 @@ kit_status_t kit_file_remove_recursive(kit_str_t const path,
return KIT_ERROR;
}
-int kit_path_type(kit_str_t const path) {
+kit_path_type_t kit_path_type(kit_str_t const path) {
PREPARE_PATH_BUF_;
#if defined(_WIN32) && !defined(__CYGWIN__)
if (PathFileExistsW(buf)) {
@@ -307,9 +307,9 @@ int kit_path_type(kit_str_t const path) {
#else
struct stat info;
if (stat(buf, &info) == 0) {
- if ((info.st_mode & S_IFREG) != 0)
+ if (S_ISREG(info.st_mode))
return KIT_PATH_FILE;
- if ((info.st_mode & S_IFDIR) != 0)
+ if (S_ISDIR(info.st_mode))
return KIT_PATH_FOLDER;
}
#endif
diff --git a/source/kit/file.h b/source/kit/file.h
index 68abea0..e85a076 100644
--- a/source/kit/file.h
+++ b/source/kit/file.h
@@ -17,12 +17,13 @@ extern "C" {
# define KIT_ENV_HOME "HOME"
#endif
-enum {
+typedef enum {
KIT_PATH_NONE,
KIT_PATH_FILE,
- KIT_PATH_FOLDER,
- KIT_FILE_SIZE_ERROR = -1
-};
+ KIT_PATH_FOLDER
+} kit_path_type_t;
+
+enum { KIT_FILE_SIZE_ERROR = -1 };
kit_string_t kit_path_norm(kit_str_t path, kit_allocator_t alloc);
@@ -46,7 +47,7 @@ kit_status_t kit_file_remove_folder(kit_str_t path);
kit_status_t kit_file_remove_recursive(kit_str_t path,
kit_allocator_t alloc);
-int kit_path_type(kit_str_t path);
+kit_path_type_t kit_path_type(kit_str_t path);
ptrdiff_t kit_file_size(kit_str_t path);
@@ -71,6 +72,7 @@ void kit_path_list_destroy(kit_path_list_t list);
# define file_remove_recursive kit_file_remove_recursive
# define path_type kit_path_type
# define file_size kit_file_size
+# define path_type_t kit_path_type_t
# define path_list_t kit_path_list_t
# define file_enum_folder kit_file_enum_folder
# define path_list_destroy kit_path_list_destroy
diff --git a/source/kit/input_buffer.c b/source/kit/input_buffer.c
index eae0f1a..5c38c22 100644
--- a/source/kit/input_buffer.c
+++ b/source/kit/input_buffer.c
@@ -71,25 +71,25 @@ kit_ib_handle_t kit_ib_wrap(kit_is_handle_t upstream,
kit_allocator_t alloc) {
kit_ib_handle_t buf;
memset(&buf, 0, sizeof buf);
- buf.error = 0;
+ buf.status = KIT_OK;
DA_INIT(buf.data, 0, alloc);
buf.internal = buf_init(upstream, alloc);
if (buf.internal == NULL)
- buf.error = 1;
+ buf.status = KIT_ERROR;
return buf;
}
kit_ib_handle_t kit_ib_read(kit_ib_handle_t buf, ptrdiff_t size) {
kit_ib_handle_t next;
memset(&next, 0, sizeof next);
- if (buf.error) {
- next.error = 1;
+ if (buf.status != KIT_OK) {
+ next.status = buf.status;
} else {
buf_acquire(buf.internal);
buf_adjust(buf.internal, buf.offset + size);
DA_INIT(next.data, size, buf_alloc(buf.internal));
if (next.data.size != size)
- next.error = 1;
+ next.status = KIT_ERROR;
kit_out_str_t destination = { .size = next.data.size,
.values = next.data.values };
ptrdiff_t n = buf_read(buf.internal, buf.offset, destination);
@@ -97,7 +97,7 @@ kit_ib_handle_t kit_ib_read(kit_ib_handle_t buf, ptrdiff_t size) {
next.internal = buf.internal;
DA_RESIZE(next.data, n);
if (next.data.size != n)
- next.error = 1;
+ next.status = KIT_ERROR;
}
return next;
}
diff --git a/source/kit/input_buffer.h b/source/kit/input_buffer.h
index 7c81da1..1b4329f 100644
--- a/source/kit/input_buffer.h
+++ b/source/kit/input_buffer.h
@@ -3,13 +3,14 @@
#include "dynamic_array.h"
#include "input_stream.h"
+#include "status.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
- int error;
+ kit_status_t status;
ptrdiff_t offset;
void *internal;
kit_string_t data;
diff --git a/source/test/unittests/input_buffer.test.c b/source/test/unittests/input_buffer.test.c
index 175537c..f1b3738 100644
--- a/source/test/unittests/input_buffer.test.c
+++ b/source/test/unittests/input_buffer.test.c
@@ -10,7 +10,7 @@ TEST("input buffer read once") {
ib_handle_t second = ib_read(first, 3);
- REQUIRE(!second.error);
+ REQUIRE(second.status == KIT_OK);
REQUIRE(second.data.size == 3);
REQUIRE(AR_EQUAL(text, second.data));