Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fcntl.h>
- #include <inttypes.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- void print(int fd, int32_t cur_ind, int32_t *ptr, int32_t *buf) {
- int read_res;
- void *cur_buf = buf;
- int cur_size = 0;
- while ((read_res = read(fd, cur_buf, 12 - cur_size)) > 0) {
- cur_buf = cur_buf + read_res;
- cur_size += read_res;
- }
- *ptr = cur_ind + 1;
- if (*(buf + 2) != 0) {
- lseek(fd, (*(buf + 2) - *ptr) * 12, SEEK_CUR);
- *ptr = *(buf + 2);
- print(fd, *(buf + 2), ptr, buf);
- }
- printf("%d ", *buf);
- if (*(buf + 1) != 0) {
- lseek(fd, (*(buf + 1) - *ptr) * 12, SEEK_CUR);
- *ptr = *(buf + 1);
- print(fd, *(buf + 1), ptr, buf);
- }
- return;
- }
- int main(int argc, char *argv[]) {
- int fd = open(argv[1], O_RDONLY);
- int32_t *buf = malloc(12);
- int32_t cur_ind = 0;
- int32_t cur_pos = 0;
- print(fd, 0, &cur_pos, buf);
- printf("\n");
- free(buf);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement