Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: add fs_stdio_hide() and fs_stdio_restore() helpers #559

Merged
merged 1 commit into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/re_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,6 @@ int fs_gethome(char *path, size_t sz);
bool fs_isdir(const char *path);
bool fs_isfile(const char *file);
int fs_fopen(FILE **fp, const char *file, const char *mode);

void fs_stdio_hide(void);
void fs_stdio_restore(void);
25 changes: 25 additions & 0 deletions src/sys/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,28 @@ int fs_fopen(FILE **fp, const char *file, const char *mode)
return 0;
#endif
}


/**
* Hide/Close stdout and stderr output
*/
void fs_stdio_hide(void)
{
(void)fclose(stdout);
(void)fclose(stderr);
}


/**
* Restore stdout and stderr output
*/
void fs_stdio_restore(void)
{
#ifdef WIN32
(void)freopen("CON", "w", stdout);
(void)freopen("CON", "w", stderr);
#else
(void)freopen("/dev/tty", "w", stdout);
(void)freopen("/dev/tty", "w", stderr);
#endif
}