aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/write.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/core/write.c b/core/write.c
new file mode 100644
index 0000000..a0be81c
--- /dev/null
+++ b/core/write.c
@@ -0,0 +1,30 @@
+#include "../lib/io/io.h"
+#include "../lib/container/container.h"
+
+#define BUFFER_SIZE 128
+char buf[BUFFER_SIZE];
+
+int main(int argc, const char **argv)
+{
+ if (argc != 2) {
+ wstd("write [filename]\n");
+ return -1;
+ }
+
+ int fd = open(argv[1], OPEN_WRITE_ONLY | OPEN_CREATE, MODE_USER_READ | MODE_USER_WRITE | MODE_OTHER_READ | MODE_GROUP_READ);
+
+ container_t *string = new_container(sizeof(char));
+ u64 size;
+
+ while ((size = read(STDIN_FD, buf, BUFFER_SIZE))) {
+ container_append(string, buf, size);
+ }
+
+
+ container_push(string, 0);
+
+ write(fd, string->data, string->size);
+
+ close(fd);
+ return 0;
+}