Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. int get_checksum(char *filename) {
  2. // New prototype, if no such function already exists in standard C-libraries
  3. int result; // Or char/float/whatever
  4.  
  5.  
  6. // ...
  7.  
  8.  
  9. return result;
  10. }
  11. int main(void) {
  12.  
  13. char filename[] = { "foo.dat" };
  14. char file_url[] = { "http://example.com/foo.dat" }
  15. int old_checksum; // Or char/float/whatever
  16. int new_checksum; // Or char/float/whatever
  17.  
  18.  
  19. // ...
  20.  
  21.  
  22. // Now assume that old_checksum has a value from before:
  23.  
  24. dl_file(filename, file_url); // Some prototype for downloading the file
  25. if ((new_checksum = get_checksum(filename)) == -1) {
  26. // Badness
  27. }
  28. else {
  29. if (new_checksum != old_checksum) {
  30. old_checksum = new_checksum;
  31. // Parse the file
  32. }
  33. else {
  34. // Do nothing
  35. }
  36. }
  37.  
  38.  
  39. // ...
  40.  
  41.  
  42. }
  43.  
  44. struct stat {
  45. dev_t st_dev; /* ID of device containing file */
  46. ino_t st_ino; /* inode number */
  47. mode_t st_mode; /* protection */
  48. nlink_t st_nlink; /* number of hard links */
  49. uid_t st_uid; /* user ID of owner */
  50. gid_t st_gid; /* group ID of owner */
  51. dev_t st_rdev; /* device ID (if special file) */
  52. off_t st_size; /* total size, in bytes */
  53. blksize_t st_blksize; /* blocksize for file system I/O */
  54. blkcnt_t st_blocks; /* number of 512B blocks allocated */
  55. time_t st_atime; /* time of last access */
  56. time_t st_mtime; /* time of last modification */
  57. time_t st_ctime; /* time of last status change */
  58. };
  59.  
  60. unsigned int hash(vector<char> file){
  61. unsigned int result;
  62. int *arr = (int*)file.data();
  63.  
  64. for(int i = 0;i < file.size() / sizeof(unsigned int);i++)
  65. result ^= arr[i];
  66.  
  67. return result;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement