2021-02-28 02:18:39 +01:00
|
|
|
/* See the end of this file for copyright, license, and warranty information. */
|
2021-01-05 14:38:06 +01:00
|
|
|
|
2021-08-01 04:22:09 +02:00
|
|
|
#include <ardix/file.h>
|
2021-01-05 14:38:06 +01:00
|
|
|
#include <ardix/malloc.h>
|
|
|
|
#include <ardix/syscall.h>
|
|
|
|
#include <ardix/userspace.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <toolchain.h>
|
|
|
|
|
2021-08-08 20:48:55 +02:00
|
|
|
long sys_write(int fd, __user const void *buf, size_t len)
|
2021-01-05 14:38:06 +01:00
|
|
|
{
|
2021-08-08 20:48:55 +02:00
|
|
|
long ret = 0;
|
2021-08-01 04:22:09 +02:00
|
|
|
void *copy;
|
2021-01-05 14:38:06 +01:00
|
|
|
|
2021-08-01 04:22:09 +02:00
|
|
|
struct file *f = file_get(fd);
|
|
|
|
if (f == NULL)
|
2021-01-07 12:29:45 +01:00
|
|
|
return -EBADF;
|
2021-01-05 14:38:06 +01:00
|
|
|
|
2021-08-12 14:34:18 +02:00
|
|
|
copy = kmalloc(len);
|
2021-08-01 04:22:09 +02:00
|
|
|
if (copy == NULL) {
|
|
|
|
file_put(f);
|
2021-01-05 14:38:06 +01:00
|
|
|
return -ENOMEM;
|
2021-08-01 04:22:09 +02:00
|
|
|
}
|
2021-01-05 14:38:06 +01:00
|
|
|
|
2021-08-01 04:22:09 +02:00
|
|
|
len = copy_from_user(copy, buf, len);
|
|
|
|
ret = file_write(f, copy, len);
|
2021-01-07 12:29:45 +01:00
|
|
|
|
2021-08-12 14:34:18 +02:00
|
|
|
kfree(copy);
|
2021-08-01 04:22:09 +02:00
|
|
|
file_put(f);
|
2021-01-07 12:30:32 +01:00
|
|
|
return ret;
|
2021-01-05 14:38:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2021-02-28 02:18:39 +01:00
|
|
|
* This file is part of Ardix.
|
|
|
|
* Copyright (c) 2020, 2021 Felix Kopp <owo@fef.moe>.
|
2021-01-05 14:38:06 +01:00
|
|
|
*
|
2021-05-10 16:19:38 +02:00
|
|
|
* Ardix is non-violent software: you may only use, redistribute,
|
|
|
|
* and/or modify it under the terms of the CNPLv6+ as found in
|
|
|
|
* the LICENSE file in the source code root directory or at
|
|
|
|
* <https://git.pixie.town/thufie/CNPL>.
|
2021-01-05 14:38:06 +01:00
|
|
|
*
|
2021-05-10 16:19:38 +02:00
|
|
|
* Ardix comes with ABSOLUTELY NO WARRANTY, to the extent
|
|
|
|
* permitted by applicable law. See the CNPLv6+ for details.
|
2021-01-05 14:38:06 +01:00
|
|
|
*/
|