38f7d8c0290d8888db426e6848720bf08b62f8a4
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 rename: lwproctrace -> upro...

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);
liblwpttr/src/symlink.c 18)     if (! target) {
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 rename: lwproctrace -> upro...

Stefan Schuermans authored 4 years ago

libuptev/src/symlink.c  38) char * uptev_symlink_read(char const *pathname, uptev_cleaner_t *cleaner) {
libuptev/src/symlink.c  39)   char *target = uptev_symlink_read_target(pathname);
libuptev/src/symlink.c  40)   if (! target) {
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;