Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / c / MakeLink.c
blobff0b97d7868f432eb0ea75a14b2b8527e37225f6
1 /*
2 Copyright © 1995-2008, 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.1 (2.6.2000)\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 IPTR args[] = { (IPTR)NULL, (IPTR)NULL, (IPTR)FALSE, (IPTR)FALSE };
73 struct RDArgs *rda;
75 rda = ReadArgs("FROM/A,TO/A,HARD/S,FORCE/S", args, NULL);
77 if(rda != NULL)
79 if(args[ARG_HARD])
81 BPTR lock;
83 lock = Lock((STRPTR)args[ARG_TO], SHARED_LOCK);
85 if(lock != NULL)
87 struct FileInfoBlock *fib = AllocDosObject(DOS_FIB, NULL);
89 if(fib != NULL)
91 if(Examine(lock, fib))
93 /* Directories may only be hard-linked to if FORCE is
94 specified */
95 if(fib->fib_DirEntryType >= 0 && !(BOOL)args[ARG_FORCE])
97 PutStr("Hard links to directories require the"
98 " FORCE keyword\n");
100 else
102 /* Check loops? */
103 if(MakeLink((STRPTR)args[ARG_FROM], lock, FALSE))
104 retval = RETURN_OK;
105 else
106 PrintFault(IoErr(), "MakeLink");
110 FreeDosObject(DOS_FIB, fib);
113 UnLock(lock);
115 else
117 PutStr((STRPTR)args[ARG_TO]);
118 PrintFault(IoErr(), "");
121 else
123 if(MakeLink((STRPTR)args[ARG_FROM], (STRPTR)args[ARG_TO], TRUE))
124 retval = RETURN_OK;
127 else
129 PrintFault(IoErr(), "MakeLink");
130 retval = RETURN_FAIL;
133 FreeArgs(rda);
135 return retval;