- "\t-f\tremove existing destination files\n"
- "\t-n\tno dereference symlinks - treat like normal file\n"
-#endif
- ;
-
-static int symlinkFlag = FALSE;
-static int removeoldFlag = FALSE;
-static int followLinks = TRUE;
+/*
+ * linkDestName is where the link points to,
+ * linkSrcName is the name of the link to be created.
+ */
+static int fs_link(const char *link_DestName, const char *link_SrcName, const int flag)
+{
+ int status;
+ int srcIsDir;
+ char *srcName;
+
+ if (link_DestName==NULL)
+ return(FALSE);
+
+ srcName = (char *) malloc(strlen(link_SrcName)+strlen(link_DestName)+1);
+
+ if (link_SrcName==NULL)
+ strcpy(srcName, link_DestName);
+ else
+ strcpy(srcName, link_SrcName);
+
+ if (flag&LN_NODEREFERENCE)
+ srcIsDir = isDirectory(srcName, TRUE, NULL);
+ else
+ srcIsDir = isDirectory(srcName, FALSE, NULL);
+
+ if ((srcIsDir==TRUE)&&((flag&LN_NODEREFERENCE)==0)) {
+ strcat(srcName, "/");
+ strcat(srcName, link_DestName);
+ }
+
+ if (flag&LN_FORCE)
+ unlink(srcName);
+
+ if (flag&LN_SYMLINK)
+ status = symlink(link_DestName, srcName);
+ else
+ status = link(link_DestName, srcName);
+
+ if (status != 0) {
+ perror(srcName);
+ return(FALSE);
+ }
+ return(TRUE);
+}