+void
+process_readlink(void)
+{
+ u_int32_t id;
+ char link[MAXPATHLEN];
+ char *path;
+
+ id = get_int();
+ path = get_string(NULL);
+ TRACE("readlink id %d path %s", id, path);
+ if (readlink(path, link, sizeof(link) - 1) == -1)
+ send_status(id, errno_to_portable(errno));
+ else {
+ Stat s;
+
+ link[sizeof(link) - 1] = '\0';
+ attrib_clear(&s.attrib);
+ s.name = s.long_name = link;
+ send_names(id, 1, &s);
+ }
+ xfree(path);
+}
+
+void
+process_symlink(void)
+{
+ u_int32_t id;
+ struct stat st;
+ char *oldpath, *newpath;
+ int ret, status = SSH2_FX_FAILURE;
+
+ id = get_int();
+ oldpath = get_string(NULL);
+ newpath = get_string(NULL);
+ TRACE("symlink id %d old %s new %s", id, oldpath, newpath);
+ /* fail if 'newpath' exists */
+ if (stat(newpath, &st) == -1) {
+ ret = symlink(oldpath, newpath);
+ status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK;
+ }
+ send_status(id, status);
+ xfree(oldpath);
+ xfree(newpath);
+}
+