diff options
author | Simon Brandner <simon.brandner@partner.bmw.de> | 2013-03-21 14:29:33 +0100 |
---|---|---|
committer | Alexander Wenzel <Alexander.AW.Wenzel@bmw.de> | 2013-07-19 16:54:32 +0200 |
commit | f06df4fd0887c5adb162ce8e35fa7582491e6d16 (patch) | |
tree | b31b973712573cba70e100c44c94b90297ffdd19 | |
parent | 9e8d7cf341445d0822fde0d4b75d572a88d714eb (diff) | |
download | dlt-daemon-f06df4fd0887c5adb162ce8e35fa7582491e6d16.tar.gz dlt-daemon-f06df4fd0887c5adb162ce8e35fa7582491e6d16.tar.bz2 dlt-daemon-f06df4fd0887c5adb162ce8e35fa7582491e6d16.zip |
added creation date and a simple hash on the file name for to improve the uniqueness of getFileSerialNumber
Signed-off-by: Alexander Wenzel <Alexander.AW.Wenzel@bmw.de>
-rw-r--r-- | src/lib/dlt_filetransfer.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/lib/dlt_filetransfer.c b/src/lib/dlt_filetransfer.c index d690696..ce18f52 100644 --- a/src/lib/dlt_filetransfer.c +++ b/src/lib/dlt_filetransfer.c @@ -77,6 +77,30 @@ unsigned long getFilesize(const char* file){ return (unsigned long)st.st_size; } +/** A simple Hash function for C-strings + * @param str input string. E.g. a file path. + * @param hash start and result value for hash computation + * + */ +void stringHash(const char* str, unsigned long *hash ) +{ + if (!str || !hash) + return; + unsigned int len = strlen(str); + + unsigned int i = 0; + if (len <= 0){ + return; + } + + for(i = 0; i < len; i++) + { + *hash = 53 * *hash + str[i]; + } + +} + + //!Get some information about the file serial number of a file /** See stat(2) for more informations. * @param file Absolute file path @@ -89,6 +113,8 @@ unsigned long getFileSerialNumber(const char* file){ ret = st.st_ino; ret = ret << (sizeof(ret)*8)/2; ret |= st.st_size; + ret ^= st.st_ctime; + stringHash(file, &ret); return ret; } |