TR181-XPON
1.4.0
TR-181 PON manager.
|
#include "file_utils.h"
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "xpon_trace.h"
Go to the source code of this file.
Macros | |
#define | _GNU_SOURCE |
#define | LINE_LEN 256 |
Functions | |
static bool | rename_file (const char *const oldpath, const char *const newpath) |
static bool | check_file_has_value (const char *const path, const char *const value, bool *has_value) |
bool | write_file (const char *const path, const char *const value) |
bool | read_first_line_from_file (const char *const path, char *line, size_t len) |
#define _GNU_SOURCE |
To avoid following error: file_utils.c:25:8: error: implicit declaration of function ‘fdatasync’ [-Werror=implicit-function-declaration]
Definition at line 71 of file file_utils.c.
#define LINE_LEN 256 |
Definition at line 84 of file file_utils.c.
|
static |
Set has_value to true if file path has value value as contents.
[in] | path | file path |
[in] | value | function must check if path has value as contents |
[in,out] | has_value | function sets this parameter to true if path has value as contents |
Definition at line 114 of file file_utils.c.
bool read_first_line_from_file | ( | const char *const | path, |
char * | line, | ||
size_t | len | ||
) |
Read the first line from a file into a buffer passed by caller.
[in] | path | file path |
[in,out] | line | function reads 1st line from path and puts it in this parameter |
[in] | len | length of line |
Definition at line 212 of file file_utils.c.
|
static |
bool write_file | ( | const char *const | path, |
const char *const | value | ||
) |
Write the string value to the file path.
[in] | path | file path |
[in] | value | value to write to path |
If path already exists and has value as contents, the function immediately returns true to avoid an unneeded write.
The function first writes the value to the file path with ".tmp" appended. Then it renames the file to path.
Avoid writing the file if the file already exists and already has the value of the parameter 'value' as contents.
Definition at line 154 of file file_utils.c.