Basic file lock API.
More...
Go to the source code of this file.
|
| struct | flock_s |
| | File lock structure for managing a single file path. More...
|
| |
|
| #define | flinit(fp) ((struct flock_s){.path = (fp), .fd = -1, .open = 0}) |
| | Initializes a unlocked, ready-to-use file lock structure with the given target lock file path. The file descriptor is set to -1 and is not opened until the file is locked with fllock().
|
| |
|
| int | fllock (struct flock_s *fl) |
| | Locks the file at the given path. If a file descriptor cannot be obtained, or the file cannot be locked, an error code is returned.
|
| |
| int | flunlock (struct flock_s *fl) |
| | Unlocks the file at the given path. If the file is not open, or the file cannot be unlocked, an error code is returned.
|
| |
◆ flinit
| #define flinit |
( |
|
fp | ) |
((struct flock_s){.path = (fp), .fd = -1, .open = 0}) |
Initializes a unlocked, ready-to-use file lock structure with the given target lock file path. The file descriptor is set to -1 and is not opened until the file is locked with fllock().
- Parameters
-
| fp | The file path to use for the lock. |
- Returns
- The initialized file lock structure.
◆ fllock()
Locks the file at the given path. If a file descriptor cannot be obtained, or the file cannot be locked, an error code is returned.
- Note
- The lock must be initialized with
flinit() before calling fllock.
- Parameters
-
| fl | The file lock structure. |
- Returns
- 0 if successful, otherwise a non-zero error code.
◆ flunlock()
| int flunlock |
( |
struct flock_s * |
fl | ) |
|
Unlocks the file at the given path. If the file is not open, or the file cannot be unlocked, an error code is returned.
- Parameters
-
| fl | The file lock structure. |
- Returns
- 0 if successful, otherwise a non-zero error code.