/* common/KMFileGuard.cpp
 *
 * Copyright (C) 2024 OpenKylin, Inc
 */

#include "KMFileGuard.h"

#include <unistd.h>

KMFileGuard::KMFileGuard(int fd)
    : m_fd(fd)
{
}

KMFileGuard::~KMFileGuard()
{
    if (m_fd > 2)
    {
        close(m_fd);
    }
}

void KMFileGuard::setFd(int fd)
{
    if (m_fd > 2)
    {
        close(m_fd);
    }

    m_fd = fd;
}
