Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #define skip_notspace(a) \
- while (!isspace(*(a))) \
- { \
- a++; \
- } \
- #define skip_space(a) \
- while (isspace(*(a))) \
- { \
- a++; \
- } \
- char* find_ld_lib_maps(char *);
- // this thing give pointer to beginning of line where "/ld-" occures
- char* find_ld_lib_maps(char *a)
- {
- start:
- if (*a == '\0')
- {
- return NULL;
- }
- skip_notspace(a);
- skip_space(a);
- if (a[2] == 'x')
- {
- skip_notspace(a);
- skip_space(a);
- skip_notspace(a);
- skip_space(a);
- skip_notspace(a);
- skip_space(a);
- skip_notspace(a);
- skip_space(a);
- while ( *a != '\n')
- {
- if(
- ( a[0] == '/') &&
- ( a[1] == 'l') &&
- ( a[2] == 'd') &&
- ( a[3] == '-')
- )
- {
- while (a[-1] != '\n') // go to start of line
- { a--; }
- return a;
- }
- a++;
- }
- a++;
- goto start;
- }
- while ( *a != '\n')
- { a++; }
- a++;
- goto start;
- }
- int main(void)
- {
- char buf[1000000] = {}, *pos;
- buf[0] = '\n';
- FILE *file1;
- size_t len;
- file1 = fopen("/proc/self/maps", "r");
- len = fread(buf+1, 1, sizeof(buf)-1, file1);
- pos = find_ld_lib_maps(buf+1);
- while ( *pos != '\n')
- {
- putchar(*pos);
- pos++;
- }
- putchar('\n');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment