New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / workbench / c / MakeLink.c
blobbdfb3398d72a85b7fb3c80e29fb8e7411346d1f1
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 /******************************************************************************
12 NAME
14 MakeLink
16 SYNOPSIS
18 FROM/A, TO/A, HARD/S, FORCE/S
20 LOCATION
22 Workbench:C
24 FUNCTION
26 Create a link to a file
28 INPUTS
30 FROM -- The name of the link
31 TO -- The name of the file or directory to link to
32 HARD -- If specified, the link will be a hard-link; default is
33 to create a soft-link
34 FORCE -- Allow a hard-link to point to a directory
36 RESULT
38 NOTES
40 EXAMPLE
42 BUGS
44 SEE ALSO
46 INTERNALS
48 HISTORY
50 04.05.2000 SDuvan implemented
52 ******************************************************************************/
54 #include <dos/dos.h>
55 #include <dos/dosextens.h>
56 #include <dos/rdargs.h>
57 #include <dos/stdio.h>
58 #include <proto/dos.h>
59 #include <proto/exec.h>
60 #include <utility/tagitem.h>
62 static const char version[] = "$VER: MakeLink 41.1 (02.06.2000)\n";
64 enum { ARG_FROM = 0, ARG_TO, ARG_HARD, ARG_FORCE };
66 int __nocommandline;
68 int main(void)
70 int retval = RETURN_FAIL;
71 IPTR args[] = { NULL, NULL, (IPTR)FALSE, (IPTR)FALSE };
72 struct RDArgs *rda;
74 rda = ReadArgs("FROM/A,TO/A,HARD/S,FORCE/S", args, NULL);
76 if(rda != NULL)
78 BPTR lock;
80 lock = Lock((STRPTR)args[ARG_TO], SHARED_LOCK);
82 if(lock != NULL)
84 struct FileInfoBlock *fib = AllocDosObject(DOS_FIB, NULL);
86 if(fib != NULL)
88 if(Examine(lock, fib) == DOSTRUE)
90 /* Directories may only be hard-linked to if FORCE is
91 specified */
92 if(fib->fib_DirEntryType >= 0 &&
93 !(BOOL)args[ARG_FORCE] && (BOOL)args[ARG_HARD])
95 PutStr("Hard-links to directories require the FORCE"
96 "keyword\n");
98 else
100 /* Check loops? */
101 if(MakeLink((STRPTR)args[ARG_FROM],
102 (BOOL)args[ARG_HARD] ? lock :
103 (STRPTR)args[ARG_TO],
104 !(BOOL)args[ARG_HARD]) == DOSTRUE)
105 retval = RETURN_OK;
106 else
107 PrintFault(IoErr(), "MakeLink");
111 FreeDosObject(DOS_FIB, fib);
114 UnLock(lock);
116 else
118 PutStr((STRPTR)args[ARG_TO]);
119 PrintFault(IoErr(), "");
122 else
124 PrintFault(IoErr(), "MakeLink");
125 retval = RETURN_FAIL;
128 FreeArgs(rda);
130 return retval;