diff --git a/HISTORY b/HISTORY index 8b83ddcab91a6da711e57bf8afc8301421b96cfd..b1b21ec85fd4d7ab1f76a808d6b699922e801c56 100644 --- a/HISTORY +++ b/HISTORY @@ -1,6 +1,7 @@ -Version 1.06 2014-05-28 +Version 1.06 2014-05-30 * update source code from FastDFS V5.02 + * add function short2buff and buff2short Version 1.05 2012-07-08 * update source code from FastDFS V3.09 diff --git a/src/shared_func.c b/src/shared_func.c index 0096bf33351c6264bf28b68e870fac44862b964c..8ed40d949816bfab567b4829d2b2c4d76390c3ba 100644 --- a/src/shared_func.c +++ b/src/shared_func.c @@ -1140,6 +1140,20 @@ int safeWriteToFile(const char *filename, const char *buff, \ return 0; } +void short2buff(const short n, char *buff) +{ + unsigned char *p; + p = (unsigned char *)buff; + *p++ = (n >> 8) & 0xFF; + *p++ = n & 0xFF; +} + +short buff2short(const char *buff) +{ + return (short)((((unsigned char)(*(buff))) << 8) | \ + ((unsigned char)(*(buff+1)))); +} + void int2buff(const int n, char *buff) { unsigned char *p; diff --git a/src/shared_func.h b/src/shared_func.h index 971c0add1b548964dbab7338ecf444a5d1590bcb..6ea8342279153727f5066f30d513f40c6878c819 100644 --- a/src/shared_func.h +++ b/src/shared_func.h @@ -147,6 +147,21 @@ char *hex2bin(const char *s, char *szBinBuff, int *nDestLen); */ void printBuffHex(const char *s, const int len); +/** 16 bits int convert to buffer (big-endian) + * parameters: + * n: 16 bits int value + * buff: the buffer, at least 2 bytes space, no tail \0 + * return: none +*/ +void short2buff(const short n, char *buff); + +/** buffer convert to 16 bits int + * parameters: + * buff: big-endian 2 bytes buffer + * return: 16 bits int value +*/ +short buff2short(const char *buff); + /** 32 bits int convert to buffer (big-endian) * parameters: * n: 32 bits int value