diff --git a/HISTORY b/HISTORY index e8a722c..9c4ea47 100644 --- a/HISTORY +++ b/HISTORY @@ -1,8 +1,9 @@ -Version 1.35 2017-02-16 +Version 1.35 2017-02-20 * logger judge log_level in function log_it_ex and log_it_ex1 * add php extension function: fastcommon_file_put_contents * add function fc_safe_read and fc_safe_write + * add function fc_ftok Version 1.34 2017-02-06 * ini_file_reader: LOCAL_IP support CIDR addresses diff --git a/src/shared_func.c b/src/shared_func.c index 531c839..3b76a25 100644 --- a/src/shared_func.c +++ b/src/shared_func.c @@ -2556,3 +2556,10 @@ ssize_t fc_safe_read(int fd, char *buf, const size_t count) return count - remain; } + +key_t fc_ftok(const char *path, const int proj_id) +{ + int hash_code; + hash_code = simple_hash(path, strlen(path)); + return (((proj_id & 0xFF) << 24) | (hash_code & 0xFFFFFF)); +} diff --git a/src/shared_func.h b/src/shared_func.h index 1f33ef4..287fbb2 100644 --- a/src/shared_func.h +++ b/src/shared_func.h @@ -651,6 +651,14 @@ 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); +/** ftok with hash code + * parameters: + * path: the file path + * proj_id: the project id + * return: read bytes for success, -1 when fail +*/ +key_t fc_ftok(const char *path, const int proj_id); + #ifdef __cplusplus } #endif