From e710e9b1218d66c12b4934bf56d4a7e5b2c876f0 Mon Sep 17 00:00:00 2001 From: mainzelm Date: Mon, 10 Jun 2002 08:47:48 +0000 Subject: [PATCH] Dynamically allocate space for symbolic link if MAXPATHLEN is not defined. --- scsh/syscalls1.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/scsh/syscalls1.c b/scsh/syscalls1.c index 3d9c872..19c0cb1 100644 --- a/scsh/syscalls1.c +++ b/scsh/syscalls1.c @@ -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) {