switchbrew / libnx

Library for Switch Homebrew

Home Page:https://switchbrew.github.io/libnx/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The tm struct from gmtime() or localtime() gets corrupted after calling fopen() in append mode

cathery opened this issue · comments

I'm so sorry to create an issue right after you guys published a new release. I've encountered this issue in libnx-master and continue to have it in libnx 3.0.0, calling fopen with any filename in any append mode causes the tm struct to lose its hour, minute and second values. For reference, this does not happen in libnx 2.5.0.

Pastebin of code I used to replicate the issue. This is an edit of the time example from switch-examples. Calling fopen here before initializing all the variables causes the printf function to output 00:00:00. On the other hand, calling fopen AFTER initializing all the variables produces normal output. You don't even have to write anything to said file. Also, calling fopen in any of read/write modes produces normal output again.

It sounds like you want localtime_r() not localtime() - shouldn't assume the contents are unchanged afterwards when calling {POSIX funcs} with the latter.

Thank you, this solved the issue. I had no idea this was even an option.