Last active
August 29, 2015 14:11
-
-
Save jwieder/5ae5f30d77fb066e9093 to your computer and use it in GitHub Desktop.
The readlink function gets the value of the symbolic link filename. The file name that the link points to is copied into buffer. This file name string is not null-terminated; readlink normally returns the number of characters copied. The size argument specifies the maximum number of characters to copy, usually the allocation size of buffer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ssize_t readlink (const char *filename, char *buffer, size_t size) | |
char *readlink_malloc (const char *filename) | |
{ | |
int size = 100; | |
char *buffer = NULL; | |
while (1) | |
{ | |
buffer = (char *) xrealloc (buffer, size); | |
int nchars = readlink (filename, buffer, size); | |
if (nchars < 0) | |
{ | |
free (buffer); | |
return NULL; | |
} | |
if (nchars < size) | |
return buffer; | |
size *= 2; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment