shared_func.[hc]: add functions getFileSize

pull/37/head
YuQing 2020-03-03 10:19:53 +08:00
parent 8005b18198
commit 773f1bc28c
3 changed files with 27 additions and 2 deletions

View File

@ -1,5 +1,5 @@
Version 1.44 2020-02-27
Version 1.44 2020-03-03
* add test file src/tests/test_pthread_lock.c
* add uniq_skiplist.[hc]
* add function split_string_ex
@ -13,6 +13,7 @@ Version 1.44 2020-02-27
* shared_func.[hc]: add functions fc_floor_prime and fc_ceil_prime
* fast_mpool.[hc]: change function fast_mpool_strdup
* fast_allocator.[hc]: add function fast_allocator_strdup
* shared_func.[hc]: add functions getFileSize
Version 1.43 2019-12-25
* replace function call system to getExecResult,

View File

@ -323,7 +323,7 @@ int getUserProcIds(const char *progName, const bool bAllOwners, \
sprintf(fullpath, "%s/%s", path, dirp->d_name);
memset(&statbuf, 0, sizeof(statbuf));
if (lstat(fullpath, &statbuf)<0)
if (lstat(fullpath, &statbuf) < 0)
{
continue;
}
@ -1240,6 +1240,22 @@ int getFileContentEx(const char *filename, char *buff, \
return 0;
}
int getFileSize(const char *filename, int64_t *file_size)
{
struct stat buf;
if (stat(filename, &buf) != 0)
{
logError("file: "__FILE__", line: %d, "
"stat file %s fail, "
"errno: %d, error info: %s", __LINE__,
filename, errno, STRERROR(errno));
return errno != 0 ? errno : EIO;
}
*file_size = buf.st_size;
return 0;
}
int writeToFile(const char *filename, const char *buff, const int file_size)
{
int fd;

View File

@ -546,6 +546,14 @@ int getFileContent(const char *filename, char **buff, int64_t *file_size);
int getFileContentEx(const char *filename, char *buff, \
int64_t offset, int64_t *size);
/** get file size
* parameters:
* filename: the filename
* file_size: store the file size
* return: error no , 0 success, != 0 fail
*/
int getFileSize(const char *filename, int64_t *file_size);
/** write to file
* parameters:
* filename: the filename to write