libos: Let users change the buffering mode of a File
This commit is contained in:
parent
dc35c42371
commit
b17793134e
@ -143,6 +143,19 @@ namespace os
|
|||||||
*/
|
*/
|
||||||
Result<void> read(Buffer& buf, usize size);
|
Result<void> read(Buffer& buf, usize size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Read an object from this File.
|
||||||
|
*
|
||||||
|
* @tparam T The type of the object to read.
|
||||||
|
* @param object A reference to the object in question.
|
||||||
|
* @return Result<void> Whether the operation succeeded.
|
||||||
|
*/
|
||||||
|
template <typename T> Result<void> read_typed(T& object)
|
||||||
|
{
|
||||||
|
TRY(raw_read((u8*)&object, sizeof(T)));
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Read the entire File's contents.
|
* @brief Read the entire File's contents.
|
||||||
*
|
*
|
||||||
@ -178,6 +191,20 @@ namespace os
|
|||||||
*/
|
*/
|
||||||
void rewind();
|
void rewind();
|
||||||
|
|
||||||
|
enum BufferingMode
|
||||||
|
{
|
||||||
|
NotBuffered = _IONBF,
|
||||||
|
LineBuffered = _IOLBF,
|
||||||
|
FullyBuffered = _IOFBF,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Change the buffering mode of this File.
|
||||||
|
*
|
||||||
|
* @param mode The buffering mode.
|
||||||
|
*/
|
||||||
|
void set_buffer(BufferingMode mode);
|
||||||
|
|
||||||
File(Badge<File>);
|
File(Badge<File>);
|
||||||
~File();
|
~File();
|
||||||
|
|
||||||
|
@ -226,6 +226,11 @@ namespace os
|
|||||||
fflush(m_file);
|
fflush(m_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void File::set_buffer(BufferingMode mode)
|
||||||
|
{
|
||||||
|
setvbuf(m_file, NULL, mode, 0);
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: Do not allocate memory for printing.
|
// FIXME: Do not allocate memory for printing.
|
||||||
Result<void> print_impl(SharedPtr<File> f, StringView fmt, va_list ap)
|
Result<void> print_impl(SharedPtr<File> f, StringView fmt, va_list ap)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user