Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Merge branch 'devel'
[palacios.git] / kitten / kernel / linux_syscalls / write.c
1 #include <lwk/kernel.h>
2 #include <lwk/task.h>
3 #include <arch/uaccess.h>
4
5 ssize_t
6 sys_write(unsigned int fd, const char __user * buf, size_t count)
7 {
8         char    kbuf[512];
9         size_t  kcount = count;
10
11         /* For now we only support stdout console output */
12         if (fd != 1)
13                 return -EBADF;
14
15         /* Protect against overflowing the kernel buffer */
16         if (kcount >= sizeof(kbuf))
17                 kcount = sizeof(kbuf) - 1;
18
19         /* Copy the user-level string to a kernel buffer */
20         if (copy_from_user(kbuf, buf, kcount))
21                 return -EFAULT;
22         kbuf[kcount] = '\0';
23
24         /* Write the string to the local console */
25         printk(KERN_USERMSG
26                 "(%s) %s%s",
27                 current->name,
28                 kbuf,
29                 (kcount != count) ? " <TRUNCATED>" : ""
30         );
31
32         /* Return number of characters actually printed */
33         return kcount;
34 }
35