--- nono/lib/autofd.h 2026/04/29 17:04:48 1.1.1.1 +++ nono/lib/autofd.h 2026/04/29 17:04:57 1.1.1.2 @@ -4,6 +4,8 @@ // Licensed under nono-license.txt // +#pragma once + #include // 自動変数みたいな生存期間を持つディスクリプタ @@ -18,7 +20,7 @@ class autofd } ~autofd() { - if (fd >= 0) + if (Valid()) close(fd); } @@ -40,6 +42,11 @@ class autofd return rv; } + // fd が有効なら true を返す + bool Valid() const { + return (fd >= 0); + } + public: int fd; };