Ignore:
File:
1 edited

Legend:

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

    r0803134 r82582e4  
    4444#include <io/klog.h>
    4545#include <vfs/vfs.h>
    46 #include <vfs/vfs_sess.h>
    4746#include <ipc/devmap.h>
    4847#include <adt/list.h>
    4948#include "../private/io.h"
    50 #include "../private/stdio.h"
    5149
    5250static void _ffillbuf(FILE *stream);
     
    5856        .eof = true,
    5957        .klog = false,
    60         .sess = NULL,
     58        .phone = -1,
    6159        .btype = _IONBF,
    6260        .buf = NULL,
     
    7270        .eof = false,
    7371        .klog = true,
    74         .sess = NULL,
     72        .phone = -1,
    7573        .btype = _IOLBF,
    7674        .buf = NULL,
     
    8684        .eof = false,
    8785        .klog = true,
    88         .sess = NULL,
     86        .phone = -1,
    8987        .btype = _IONBF,
    9088        .buf = NULL,
     
    127125void __stdio_done(void)
    128126{
    129         while (!list_empty(&files)) {
    130                 FILE *file = list_get_instance(list_first(&files), FILE, link);
     127        link_t *link = files.next;
     128       
     129        while (link != &files) {
     130                FILE *file = list_get_instance(link, FILE, link);
    131131                fclose(file);
     132                link = files.next;
    132133        }
    133134}
     
    254255        stream->eof = false;
    255256        stream->klog = false;
    256         stream->sess = NULL;
     257        stream->phone = -1;
    257258        stream->need_sync = false;
    258259        _setvbuf(stream);
     
    276277        stream->eof = false;
    277278        stream->klog = false;
    278         stream->sess = NULL;
     279        stream->phone = -1;
    279280        stream->need_sync = false;
    280281        _setvbuf(stream);
     
    308309        stream->eof = false;
    309310        stream->klog = false;
    310         stream->sess = NULL;
     311        stream->phone = -1;
    311312        stream->need_sync = false;
    312313        _setvbuf(stream);
     
    323324        fflush(stream);
    324325       
    325         if (stream->sess != NULL)
    326                 async_hangup(stream->sess);
     326        if (stream->phone >= 0)
     327                async_hangup(stream->phone);
    327328       
    328329        if (stream->fd >= 0)
     
    594595                }
    595596               
    596                 data += now;
     597                buf += now;
    597598                stream->buf_head += now;
    598599                buf_free -= now;
    599600                bytes_left -= now;
    600601                total_written += now;
    601                 stream->buf_state = _bs_write;
    602602               
    603603                if (buf_free == 0) {
     
    607607                }
    608608        }
     609       
     610        if (total_written > 0)
     611                stream->buf_state = _bs_write;
    609612
    610613        if (need_flush)
     
    712715off64_t ftell(FILE *stream)
    713716{
    714         _fflushbuf(stream);
    715717        return lseek(stream->fd, 0, SEEK_CUR);
    716718}
     
    730732        }
    731733       
    732         if ((stream->fd >= 0) && (stream->need_sync)) {
     734        if (stream->fd >= 0 && stream->need_sync) {
    733735                /**
    734736                 * Better than syncing always, but probably still not the
     
    768770}
    769771
    770 async_sess_t *fsession(exch_mgmt_t mgmt, FILE *stream)
     772int fphone(FILE *stream)
    771773{
    772774        if (stream->fd >= 0) {
    773                 if (stream->sess == NULL)
    774                         stream->sess = fd_session(mgmt, stream->fd);
    775                
    776                 return stream->sess;
    777         }
    778        
    779         return NULL;
     775                if (stream->phone < 0)
     776                        stream->phone = fd_phone(stream->fd);
     777               
     778                return stream->phone;
     779        }
     780       
     781        return -1;
    780782}
    781783
Note: See TracChangeset for help on using the changeset viewer.