plptools
Loading...
Searching...
No Matches
plpdirent.cc
Go to the documentation of this file.
1/*
2 * This file is part of plptools.
3 *
4 * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
5 * Copyright (c) 2026 Jason Morley <hello@jbmorley.co.uk>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * along with this program; if not, see <https://www.gnu.org/licenses/>.
19 *
20 */
21#include "config.h"
22#include "rfsv.h"
23
24#include "plpdirent.h"
25
26#include "pathutils.h"
27
28#include <cstdint>
29#include <iomanip>
30
31using namespace std;
32
34 memset(uid, 0, sizeof(uid));
35}
36
37PlpUID::PlpUID(const uint32_t u1, const uint32_t u2, const uint32_t u3) {
38 uid[0] = u1; uid[1] = u2; uid[2] = u3;
39}
40
41uint32_t PlpUID::operator[](int idx) {
42 assert ((idx > -1) && (idx < 3));
43 return uid[idx];
44}
45
47: size(0)
48, attr(0)
49, UID()
50, time(time_t(0))
51, attrstr("")
52, dirname_("")
53, name("") {
54}
55
56PlpDirent::PlpDirent(const uint32_t _size,
57 const uint32_t _attr,
58 const uint32_t tHi,
59 const uint32_t tLo,
60 const std::string &dirname,
61 const char * const _name)
62: size(_size)
63, attr(_attr)
64, UID()
65, time(tHi, tLo)
66, attrstr("")
67, dirname_(dirname)
68, name(_name) {
69}
70
71uint32_t PlpDirent::getSize() const {
72 return size;
73}
74
75uint32_t PlpDirent::getAttr() const {
76 return attr;
77}
78
80 return (attr & RFSV::PSI_A_DIR) > 0;
81}
82
83uint32_t PlpDirent::getUID(int uididx) {
84 if ((uididx >= 0) && (uididx < 4))
85 return UID[uididx];
86 return 0;
87}
88
90 return UID;
91}
92
93std::string PlpDirent::getPath() const {
95 pathComponents.push_back(name);
96 if (isDirectory()) {
97 pathComponents.push_back("");
98 }
99 return join(pathComponents, pathutils::PathFormat::kEPOC);
100}
101
102const char *PlpDirent::getName() const {
103 return name.c_str();
104}
105
107 return time;
108}
109
110void PlpDirent::setName(const char *str) {
111 name = str;
112}
113
115 ostream::fmtflags old = o.flags();
116
117 o << e.attrstr << " " << dec << setw(10)
118 << setfill(' ') << e.size << " " << e.time
119 << " " << e.name;
120 o.flags(old);
121 return o;
122}
A class, representing a directory entry of the Psion.
Definition: plpdirent.h:79
PlpUID & getUID()
Retrieves the PlpUID object of a directory entry.
Definition: plpdirent.cc:89
uint32_t getAttr() const
Retrieves the file attributes of a directory entry.
Definition: plpdirent.cc:75
std::string dirname_
Definition: plpdirent.h:199
std::string attrstr
Definition: plpdirent.h:198
std::string getPath() const
Definition: plpdirent.cc:93
PsiTime time
Definition: plpdirent.h:197
const char * getName() const
Retrieve the file name of a directory entry.
Definition: plpdirent.cc:102
std::string name
Definition: plpdirent.h:200
PlpDirent()
Default constructor.
Definition: plpdirent.cc:46
bool isDirectory() const
Determine if the directory entry represents a directory.
Definition: plpdirent.cc:79
PlpUID UID
Definition: plpdirent.h:196
void setName(const char *str)
Set the file name of a directory entry.
Definition: plpdirent.cc:110
uint32_t attr
Definition: plpdirent.h:195
PsiTime getPsiTime()
Retrieve the modification time of a directory entry.
Definition: plpdirent.cc:106
uint32_t size
Definition: plpdirent.h:194
uint32_t getSize() const
Retrieves the file size of a directory entry.
Definition: plpdirent.cc:71
A class, representing the UIDs of a file on the Psion.
Definition: plpdirent.h:41
long uid[3]
Definition: plpdirent.h:64
PlpUID()
Default constructor.
Definition: plpdirent.cc:33
uint32_t operator[](int idx)
Retrieve a UID value.
Definition: plpdirent.cc:41
Psion time related utility class.
Definition: psitime.h:124
@ PSI_A_DIR
Definition: rfsv.h:202
static char * dirname(const char *dir)
Definition: fuse.c:171
std::vector< std::string > split(const std::string &path, const PathFormat format)
Split a path, path, into its components, using the path separator, separator.
Definition: pathutils.cc:142
Definition: doctest.h:522
ostream & operator<<(ostream &o, const PlpDirent &e)
Definition: plpdirent.cc:114