OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [posix/] [libposix/] [write.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * l4/posix glue for write()
3
 *
4
 * Copyright (C) 2007 Bahadir Balban
5
 */
6
#include <errno.h>
7
#include <stdio.h>
8
#include <sys/types.h>
9
#include <unistd.h>
10
#include <l4lib/ipcdefs.h>
11
#include <libposix.h>
12
 
13
static inline int l4_write(int fd, const void *buf, size_t count)
14
{
15
        int wrcnt;
16
 
17
        write_mr(L4SYS_ARG0, fd);
18
        write_mr(L4SYS_ARG1, (const unsigned long)buf);
19
        write_mr(L4SYS_ARG2, count);
20
 
21
        /* Call pager with write() request. Check ipc error. */
22
        if ((wrcnt = l4_sendrecv(pagerid, pagerid, L4_IPC_TAG_WRITE)) < 0) {
23
                print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, wrcnt);
24
                return wrcnt;
25
        }
26
        /* Check if syscall itself was successful */
27
        if ((wrcnt = l4_get_retval()) < 0) {
28
                print_err("%s: WRITE Error: %d.\n", __FUNCTION__, (int)wrcnt);
29
                return wrcnt;
30
 
31
        }
32
        return wrcnt;
33
}
34
 
35
ssize_t write(int fd, const void *buf, size_t count)
36
{
37
        int ret;
38
 
39
        if (!count)
40
                return 0;
41
 
42
        ret = l4_write(fd, buf, count);
43
 
44
        /* If error, return positive error code */
45
        if (ret < 0) {
46
                errno = -ret;
47
                return -1;
48
        }
49
        /* else return value */
50
        return ret;
51
}
52
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.