-
Notifications
You must be signed in to change notification settings - Fork 2
POD File Format Derivates
Jon Daniel edited this page Sep 20, 2024
·
82 revisions
All information here is to my best knowledge, is is not proven by any official reference manual by Terminal Reality.
Sring manipulation
namespace tr::pod::string
{
u32 ceil(u32 len)
{
static const std::array<u32,12> sizes = { 4, 8, 12, 16, 32, 48, 64, 80, 96, 128, 256, 264 };
std::array<u32,12>::const_iterator dst = sizes.begin();
while(size > *dst) dst++;
return *dst;
}
c8* fgets(u32 size, FILE* stream)
{
if(size == 0)
return nullptr;
c8* dst = (c8*)calloc(ceil(size), 1);
for(u32 i = 0; i < size; i++)
{
dst[i] = fgetc(stream);
if(dst[i] == EOF)
dst[i] = '\0';
if(dst[i] == '\0')
break;
}
if(strlen(dst) == 0)
{
free(dst);
dst = nullptr;
}
return dst;
}
c8* ctime(const t32* time)
{
time_t t = (time_t)*time;
c8* dst = std::ctime(&t);
dst[strcspn(dst, "\n")] = '\0';
return dst;
}
};All information here is to my best knowledge, is is not proven by any official reference manual by Microsoft or Terminal Reality.