aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2026-06-20 11:09:03 +0200
committerFelix Morgner <felix.morgner@gmail.com>2026-06-20 11:09:03 +0200
commit280190248bfbadaec4575932dc956401f7bb6390 (patch)
tree70eb2d797349127e68108f0d1ed58e87ddecd5ea
parent1ae9669c30089447212b05104a239c0866890116 (diff)
downloadttwhy-280190248bfbadaec4575932dc956401f7bb6390.tar.xz
ttwhy-280190248bfbadaec4575932dc956401f7bb6390.zip
lib: harden scoped attributes
-rw-r--r--ttwhy/scoped_attributes.cppm12
1 files changed, 9 insertions, 3 deletions
diff --git a/ttwhy/scoped_attributes.cppm b/ttwhy/scoped_attributes.cppm
index c68ab01..080bca7 100644
--- a/ttwhy/scoped_attributes.cppm
+++ b/ttwhy/scoped_attributes.cppm
@@ -56,9 +56,15 @@ namespace ttwhy
export struct scoped_attributes
{
explicit scoped_attributes(int file_descriptor)
- : m_file_descriptor{::dup(file_descriptor)}
- , m_attributes{read_attributes(file_descriptor)}
- {}
+ : m_file_descriptor{-1}
+ , m_attributes{}
+ {
+ if (isatty(file_descriptor))
+ {
+ m_file_descriptor = dup(file_descriptor);
+ m_attributes = read_attributes(m_file_descriptor);
+ }
+ }
scoped_attributes(scoped_attributes const &) = delete;