Line data Source code
1 : /* SPDX-FileCopyrightText: Copyright 2026 Cozens Software Solutions Limited
2 : * SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0 OR LicenseRef-PolyForm-Internal-Use-1.0.0 OR LicenseRef-COSOSO-Commercial
3 : */
4 :
5 : #include "SolidSyslogNullFile.h"
6 :
7 : #include <stdbool.h>
8 : #include <stddef.h>
9 :
10 : #include "SolidSyslogFileDefinition.h"
11 :
12 : static bool NullFile_Open(struct SolidSyslogFile* base, const char* path);
13 : static void NullFile_Close(struct SolidSyslogFile* base);
14 : static bool NullFile_IsOpen(struct SolidSyslogFile* base);
15 : static bool NullFile_Read(struct SolidSyslogFile* base, void* buf, size_t count);
16 : static bool NullFile_Write(struct SolidSyslogFile* base, const void* buf, size_t count);
17 : static void NullFile_SeekTo(struct SolidSyslogFile* base, size_t offset);
18 : static bool NullFile_Size(struct SolidSyslogFile* base, size_t* size);
19 : static void NullFile_Truncate(struct SolidSyslogFile* base);
20 : static bool NullFile_Exists(struct SolidSyslogFile* base, const char* path);
21 : static bool NullFile_Delete(struct SolidSyslogFile* base, const char* path);
22 :
23 657 : struct SolidSyslogFile* SolidSyslogNullFile_Get(void)
24 : {
25 : static struct SolidSyslogFile instance = {
26 : .Open = NullFile_Open,
27 : .Close = NullFile_Close,
28 : .IsOpen = NullFile_IsOpen,
29 : .Read = NullFile_Read,
30 : .Write = NullFile_Write,
31 : .SeekTo = NullFile_SeekTo,
32 : .Size = NullFile_Size,
33 : .Truncate = NullFile_Truncate,
34 : .Exists = NullFile_Exists,
35 : .Delete = NullFile_Delete,
36 : };
37 657 : return &instance;
38 : }
39 :
40 : /* Open returns false so callers see a consistently non-functional file.
41 : * NullFile is the fallback when PosixFile / WindowsFile / FatFsFile
42 : * Create exhausts the pool - at that point the wider chain
43 : * (BlockStore -> NullStore) is already broken; presenting "open failed"
44 : * lets the consumer's existing error path handle it cleanly. */
45 6 : static bool NullFile_Open(struct SolidSyslogFile* base, const char* path)
46 : {
47 : (void) base;
48 : (void) path;
49 6 : return false;
50 : }
51 :
52 1 : static void NullFile_Close(struct SolidSyslogFile* base)
53 : {
54 : (void) base;
55 1 : }
56 :
57 1 : static bool NullFile_IsOpen(struct SolidSyslogFile* base)
58 : {
59 : (void) base;
60 1 : return false;
61 : }
62 :
63 1 : static bool NullFile_Read(struct SolidSyslogFile* base, void* buf, size_t count)
64 : {
65 : (void) base;
66 : (void) buf;
67 : (void) count;
68 1 : return false;
69 : }
70 :
71 : /* Write returns true so the BlockStore-side caller treats the bytes as
72 : * persisted and does not retry. Mirrors NullSender_Send's drop-on-the-floor. */
73 1 : static bool NullFile_Write(struct SolidSyslogFile* base, const void* buf, size_t count)
74 : {
75 : (void) base;
76 : (void) buf;
77 : (void) count;
78 1 : return true;
79 : }
80 :
81 1 : static void NullFile_SeekTo(struct SolidSyslogFile* base, size_t offset)
82 : {
83 : (void) base;
84 : (void) offset;
85 1 : }
86 :
87 1 : static bool NullFile_Size(struct SolidSyslogFile* base, size_t* size)
88 : {
89 : (void) base;
90 1 : *size = 0U;
91 1 : return false;
92 : }
93 :
94 1 : static void NullFile_Truncate(struct SolidSyslogFile* base)
95 : {
96 : (void) base;
97 1 : }
98 :
99 1 : static bool NullFile_Exists(struct SolidSyslogFile* base, const char* path)
100 : {
101 : (void) base;
102 : (void) path;
103 1 : return false;
104 : }
105 :
106 : /* Delete returns true ("succeeded vacuously") so callers that treat
107 : * delete-of-nonexistent as a no-op are not tripped by the null object. */
108 1 : static bool NullFile_Delete(struct SolidSyslogFile* base, const char* path)
109 : {
110 : (void) base;
111 : (void) path;
112 1 : return true;
113 : }
|