Changeset 925a21e in mainline for uspace/lib/c/generic/io/io.c


Ignore:
Timestamp:
2011-09-24T14:20:29Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5bf76c1
Parents:
867e2555 (diff), 1ab4aca (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/io/io.c

    r867e2555 r925a21e  
    4545#include <vfs/vfs.h>
    4646#include <vfs/vfs_sess.h>
    47 #include <ipc/devmap.h>
     47#include <ipc/loc.h>
    4848#include <adt/list.h>
    4949#include "../private/io.h"
     
    101101static LIST_INITIALIZE(files);
    102102
    103 void __stdio_init(int filc, fdi_node_t *filv[])
     103void __stdio_init(int filc)
    104104{
    105105        if (filc > 0) {
    106                 stdin = fopen_node(filv[0], "r");
     106                stdin = fdopen(0, "r");
    107107        } else {
    108108                stdin = &stdin_null;
     
    111111       
    112112        if (filc > 1) {
    113                 stdout = fopen_node(filv[1], "w");
     113                stdout = fdopen(1, "w");
    114114        } else {
    115115                stdout = &stdout_klog;
     
    118118       
    119119        if (filc > 2) {
    120                 stderr = fopen_node(filv[2], "w");
     120                stderr = fdopen(2, "w");
    121121        } else {
    122122                stderr = &stderr_klog;
     
    285285}
    286286
    287 FILE *fopen_node(fdi_node_t *node, const char *mode)
    288 {
    289         int flags;
    290         if (!parse_mode(mode, &flags))
    291                 return NULL;
    292        
    293         /* Open file. */
    294         FILE *stream = malloc(sizeof(FILE));
    295         if (stream == NULL) {
    296                 errno = ENOMEM;
    297                 return NULL;
    298         }
    299        
    300         stream->fd = open_node(node, flags);
    301         if (stream->fd < 0) {
    302                 /* errno was set by open_node() */
    303                 free(stream);
    304                 return NULL;
    305         }
    306        
    307         stream->error = false;
    308         stream->eof = false;
    309         stream->klog = false;
    310         stream->sess = NULL;
    311         stream->need_sync = false;
    312         _setvbuf(stream);
    313        
    314         list_append(&stream->link, &files);
    315        
    316         return stream;
    317 }
    318 
    319287int fclose(FILE *stream)
    320288{
     
    450418
    451419        bytes_used = stream->buf_head - stream->buf_tail;
    452         if (bytes_used == 0)
    453                 return;
    454420
    455421        /* If buffer has prefetched read data, we need to seek back. */
    456         if (stream->buf_state == _bs_read)
     422        if (bytes_used > 0 && stream->buf_state == _bs_read)
    457423                lseek(stream->fd, - (ssize_t) bytes_used, SEEK_CUR);
    458424
    459425        /* If buffer has unwritten data, we need to write them out. */
    460         if (stream->buf_state == _bs_write)
     426        if (bytes_used > 0 && stream->buf_state == _bs_write)
    461427                (void) _fwrite(stream->buf_tail, 1, bytes_used, stream);
    462428
     
    780746}
    781747
    782 int fnode(FILE *stream, fdi_node_t *node)
    783 {
    784         if (stream->fd >= 0)
    785                 return fd_node(stream->fd, node);
     748int fhandle(FILE *stream, int *handle)
     749{
     750        if (stream->fd >= 0) {
     751                *handle = stream->fd;
     752                return EOK;
     753        }
    786754       
    787755        return ENOENT;
Note: See TracChangeset for help on using the changeset viewer.