Now with_stdin_at() doesn't need the scope wrapper

This commit is contained in:
наб 2024-03-10 03:28:51 +01:00
parent 1d39364a02
commit 887f9b6386
No known key found for this signature in database
GPG Key ID: BCFD0B018D2658F1

View File

@ -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;
}