shared_func.[hc]: add function fc_read_lines
parent
09e00bcf5e
commit
9ca9592326
3
HISTORY
3
HISTORY
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
Version 1.54 2021-10-10
|
Version 1.54 2021-10-19
|
||||||
* fast_allocator.[hc]: correct reclaim_interval logic
|
* fast_allocator.[hc]: correct reclaim_interval logic
|
||||||
* shared_func.[hc]: add functions getFileContentEx1 and getFileContent1
|
* shared_func.[hc]: add functions getFileContentEx1 and getFileContent1
|
||||||
* fc_queue.[hc]: add function fc_queue_timedpeek
|
* fc_queue.[hc]: add function fc_queue_timedpeek
|
||||||
|
|
@ -7,6 +7,7 @@ Version 1.54 2021-10-10
|
||||||
* add files: sorted_queue.[hc]
|
* add files: sorted_queue.[hc]
|
||||||
* add files: array_allocator.[hc]
|
* add files: array_allocator.[hc]
|
||||||
* add files: sorted_array.[hc]
|
* add files: sorted_array.[hc]
|
||||||
|
* shared_func.[hc]: add function fc_read_lines
|
||||||
|
|
||||||
Version 1.53 2021-06-30
|
Version 1.53 2021-06-30
|
||||||
* process_action support action status
|
* process_action support action status
|
||||||
|
|
|
||||||
|
|
@ -1509,6 +1509,41 @@ int fd_gets(int fd, char *buff, const int size, int once_bytes)
|
||||||
return pDest - buff;
|
return pDest - buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ssize_t fc_read_lines(int fd, char *buf, const size_t size)
|
||||||
|
{
|
||||||
|
ssize_t count;
|
||||||
|
ssize_t old;
|
||||||
|
int remain;
|
||||||
|
char *last;
|
||||||
|
|
||||||
|
if ((count=fc_safe_read(fd, buf, size)) <= 0)
|
||||||
|
{
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((last=(char *)fc_memrchr(buf, '\n', count)) == NULL)
|
||||||
|
{
|
||||||
|
last = buf;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
last++; //skip \n
|
||||||
|
}
|
||||||
|
|
||||||
|
old = count;
|
||||||
|
count = last - buf;
|
||||||
|
remain = old - count;
|
||||||
|
if (remain > 0)
|
||||||
|
{
|
||||||
|
if (lseek(fd, -1 * remain, SEEK_CUR) < 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
int set_rlimit(int resource, const rlim_t value)
|
int set_rlimit(int resource, const rlim_t value)
|
||||||
{
|
{
|
||||||
struct rlimit limit;
|
struct rlimit limit;
|
||||||
|
|
|
||||||
|
|
@ -880,6 +880,15 @@ ssize_t fc_lock_write(int fd, const char *buf, const size_t nbyte);
|
||||||
*/
|
*/
|
||||||
ssize_t fc_safe_read(int fd, char *buf, const size_t count);
|
ssize_t fc_safe_read(int fd, char *buf, const size_t count);
|
||||||
|
|
||||||
|
/** read integral lines from file
|
||||||
|
* parameters:
|
||||||
|
* fd: the fd to read
|
||||||
|
* buf: the buffer to store the line
|
||||||
|
* size: max read bytes
|
||||||
|
* return: error no , 0 success, != 0 fail
|
||||||
|
*/
|
||||||
|
ssize_t fc_read_lines(int fd, char *buf, const size_t size);
|
||||||
|
|
||||||
/** ftok with hash code
|
/** ftok with hash code
|
||||||
* parameters:
|
* parameters:
|
||||||
* path: the file path
|
* path: the file path
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,24 @@ static inline int uniq_skiplist_init_pair_ex(UniqSkiplistPair *pair,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline UniqSkiplist *uniq_skiplist_new_by_pair(
|
||||||
|
UniqSkiplistPair *pair, const int level_count)
|
||||||
|
{
|
||||||
|
if (pair->skiplist == NULL) {
|
||||||
|
pair->skiplist = uniq_skiplist_new(&pair->factory, level_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pair->skiplist;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void uniq_skiplist_free_by_pair(UniqSkiplistPair *pair)
|
||||||
|
{
|
||||||
|
if (pair->skiplist != NULL) {
|
||||||
|
uniq_skiplist_free(pair->skiplist);
|
||||||
|
pair->skiplist = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int uniq_skiplist_insert(UniqSkiplist *sl, void *data);
|
int uniq_skiplist_insert(UniqSkiplist *sl, void *data);
|
||||||
int uniq_skiplist_delete_ex(UniqSkiplist *sl, void *data,
|
int uniq_skiplist_delete_ex(UniqSkiplist *sl, void *data,
|
||||||
const bool need_free);
|
const bool need_free);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue