Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- unsigned long long hash_function(unsigned long long);
- enum
- {
- MIN_ARGS = 4
- };
- int
- main(int argc, char *argv[])
- {
- unsigned long long h;
- int count;
- if (argc < MIN_ARGS ||
- sscanf(argv[2], "%llx", &h) != 1 ||
- sscanf(argv[3], "%d", &count) != 1) {
- return 0;
- }
- int fd = open(argv[1], O_WRONLY | O_CREAT,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
- if (fd == -1) {
- return 0;
- }
- int file_end = lseek(fd, 0, SEEK_END);
- for (int i = 0; i < count; ++i) {
- off_t offset = file_end + (count - i - 1) * sizeof(h);
- if (lseek(fd, offset, SEEK_SET) == -1 ||
- write(fd, &h, sizeof(h)) != sizeof(h)) {
- return 0;
- }
- h = hash_function(h);
- }
- close(fd);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement