mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-24 00:55:07 +03:00
The inode is useful to check if two file descriptors refer to the same file. Add a function to retrieve it. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
51 lines
1 KiB
C++
51 lines
1 KiB
C++
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
/*
|
|
* Copyright (C) 2019, Google Inc.
|
|
*
|
|
* file_descriptor.h - File descriptor wrapper
|
|
*/
|
|
#ifndef __LIBCAMERA_FILE_DESCRIPTOR_H__
|
|
#define __LIBCAMERA_FILE_DESCRIPTOR_H__
|
|
|
|
#include <memory>
|
|
#include <sys/types.h>
|
|
|
|
namespace libcamera {
|
|
|
|
class FileDescriptor final
|
|
{
|
|
public:
|
|
explicit FileDescriptor(const int &fd = -1);
|
|
explicit FileDescriptor(int &&fd);
|
|
FileDescriptor(const FileDescriptor &other);
|
|
FileDescriptor(FileDescriptor &&other);
|
|
~FileDescriptor();
|
|
|
|
FileDescriptor &operator=(const FileDescriptor &other);
|
|
FileDescriptor &operator=(FileDescriptor &&other);
|
|
|
|
bool isValid() const { return fd_ != nullptr; }
|
|
int fd() const { return fd_ ? fd_->fd() : -1; }
|
|
FileDescriptor dup() const;
|
|
|
|
ino_t inode() const;
|
|
|
|
private:
|
|
class Descriptor
|
|
{
|
|
public:
|
|
Descriptor(int fd, bool duplicate);
|
|
~Descriptor();
|
|
|
|
int fd() const { return fd_; }
|
|
|
|
private:
|
|
int fd_;
|
|
};
|
|
|
|
std::shared_ptr<Descriptor> fd_;
|
|
};
|
|
|
|
} /* namespace libcamera */
|
|
|
|
#endif /* __LIBCAMERA_FILE_DESCRIPTOR_H__ */
|