d25cfbad02b03333ebc8f0d63d6055702d3da9ec
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 use libname as prefix for a...

Stefan Schuermans authored 4 years ago

liblwptev/src/symlink.c 12) static char * lwptev_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 use libname as prefix for a...

Stefan Schuermans authored 4 years ago

liblwptev/src/symlink.c 38) int lwptev_symlink_read(char const *pathname, char **target,
liblwptev/src/symlink.c 39)                         lwptev_cleaner_t *cleaner) {
liblwptev/src/symlink.c 40)   *target = lwptev_symlink_read_target(pathname);
Stefan Schuermans add exe and cwd to proc_begin

Stefan Schuermans authored 4 years ago

liblwpttr/src/symlink.c 41)   if (! *target) {
Stefan Schuermans lwpttr -> lwptev

Stefan Schuermans authored 4 years ago

liblwptev/src/symlink.c 42)     lwptev_cleaner_cleanup(cleaner);
Stefan Schuermans add exe and cwd to proc_begin

Stefan Schuermans authored 4 years ago

liblwpttr/src/symlink.c 43)     return -1;
liblwpttr/src/symlink.c 44)   }
Stefan Schuermans lwpttr -> lwptev

Stefan Schuermans authored 4 years ago

liblwptev/src/symlink.c 45)   lwptev_cleaner_add_ptr(cleaner, *target);