/trunk/uspace/lib/libc/include/vfs/vfs.h |
---|
55,13 → 55,16 |
extern int mount(const char *, const char *, const char *, const char *, |
unsigned int); |
extern void stdio_init(int filc, fdi_node_t *filv[]); |
extern void stdio_done(void); |
extern int open_node(fdi_node_t *, int); |
extern int fd_phone(int); |
extern void fd_node(int, fdi_node_t *); |
extern int fd_node(int, fdi_node_t *); |
extern FILE *fopen_node(fdi_node_t *, const char *); |
extern int fphone(FILE *); |
extern void fnode(FILE *, fdi_node_t *); |
extern int fnode(FILE *, fdi_node_t *); |
#endif |
/trunk/uspace/lib/libc/include/stdio.h |
---|
37,6 → 37,7 |
#include <sys/types.h> |
#include <stdarg.h> |
#include <libadt/list.h> |
#define EOF (-1) |
55,6 → 56,9 |
#endif |
typedef struct { |
/** Linked list pointer. */ |
link_t link; |
/** Underlying file descriptor. */ |
int fd; |
71,9 → 75,6 |
int phone; |
} FILE; |
extern FILE stdin_null; |
extern FILE stdout_klog; |
extern FILE *stdin; |
extern FILE *stdout; |
extern FILE *stderr; |
/trunk/uspace/lib/libc/generic/task.c |
---|
105,22 → 105,19 |
fdi_node_t stdout_node; |
fdi_node_t stderr_node; |
if ((stdin != NULL) && (stdin != &stdin_null)) { |
fnode(stdin, &stdin_node); |
if ((stdin != NULL) && (fnode(stdin, &stdin_node) == EOK)) |
files[0] = &stdin_node; |
} else |
else |
files[0] = NULL; |
if ((stdout != NULL) && (stdout != &stdout_klog)) { |
fnode(stdout, &stdout_node); |
if ((stdout != NULL) && (fnode(stdout, &stdout_node) == EOK)) |
files[1] = &stdout_node; |
} else |
else |
files[1] = NULL; |
if ((stderr != NULL) && (stderr != &stdout_klog)) { |
fnode(stderr, &stderr_node); |
if ((stderr != NULL) && (fnode(stderr, &stderr_node) == EOK)) |
files[2] = &stderr_node; |
} else |
else |
files[2] = NULL; |
files[3] = NULL; |
/trunk/uspace/lib/libc/generic/libc.c |
---|
79,30 → 79,15 |
if (__pcb == NULL) { |
argc = 0; |
argv = NULL; |
stdio_init(0, NULL); |
} else { |
argc = __pcb->argc; |
argv = __pcb->argv; |
if (__pcb->filc > 0) |
stdin = fopen_node(__pcb->filv[0], "r"); |
if (__pcb->filc > 1) |
stdout = fopen_node(__pcb->filv[1], "w"); |
if (__pcb->filc > 2) |
stderr = fopen_node(__pcb->filv[2], "w"); |
stdio_init(__pcb->filc, __pcb->filv); |
} |
main(argc, argv); |
if (stdin != NULL) |
fclose(stdin); |
if (stdout != NULL) |
fclose(stdout); |
if (stderr != NULL) |
fclose(stderr); |
stdio_done(); |
} |
void __exit(void) |
/trunk/uspace/lib/libc/generic/vfs/vfs.c |
---|
332,7 → 332,7 |
return devmap_device_connect((dev_handle_t) device, 0); |
} |
void fd_node(int fildes, fdi_node_t *node) |
int fd_node(int fildes, fdi_node_t *node) |
{ |
futex_down(&vfs_phone_futex); |
async_serialize_start(); |
351,11 → 351,9 |
node->fs_handle = (fs_handle_t) fs_handle; |
node->dev_handle = (dev_handle_t) dev_handle; |
node->index = (fs_index_t) index; |
} else { |
node->fs_handle = 0; |
node->dev_handle = 0; |
node->index = 0; |
} |
return rc; |
} |
int fsync(int fildes) |
/trunk/uspace/lib/libc/generic/io/io.c |
---|
42,8 → 42,9 |
#include <io/klog.h> |
#include <vfs/vfs.h> |
#include <ipc/devmap.h> |
#include <libadt/list.h> |
FILE stdin_null = { |
static FILE stdin_null = { |
.fd = -1, |
.error = true, |
.eof = true, |
51,7 → 52,7 |
.phone = -1 |
}; |
FILE stdout_klog = { |
static FILE stdout_klog = { |
.fd = -1, |
.error = false, |
.eof = false, |
59,10 → 60,55 |
.phone = -1 |
}; |
FILE *stdin = &stdin_null; |
FILE *stdout = &stdout_klog; |
FILE *stderr = &stdout_klog; |
static FILE stderr_klog = { |
.fd = -1, |
.error = false, |
.eof = false, |
.klog = true, |
.phone = -1 |
}; |
FILE *stdin = NULL; |
FILE *stdout = NULL; |
FILE *stderr = NULL; |
static LIST_INITIALIZE(files); |
void stdio_init(int filc, fdi_node_t *filv[]) |
{ |
if (filc > 0) { |
stdin = fopen_node(filv[0], "r"); |
} else { |
stdin = &stdin_null; |
list_append(&stdin->link, &files); |
} |
if (filc > 1) { |
stdout = fopen_node(filv[1], "w"); |
} else { |
stdout = &stdout_klog; |
list_append(&stdout->link, &files); |
} |
if (filc > 2) { |
stderr = fopen_node(filv[2], "w"); |
} else { |
stderr = &stderr_klog; |
list_append(&stderr->link, &files); |
} |
} |
void stdio_done(void) |
{ |
link_t *link = files.next; |
while (link != &files) { |
FILE *file = list_get_instance(link, FILE, link); |
fclose(file); |
link = files.next; |
} |
} |
static bool parse_mode(const char *mode, int *flags) |
{ |
/* Parse mode except first character. */ |
141,6 → 187,8 |
stream->klog = false; |
stream->phone = -1; |
list_append(&stream->link, &files); |
return stream; |
} |
169,6 → 217,8 |
stream->klog = false; |
stream->phone = -1; |
list_append(&stream->link, &files); |
return stream; |
} |
184,7 → 234,11 |
if (stream->fd >= 0) |
rc = close(stream->fd); |
if ((stream != &stdin_null) && (stream != &stdout_klog)) |
list_remove(&stream->link); |
if ((stream != &stdin_null) |
&& (stream != &stdout_klog) |
&& (stream != &stderr_klog)) |
free(stream); |
stream = NULL; |
353,15 → 407,12 |
return -1; |
} |
void fnode(FILE *stream, fdi_node_t *node) |
int fnode(FILE *stream, fdi_node_t *node) |
{ |
if (stream->fd >= 0) { |
fd_node(stream->fd, node); |
} else { |
node->fs_handle = 0; |
node->dev_handle = 0; |
node->index = 0; |
} |
if (stream->fd >= 0) |
return fd_node(stream->fd, node); |
return ENOENT; |
} |
/** @} |