Skip to content

Commit 20339e5

Browse files
add new features
1 parent a76fa40 commit 20339e5

File tree

2 files changed

+519
-0
lines changed

2 files changed

+519
-0
lines changed

code/logic/fossil/io/stream.h

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,163 @@ int32_t fossil_fstream_delete(const char *filename);
185185
*/
186186
int32_t fossil_fstream_rename(const char *old_filename, const char *new_filename);
187187

188+
/**
189+
* Read file with buffering.
190+
*
191+
* This function reads a file with buffering.
192+
*
193+
* @param filename The name of the file to read.
194+
* @param buffer Pointer to the buffer to store the read data.
195+
* @param size Size of the buffer to read.
196+
* @return 0 on success, non-zero on failure.
197+
*/
198+
int fossil_fstream_read_buffered(const char *filename, void *buffer, size_t size);
199+
200+
/**
201+
* Write file with buffering.
202+
*
203+
* This function writes a file with buffering.
204+
*
205+
* @param filename The name of the file to write.
206+
* @param data Pointer to the data to write.
207+
* @param size Size of the data to write.
208+
* @return 0 on success, non-zero on failure.
209+
*/
210+
int fossil_fstream_write_buffered(const char *filename, const void *data, size_t size);
211+
212+
/**
213+
* Append file with buffering.
214+
*
215+
* This function appends a file with buffering.
216+
*
217+
* @param filename The name of the file to append.
218+
* @param data Pointer to the data to append.
219+
* @param size Size of the data to append.
220+
* @return 0 on success, non-zero on failure.
221+
*/
222+
int fossil_fstream_lock(const char *filename);
223+
224+
/**
225+
* Lock a file.
226+
*
227+
* This function locks a file.
228+
*
229+
* @param filename The name of the file to lock.
230+
* @return 0 on success, non-zero on failure.
231+
*/
232+
int fossil_fstream_unlock(const char *filename);
233+
234+
/**
235+
* Get the type of a file stream.
236+
*
237+
* This function retrieves the type of a file stream.
238+
*
239+
* @param filename The name of the file to get the type of.
240+
* @return The type of the file stream.
241+
*/
242+
int fossil_fstream_get_type(const char *filename);
243+
244+
/**
245+
* Check if a file stream is open.
246+
*
247+
* This function checks whether a given fossil_fstream_t structure represents
248+
* an open file stream.
249+
*
250+
* @param stream Pointer to the fossil_fstream_t structure to check.
251+
* @return 1 if the stream is open, 0 if it is not.
252+
*/
253+
int32_t fossil_fstream_is_open(const fossil_fstream_t *stream);
254+
255+
/**
256+
* Read the entire contents of a file into a dynamically allocated buffer.
257+
*
258+
* This function reads the entire contents of a file associated with an open stream
259+
* and returns the data in a dynamically allocated buffer. The caller is responsible
260+
* for freeing the buffer.
261+
*
262+
* @param stream Pointer to the fossil_fstream_t structure from which to read.
263+
* @param buffer Pointer to the pointer where the data buffer will be stored.
264+
* @param size Pointer to store the size of the read data.
265+
* @return 0 on success, non-zero on failure.
266+
*/
267+
int32_t fossil_fstream_read_all(fossil_fstream_t *stream, void **buffer, size_t *size);
268+
269+
/**
270+
* Write a buffer to a file, overwriting any existing contents.
271+
*
272+
* This function writes the entire buffer contents to a file associated with an
273+
* open stream, overwriting any existing data in the file.
274+
*
275+
* @param stream Pointer to the fossil_fstream_t structure to which to write.
276+
* @param buffer Pointer to the buffer containing the data to write.
277+
* @param size Size of the buffer to write.
278+
* @return 0 on success, non-zero on failure.
279+
*/
280+
int32_t fossil_fstream_write_all(fossil_fstream_t *stream, const void *buffer, size_t size);
281+
282+
/**
283+
* Check file permissions.
284+
*
285+
* This function checks the read, write, or execute permissions of a specified file.
286+
*
287+
* @param filename The name of the file to check.
288+
* @param mode The permission to check: "r" for read, "w" for write, "x" for execute.
289+
* @return 1 if the permission is granted, 0 otherwise.
290+
*/
291+
int32_t fossil_fstream_check_permission(const char *filename, const char *mode);
292+
293+
/**
294+
* Set file permissions.
295+
*
296+
* This function sets the permissions of a specified file.
297+
*
298+
* @param filename The name of the file.
299+
* @param mode The permission mode to set (e.g., 0644 for rw-r--r--).
300+
* @return 0 on success, non-zero on failure.
301+
*/
302+
int32_t fossil_fstream_set_permissions(const char *filename, int32_t mode);
303+
304+
/**
305+
* Get file permissions.
306+
*
307+
* This function retrieves the current permissions of a specified file.
308+
*
309+
* @param filename The name of the file.
310+
* @return The permissions of the file as an integer (e.g., 0644), or -1 on failure.
311+
*/
312+
int32_t fossil_fstream_get_permissions(const char *filename);
313+
314+
/**
315+
* Restrict file permissions.
316+
*
317+
* This function restricts the permissions of a specified file to the owner only.
318+
*
319+
* @param filename The name of the file.
320+
* @return 0 on success, non-zero on failure.
321+
*/
322+
int32_t fossil_fstream_restrict(const char *filename);
323+
324+
/**
325+
* Check file ownership.
326+
*
327+
* This function checks if the current user owns the specified file.
328+
*
329+
* @param filename The name of the file.
330+
* @return 1 if the user owns the file, 0 otherwise.
331+
*/
332+
int32_t fossil_fstream_check_ownership(const char *filename);
333+
334+
/**
335+
* Compare the permissions of two files.
336+
*
337+
* This function compares the permissions of two files and returns the difference.
338+
*
339+
* @param file1 The name of the first file.
340+
* @param file2 The name of the second file.
341+
* @return The difference in permissions between the two files.
342+
*/
343+
int32_t fossil_fstream_compare_permissions(const char *file1, const char *file2);
344+
188345
#ifdef __cplusplus
189346
}
190347
#endif

0 commit comments

Comments
 (0)