From 6fbe24a4e92c5aa164e87c4a226eddcfe4fc6cb8 Mon Sep 17 00:00:00 2001 From: namark <namark@disroot.org> Date: Sat, 12 Jun 2021 03:25:27 +0400 Subject: [PATCH] Gotta love "everything is a file", except file is not a file -_- it's a stream, how impressive, what an abstraction, wow --- source/simple/file.hpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/source/simple/file.hpp b/source/simple/file.hpp index 5f5fb34..84e2f7c 100644 --- a/source/simple/file.hpp +++ b/source/simple/file.hpp @@ -1,5 +1,5 @@ -#ifndef _SIMPLE_FILE_HPP -#define _SIMPLE_FILE_HPP +#ifndef SIMPLE_FILE_HPP +#define SIMPLE_FILE_HPP #include <iosfwd> #include <type_traits> @@ -159,11 +159,23 @@ namespace string_stack inline size_type size(stream&& file) { + // TODO FIXME: does not work on text steams and generally is undefined behavior apparently -_- file.seekg(0, file.end); auto ret = file.tellg(); return ret; } + // supa slow way + std::streamsize defined_size(stream& file) + { + file.ignore( std::numeric_limits<std::streamsize>::max() ); + std::streamsize size = file.gcount(); + file.clear(); + file.seekg( 0, file.beg ); + return size; + } + // just read it (trollface) + inline void dump(stream& from, char* to, size_type this_much) { auto _size = size(from); -- GitLab