File: file_system.h

package info (click to toggle)
newsboat 2.38-0.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,540 kB
  • sloc: cpp: 90,216; xml: 606; sh: 429; makefile: 369; ruby: 258; python: 239; ansic: 211; php: 63; awk: 59; perl: 38
file content (56 lines) | stat: -rw-r--r-- 1,366 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef NEWSBOAT_FILE_SYSTEM_H_
#define NEWSBOAT_FILE_SYSTEM_H_

#include <string>
#include <sys/stat.h>

#include "3rd-party/optional.hpp"

namespace newsboat {

namespace file_system {

enum class FileType {
	Unknown,
	RegularFile,
	Directory,
	BlockDevice,
	CharDevice,
	Fifo,
	Symlink,
	Socket,
};

FileType mode_to_filetype(mode_t mode);

/// Convert the filetype into an ASCII character that `ls` and others use to
/// represent it.
///
/// \note `Unknown` filetype is represented by a question mark.
char filetype_to_char(FileType type);

/// Get a suffix that `ls --classify` adds to names with given `mode`.
nonstd::optional<char> mode_suffix(mode_t mode);

/// An entry in a listing, e.g. a file, a directory or suchlike.
struct FileSystemEntry {
	FileType filetype;
	std::string name;
};

/// The name of the user with a given UID, padded on the right to the width of
/// 8 characters. If the name is unknown, returns 8 question marks.
std::string get_user_padded(uid_t uid);

/// The name of the group with a given GID, padded on the right to the width of
/// 8 characters. If the name is unknown, returns 8 question marks.
std::string get_group_padded(gid_t gid);

/// Convert permissions into an rwxrwxrwx-style string.
std::string permissions_string(mode_t mode);

} // namespace file_system

} // namespace newsboat

#endif //NEWSBOAT_FILE_SYSTEM_H_