user/lib/libc/src/file/default_streams.c
/**
 * Writes a new character to the debug out stream. If it's a newline (or if we reach the
 * maximum bounds of the buffer) we flush the stream.
 */
Writes a new character to the debug out stream. If it's a newline (or if we reach the
maximum bounds of the buffer) we flush the stream.
Writes a new character to the debug out stream . If it ' s a newline ( or if we reach the maximum bounds of the buffer ) we flush the stream .
static int DebugOutPutc(struct __libc_file_stream *_file, char c) {
    struct DebugOutStream *file = (struct DebugOutStream *) _file;
    int err = mtx_lock(&file->header.lock);
    if(err != thrd_success) {
        return EOF;
    }
    file->bytesWritten++;
    if(file->bufUsed == kBufLength) {
        DebugOutFlush(_file);
    }
    if(c == '\n') {
        DebugOutFlush(_file);
    }
    else {
        file->buf[file->bufUsed++] = c;
    }
    mtx_unlock(&file->header.lock);
    return c;
}
static int DebugOutPutc ( struct __libc_file_stream * _file , char c ) { struct DebugOutStream * file = ( struct DebugOutStream * ) _file ; int err = mtx_lock ( & file -> header . lock ) ; if ( err != thrd_success ) { return EOF ; } file -> bytesWritten ++ ; if ( file -> bufUsed == kBufLength ) { DebugOutFlush ( _file ) ; } if ( c == ' \n ' ) { DebugOutFlush ( _file ) ; } else { file -> buf [ file -> bufUsed ++ ] = c ; } mtx_unlock ( & file -> header . lock ) ; return c ; }
Writes a new character to the debug out stream.
Writes a new character to the debug out stream .
// if buffer is full, flush and try again // flush if newline // otherwise, add it into the buffer