force CC/CXX to the passed in compiler to use.
[AROS.git] / workbench / c / MakeLink.c
blob7d4ab6f53738931baf00e3f40a1067625b7a3388
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 /******************************************************************************
11 NAME
13 MakeLink
15 SYNOPSIS
17 FROM/A, TO/A, HARD/S, FORCE/S
19 LOCATION
23 FUNCTION
25 Create a link to a file.
27 INPUTS
29 FROM -- The name of the link
30 TO -- The name of the file or directory to link to
31 HARD -- If specified, the link will be a hard link; default is
32 to create a soft link
33 FORCE -- Allow a hard-link to point to a directory
35 RESULT
37 Standard DOS error codes.
39 NOTES
41 Not all file systems support links.
43 EXAMPLE
45 Makelink ls C:List
46 Creates an 'ls' file with a soft link to the 'List' command in C:.
48 BUGS
50 SEE ALSO
52 INTERNALS
54 ******************************************************************************/
56 #include <dos/dos.h>
57 #include <dos/dosextens.h>
58 #include <dos/rdargs.h>
59 #include <proto/dos.h>
60 #include <proto/exec.h>
61 #include <aros/debug.h>
63 const TEXT version[] = "$VER: MakeLink 41.2 (3.4.2014)\n";
65 enum { ARG_FROM = 0, ARG_TO, ARG_HARD, ARG_FORCE };
67 int __nocommandline;
69 int main(void)
71 int retval = RETURN_FAIL;
72 LONG error = 0;
73 IPTR args[] = { (IPTR)NULL, (IPTR)NULL, (IPTR)FALSE, (IPTR)FALSE };
74 struct RDArgs *rda;
76 rda = ReadArgs("FROM/A,TO/A,HARD/S,FORCE/S", args, NULL);
78 if(rda != NULL)
80 if(args[ARG_HARD])
82 BPTR lock;
84 lock = Lock((STRPTR)args[ARG_TO], SHARED_LOCK);
86 if(lock != BNULL)
88 struct FileInfoBlock *fib = AllocDosObject(DOS_FIB, NULL);
90 if(fib != NULL)
92 if(Examine(lock, fib))
94 /* Directories may only be hard-linked to if FORCE is
95 specified */
96 if(fib->fib_DirEntryType >= 0 && !(BOOL)args[ARG_FORCE])
98 PutStr("Hard links to directories require the"
99 " FORCE keyword\n");
101 else
103 /* Check loops? */
104 if(MakeLink((STRPTR)args[ARG_FROM], (SIPTR)lock, FALSE))
105 retval = RETURN_OK;
106 else
108 error = IoErr();
109 PrintFault(error, "MakeLink");
114 FreeDosObject(DOS_FIB, fib);
117 UnLock(lock);
119 else
121 error = IoErr();
122 PutStr((STRPTR)args[ARG_TO]);
123 PrintFault(error, "");
126 else
128 if(MakeLink((STRPTR)args[ARG_FROM], (SIPTR)args[ARG_TO], TRUE))
129 retval = RETURN_OK;
132 else
134 error = IoErr();
135 PrintFault(error, "MakeLink");
136 retval = RETURN_FAIL;
139 FreeArgs(rda);
141 SetIoErr(error);
142 return retval;