c84264bb398c51438bb5230fc6b4a2a75a5bd923
Stefan Schuermans add exe and cwd to proc_begin

Stefan Schuermans authored 4 years ago

liblwpttr/src/symlink.c  1) #include "symlink.h"
liblwpttr/src/symlink.c  2) #include "cleaner.h"
liblwpttr/src/symlink.c  3) 
liblwpttr/src/symlink.c  4) #include <stdlib.h>
liblwpttr/src/symlink.c  5) #include <unistd.h>
liblwpttr/src/symlink.c  6) 
liblwpttr/src/symlink.c  7) /**
liblwpttr/src/symlink.c  8)  * @brief read target of symlink
liblwpttr/src/symlink.c  9)  * @param[in] pathname path to symbolic link
liblwpttr/src/symlink.c 10)  * @return malloc-ed string containting link target or NULL
liblwpttr/src/symlink.c 11)  */
Stefan Schuermans formatting

Stefan Schuermans authored 4 years ago

libuptev/src/symlink.c  12) static char *uptev_symlink_read_target(char const *pathname) {
Stefan Schuermans add exe and cwd to proc_begin

Stefan Schuermans authored 4 years ago

liblwpttr/src/symlink.c 13)   size_t sz = 256;
liblwpttr/src/symlink.c 14)   char *target = NULL;
liblwpttr/src/symlink.c 15)   while (1) {
liblwpttr/src/symlink.c 16)     /* get buffer */
liblwpttr/src/symlink.c 17)     target = malloc(sz);
Stefan Schuermans formatting

Stefan Schuermans authored 4 years ago

libuptev/src/symlink.c  18)     if (!target) {
Stefan Schuermans add exe and cwd to proc_begin

Stefan Schuermans authored 4 years ago

liblwpttr/src/symlink.c 19)       return NULL;
liblwpttr/src/symlink.c 20)     }
liblwpttr/src/symlink.c 21)     /* get link target */
liblwpttr/src/symlink.c 22)     ssize_t len = readlink(pathname, target, sz);
liblwpttr/src/symlink.c 23)     if (len < 0) {
liblwpttr/src/symlink.c 24)       free(target);
liblwpttr/src/symlink.c 25)       return NULL;
liblwpttr/src/symlink.c 26)     }
liblwpttr/src/symlink.c 27)     /* link target fit into buffer -> terminate string and return */
liblwpttr/src/symlink.c 28)     if ((size_t)len + 1 < sz) {
liblwpttr/src/symlink.c 29)       target[len] = 0;
liblwpttr/src/symlink.c 30)       return target;
liblwpttr/src/symlink.c 31)     }
liblwpttr/src/symlink.c 32)     /* free buffer and try again with larger buffer */
liblwpttr/src/symlink.c 33)     free(target);
liblwpttr/src/symlink.c 34)     sz *= 2;
liblwpttr/src/symlink.c 35)   }
liblwpttr/src/symlink.c 36) }
liblwpttr/src/symlink.c 37) 
Stefan Schuermans formatting

Stefan Schuermans authored 4 years ago

libuptev/src/symlink.c  38) char *uptev_symlink_read(char const *pathname, uptev_cleaner_t *cleaner) {
Stefan Schuermans rename: lwproctrace -> upro...

Stefan Schuermans authored 4 years ago

libuptev/src/symlink.c  39)   char *target = uptev_symlink_read_target(pathname);
Stefan Schuermans formatting

Stefan Schuermans authored 4 years ago

libuptev/src/symlink.c  40)   if (!target) {
Stefan Schuermans rename: lwproctrace -> upro...

Stefan Schuermans authored 4 years ago

libuptev/src/symlink.c  41)     return NULL;
Stefan Schuermans add exe and cwd to proc_begin

Stefan Schuermans authored 4 years ago

liblwpttr/src/symlink.c 42)   }
Stefan Schuermans rename: lwproctrace -> upro...

Stefan Schuermans authored 4 years ago

libuptev/src/symlink.c  43)   /* success: add malloc-ed object to cleaner and return target string */
libuptev/src/symlink.c  44)   uptev_cleaner_add_ptr(cleaner, target);
libuptev/src/symlink.c  45)   return target;