call getFileContentEx with offset constant
parent
7b06207f6f
commit
f6f664b33d
|
|
@ -180,6 +180,7 @@ int fast_buffer_append_binary(FastBuffer *buffer,
|
|||
|
||||
int fast_buffer_append_file(FastBuffer *buffer, const char *filename)
|
||||
{
|
||||
const int64_t offset = 0;
|
||||
struct stat st;
|
||||
int result;
|
||||
int64_t file_size;
|
||||
|
|
@ -213,7 +214,7 @@ int fast_buffer_append_file(FastBuffer *buffer, const char *filename)
|
|||
}
|
||||
|
||||
if ((result=getFileContentEx(filename, buffer->data + buffer->length,
|
||||
0, &file_size)) != 0)
|
||||
offset, &file_size)) != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
int get_pid_from_file(const char *pidFilename, pid_t *pid)
|
||||
{
|
||||
const int64_t offset = 0;
|
||||
char buff[32];
|
||||
int64_t file_size;
|
||||
int result;
|
||||
|
|
@ -33,7 +34,7 @@ int get_pid_from_file(const char *pidFilename, pid_t *pid)
|
|||
}
|
||||
|
||||
file_size = sizeof(buff);
|
||||
if ((result=getFileContentEx(pidFilename, buff, 0, &file_size)) != 0) {
|
||||
if ((result=getFileContentEx(pidFilename, buff, offset, &file_size)) != 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -183,12 +184,13 @@ static const char *process_get_exename(const char* program)
|
|||
static const char *get_exename_by_pid(const pid_t pid, char *buff,
|
||||
const int buff_size, int *result)
|
||||
{
|
||||
const int64_t offset = 0;
|
||||
char cmdfile[MAX_PATH_SIZE];
|
||||
int64_t cmdsz;
|
||||
|
||||
cmdsz = buff_size;
|
||||
sprintf(cmdfile, "/proc/%d/cmdline", pid);
|
||||
if ((*result=getFileContentEx(cmdfile, buff, 0, &cmdsz)) != 0) {
|
||||
if ((*result=getFileContentEx(cmdfile, buff, offset, &cmdsz)) != 0) {
|
||||
fprintf(stderr, "read file %s fail, errno: %d, error info: %s\n",
|
||||
cmdfile, *result, strerror(*result));
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -4090,12 +4090,13 @@ int fc_check_rename_ex(const char *oldpath, const char *newpath,
|
|||
int fc_get_first_line(const char *filename, char *buff,
|
||||
const int buff_size, string_t *line)
|
||||
{
|
||||
const int64_t offset = 0;
|
||||
int result;
|
||||
int64_t read_bytes;
|
||||
char *line_end;
|
||||
|
||||
read_bytes = buff_size - 1;
|
||||
if ((result=getFileContentEx(filename, buff, 0, &read_bytes)) != 0) {
|
||||
if ((result=getFileContentEx(filename, buff, offset, &read_bytes)) != 0) {
|
||||
FC_SET_STRING_EMPTY(*line, buff);
|
||||
return result;
|
||||
}
|
||||
|
|
@ -4121,6 +4122,7 @@ int fc_get_first_line(const char *filename, char *buff,
|
|||
int fc_get_first_lines(const char *filename, char *buff,
|
||||
const int buff_size, string_t *lines, int *count)
|
||||
{
|
||||
const int64_t offset = 0;
|
||||
int result;
|
||||
int target_count;
|
||||
int64_t read_bytes;
|
||||
|
|
@ -4134,7 +4136,7 @@ int fc_get_first_lines(const char *filename, char *buff,
|
|||
}
|
||||
|
||||
read_bytes = buff_size - 1;
|
||||
if ((result=getFileContentEx(filename, buff, 0, &read_bytes)) != 0) {
|
||||
if ((result=getFileContentEx(filename, buff, offset, &read_bytes)) != 0) {
|
||||
*count = 0;
|
||||
FC_SET_STRING_EMPTY(*lines, buff);
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -878,7 +878,7 @@ int getFileContentEx1(int fd, const char *filename, char *buff,
|
|||
* size: specify the size to fetch and return the fetched size
|
||||
* return: error no , 0 success, != 0 fail
|
||||
*/
|
||||
int getFileContentEx(const char *filename, char *buff, \
|
||||
int getFileContentEx(const char *filename, char *buff,
|
||||
int64_t offset, int64_t *size);
|
||||
|
||||
/** get file size
|
||||
|
|
|
|||
|
|
@ -118,12 +118,13 @@ int get_sys_cpu_count()
|
|||
int get_boot_time(struct timeval *boot_time)
|
||||
{
|
||||
#ifdef OS_LINUX
|
||||
const int64_t offset = 0;
|
||||
char buff[256];
|
||||
int64_t bytes;
|
||||
struct sysinfo si;
|
||||
|
||||
bytes = sizeof(buff);
|
||||
if (getFileContentEx("/proc/uptime", buff, 0, &bytes) == 0)
|
||||
if (getFileContentEx("/proc/uptime", buff, offset, &bytes) == 0)
|
||||
{
|
||||
double uptime;
|
||||
double btime;
|
||||
|
|
@ -621,6 +622,7 @@ static void parse_proc_stat(char *buff, const int len,
|
|||
|
||||
int get_processes(struct fast_process_info **processes, int *count)
|
||||
{
|
||||
const int64_t offset = 0;
|
||||
const char *dirname = "/proc";
|
||||
char filename[128];
|
||||
char buff[4096];
|
||||
|
|
@ -679,7 +681,7 @@ int get_processes(struct fast_process_info **processes, int *count)
|
|||
|
||||
sprintf(filename, "%s/%s/stat", dirname, ent->d_name);
|
||||
bytes = sizeof(buff);
|
||||
if (getFileContentEx(filename, buff, 0, &bytes) != 0)
|
||||
if (getFileContentEx(filename, buff, offset, &bytes) != 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue