qLibc
qcount.c File Reference

Counter file handling APIs. More...

Go to the source code of this file.

Functions

int64_t qcount_read (const char *filepath)
 Read an integer counter from a file with advisory file locking.
bool qcount_save (const char *filepath, int64_t number)
 Save an integer counter to a file with advisory file locking.
int64_t qcount_update (const char *filepath, int64_t number)
 Increase or decrease the counter by the given value with advisory file locking.

Detailed Description

Counter file handling APIs.

Definition in file qcount.c.

Function Documentation

◆ qcount_read()

int64_t qcount_read ( const char * filepath)

Read an integer counter from a file with advisory file locking.

Parameters
filepathfile path
Returns
counter value read from the file. On failure, returns 0.
qcount_save("number.dat", 75);
int count = qcount_read("number.dat");
bool qcount_save(const char *filepath, int64_t number)
Save an integer counter to a file with advisory file locking.
Definition qcount.c:95
int64_t qcount_read(const char *filepath)
Read an integer counter from a file with advisory file locking.
Definition qcount.c:65
---- number.dat ----
75
--------------------

Definition at line 65 of file qcount.c.

◆ qcount_save()

bool qcount_save ( const char * filepath,
int64_t number )

Save an integer counter to a file with advisory file locking.

Parameters
filepathfile path
numbercounter value
Returns
true on success, otherwise false.
qcount_save("number.dat", 75);

Definition at line 95 of file qcount.c.

◆ qcount_update()

int64_t qcount_update ( const char * filepath,
int64_t number )

Increase or decrease the counter by the given value with advisory file locking.

Parameters
filepathfile path
numberamount to increase or decrease
Returns
updated counter value. On failure, returns 0.
int count;
count = qcount_update("number.dat", -3);
int64_t qcount_update(const char *filepath, int64_t number)
Increase or decrease the counter by the given value with advisory file locking.
Definition qcount.c:124

Definition at line 124 of file qcount.c.