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

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [posix/] [libposix/] [open.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 open()
3
 *
4
 * Copyright (C) 2007 Bahadir Balban
5
 */
6
 
7
#include <errno.h>
8
#include <stdio.h>
9
#include <stdarg.h>
10
#include <string.h>
11
#include <sys/shm.h>
12
#include <sys/types.h>
13
#include <sys/stat.h>
14
#include <l4lib/ipcdefs.h>
15
#include <l4lib/utcb.h>
16
#include <fcntl.h>
17
#include <l4/macros.h>
18
#include INC_GLUE(memory.h)
19
#include <shpage.h>
20
#include <libposix.h>
21
 
22
static inline int l4_open(const char *pathname, int flags, mode_t mode)
23
{
24
        int fd;
25
 
26
        utcb_full_strcpy_from(pathname);
27
        write_mr(L4SYS_ARG0, flags);
28
        write_mr(L4SYS_ARG1, (u32)mode);
29
 
30
        /* Call pager with open() request. Check ipc error. */
31
        if ((fd = l4_sendrecv_full(pagerid, pagerid, L4_IPC_TAG_OPEN)) < 0) {
32
                print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, fd);
33
                return fd;
34
        }
35
        /* Check if syscall itself was successful */
36
        if ((fd = l4_get_retval()) < 0) {
37
                print_err("%s: OPEN Error: %d, for path %s\n",
38
                       __FUNCTION__, fd, pathname);
39
                return fd;
40
        }
41
        return fd;
42
}
43
 
44
int open(const char *pathname, int oflag, ...)
45
{
46
        int ret;
47
        mode_t mode = 0;
48
 
49
        if (oflag & O_CREAT) {
50
                va_list arg;
51
                va_start(arg, oflag);
52
                mode = va_arg(arg, mode_t);
53
                va_end(arg);
54
        }
55
        ret = l4_open(pathname, oflag, mode);
56
 
57
        /* If error, return positive error code */
58
        if (ret < 0) {
59
                errno = -ret;
60
                return -1;
61
        }
62
        /* else return value */
63
        return ret;
64
 
65
}
66
 

powered by: WebSVN 2.1.0

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