2 * hl_open.c -- provide _open().
4 * Copyright (c) 2024 Synopsys Inc.
6 * The authors hereby grant permission to use, copy, modify, distribute,
7 * and license this software and its documentation for any purpose, provided
8 * that existing copyright notices are retained in all copies and that this
9 * notice is included verbatim in any distributions. No written agreement,
10 * license, or royalty fee is required for any of the authorized uses.
11 * Modifications to this software may be copyrighted by their authors
12 * and need not follow the licensing terms described here, provided that
13 * the new terms are clearly indicated on the first page of each file where
22 #include <sys/types.h>
25 #include "hl_toolchain.h"
28 /* Map newlib open flags into Hostlink IO ones. */
29 static __always_inline
uint32_t
30 _hl_open_flags_map (int flags
)
32 uint32_t hl_flags
= 0;
34 hl_flags
|= (flags
& O_RDONLY
) ? 0x0000 : 0;
35 hl_flags
|= (flags
& O_WRONLY
) ? 0x0001 : 0;
36 hl_flags
|= (flags
& O_RDWR
) ? 0x0002 : 0;
37 hl_flags
|= (flags
& O_APPEND
) ? 0x0008 : 0;
38 hl_flags
|= (flags
& O_CREAT
) ? 0x0100 : 0;
39 hl_flags
|= (flags
& O_TRUNC
) ? 0x0200 : 0;
40 hl_flags
|= (flags
& O_EXCL
) ? 0x0400 : 0;
45 /* Open file on host. Implements HL_SYSCALL_OPEN. */
46 static __always_inline
int
47 _hl_open (const char *path
, int flags
, mode_t mode
)
51 uint32_t hl_flags
= _hl_open_flags_map (flags
);
52 volatile __uncached
char *p
;
54 p
= _hl_message (HL_SYSCALL_OPEN
, "sii:ii",
56 (uint32_t) hl_flags
, /* i */
57 (uint32_t) mode
, /* i */
58 (uint32_t *) &fd
, /* :i */
59 (uint32_t *) &host_errno
/* :i */);
78 _open (const char *path
, int flags
, ...)
86 mode
= va_arg (ap
, mode_t
);
88 return _hl_open (path
, flags
, mode
);