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)
|
int fast_buffer_append_file(FastBuffer *buffer, const char *filename)
|
||||||
{
|
{
|
||||||
|
const int64_t offset = 0;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int result;
|
int result;
|
||||||
int64_t file_size;
|
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,
|
if ((result=getFileContentEx(filename, buffer->data + buffer->length,
|
||||||
0, &file_size)) != 0)
|
offset, &file_size)) != 0)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
int get_pid_from_file(const char *pidFilename, pid_t *pid)
|
int get_pid_from_file(const char *pidFilename, pid_t *pid)
|
||||||
{
|
{
|
||||||
|
const int64_t offset = 0;
|
||||||
char buff[32];
|
char buff[32];
|
||||||
int64_t file_size;
|
int64_t file_size;
|
||||||
int result;
|
int result;
|
||||||
|
|
@ -33,7 +34,7 @@ int get_pid_from_file(const char *pidFilename, pid_t *pid)
|
||||||
}
|
}
|
||||||
|
|
||||||
file_size = sizeof(buff);
|
file_size = sizeof(buff);
|
||||||
if ((result=getFileContentEx(pidFilename, buff, 0, &file_size)) != 0) {
|
if ((result=getFileContentEx(pidFilename, buff, offset, &file_size)) != 0) {
|
||||||
return result;
|
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,
|
static const char *get_exename_by_pid(const pid_t pid, char *buff,
|
||||||
const int buff_size, int *result)
|
const int buff_size, int *result)
|
||||||
{
|
{
|
||||||
|
const int64_t offset = 0;
|
||||||
char cmdfile[MAX_PATH_SIZE];
|
char cmdfile[MAX_PATH_SIZE];
|
||||||
int64_t cmdsz;
|
int64_t cmdsz;
|
||||||
|
|
||||||
cmdsz = buff_size;
|
cmdsz = buff_size;
|
||||||
sprintf(cmdfile, "/proc/%d/cmdline", pid);
|
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",
|
fprintf(stderr, "read file %s fail, errno: %d, error info: %s\n",
|
||||||
cmdfile, *result, strerror(*result));
|
cmdfile, *result, strerror(*result));
|
||||||
return NULL;
|
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,
|
int fc_get_first_line(const char *filename, char *buff,
|
||||||
const int buff_size, string_t *line)
|
const int buff_size, string_t *line)
|
||||||
{
|
{
|
||||||
|
const int64_t offset = 0;
|
||||||
int result;
|
int result;
|
||||||
int64_t read_bytes;
|
int64_t read_bytes;
|
||||||
char *line_end;
|
char *line_end;
|
||||||
|
|
||||||
read_bytes = buff_size - 1;
|
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);
|
FC_SET_STRING_EMPTY(*line, buff);
|
||||||
return result;
|
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,
|
int fc_get_first_lines(const char *filename, char *buff,
|
||||||
const int buff_size, string_t *lines, int *count)
|
const int buff_size, string_t *lines, int *count)
|
||||||
{
|
{
|
||||||
|
const int64_t offset = 0;
|
||||||
int result;
|
int result;
|
||||||
int target_count;
|
int target_count;
|
||||||
int64_t read_bytes;
|
int64_t read_bytes;
|
||||||
|
|
@ -4134,7 +4136,7 @@ int fc_get_first_lines(const char *filename, char *buff,
|
||||||
}
|
}
|
||||||
|
|
||||||
read_bytes = buff_size - 1;
|
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;
|
*count = 0;
|
||||||
FC_SET_STRING_EMPTY(*lines, buff);
|
FC_SET_STRING_EMPTY(*lines, buff);
|
||||||
return result;
|
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
|
* size: specify the size to fetch and return the fetched size
|
||||||
* return: error no , 0 success, != 0 fail
|
* 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);
|
int64_t offset, int64_t *size);
|
||||||
|
|
||||||
/** get file size
|
/** get file size
|
||||||
|
|
|
||||||
|
|
@ -118,12 +118,13 @@ int get_sys_cpu_count()
|
||||||
int get_boot_time(struct timeval *boot_time)
|
int get_boot_time(struct timeval *boot_time)
|
||||||
{
|
{
|
||||||
#ifdef OS_LINUX
|
#ifdef OS_LINUX
|
||||||
|
const int64_t offset = 0;
|
||||||
char buff[256];
|
char buff[256];
|
||||||
int64_t bytes;
|
int64_t bytes;
|
||||||
struct sysinfo si;
|
struct sysinfo si;
|
||||||
|
|
||||||
bytes = sizeof(buff);
|
bytes = sizeof(buff);
|
||||||
if (getFileContentEx("/proc/uptime", buff, 0, &bytes) == 0)
|
if (getFileContentEx("/proc/uptime", buff, offset, &bytes) == 0)
|
||||||
{
|
{
|
||||||
double uptime;
|
double uptime;
|
||||||
double btime;
|
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)
|
int get_processes(struct fast_process_info **processes, int *count)
|
||||||
{
|
{
|
||||||
|
const int64_t offset = 0;
|
||||||
const char *dirname = "/proc";
|
const char *dirname = "/proc";
|
||||||
char filename[128];
|
char filename[128];
|
||||||
char buff[4096];
|
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);
|
sprintf(filename, "%s/%s/stat", dirname, ent->d_name);
|
||||||
bytes = sizeof(buff);
|
bytes = sizeof(buff);
|
||||||
if (getFileContentEx(filename, buff, 0, &bytes) != 0)
|
if (getFileContentEx(filename, buff, offset, &bytes) != 0)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue