mirror of
https://git.sr.ht/~nabijaczleweli/tzpfms
synced 2025-04-11 09:30:02 +03:00
Now with_stdin_at() doesn't need the scope wrapper
This commit is contained in:
parent
1d39364a02
commit
887f9b6386
@ -4,21 +4,21 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "common.hpp"
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
template <class F>
|
||||
int with_stdin_at(int fd, F && what) {
|
||||
auto stdin_saved = dup(0);
|
||||
quickscope_wrapper stdin_saved_deleter{[=] { close(stdin_saved); }};
|
||||
|
||||
dup2(fd, 0);
|
||||
clearerr(stdin);
|
||||
int ret = what();
|
||||
|
||||
dup2(stdin_saved, 0);
|
||||
close(stdin_saved);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user