Dynamically allocate space for symbolic link if MAXPATHLEN is not defined.
This commit is contained in:
parent
bbfd094bbd
commit
e710e9b121
|
@ -189,7 +189,7 @@ s48_value scsh_kill (s48_value sch_pid, s48_value sch_signal)
|
|||
|
||||
|
||||
/* Read the symlink. */
|
||||
|
||||
#ifdef MAXPATHLEN
|
||||
s48_value scsh_readlink(s48_value sch_path)
|
||||
{
|
||||
char linkpath[MAXPATHLEN+1];
|
||||
|
@ -202,6 +202,37 @@ s48_value scsh_readlink(s48_value sch_path)
|
|||
return s48_enter_string(linkpath);
|
||||
}
|
||||
}
|
||||
#else
|
||||
s48_value scsh_readlink(s48_value sch_path)
|
||||
{
|
||||
char *linkpath;
|
||||
int size;
|
||||
int retval;
|
||||
s48_value sch_sym_link_path = S48_UNSPECIFIC;
|
||||
|
||||
for (size = 256;; size *=2){
|
||||
|
||||
linkpath = Malloc(char,size);
|
||||
if (!linkpath)
|
||||
s48_raise_os_error_1(errno, sch_path);
|
||||
|
||||
retval = readlink(s48_extract_string (sch_path), linkpath, size);
|
||||
|
||||
if (retval == -1){
|
||||
free (linkpath);
|
||||
s48_raise_os_error_1(errno, sch_path);
|
||||
}
|
||||
|
||||
if (retval < size){
|
||||
sch_sym_link_path = s48_enter_substring (linkpath, retval);
|
||||
free (linkpath);
|
||||
return sch_sym_link_path;
|
||||
}
|
||||
free (linkpath);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
s48_value scsh_rename(s48_value sch_from, s48_value sch_to)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue