Autodoc corrections
[cake.git] / compiler / clib / symlink.c
blob13bb7b65e51ed3196dfa76e13a390176b425a677
1 /*
2 Copyright © 2004, The AROS Development Team. All rights reserved.
3 $Id$
5 POSIX function symlink().
6 */
8 #include <aros/debug.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <proto/dos.h>
13 #include <errno.h>
14 #include "__errno.h"
15 #include "__upath.h"
16 #include <aros/debug.h>
18 /*****************************************************************************
20 NAME */
22 int symlink(
24 /* SYNOPSIS */
25 const char *oldpath,
26 const char *newpath)
28 /* FUNCTION
30 INPUTS
32 RESULT
34 NOTES
36 EXAMPLE
38 BUGS
40 SEE ALSO
42 INTERNALS
44 ******************************************************************************/
46 int retval = -1;
47 BPTR lock;
48 struct FileInfoBlock *fib;
49 int errorset = FALSE;
50 LONG ioerr;
51 UBYTE *buffer;
52 int bufferincrease = 256;
53 int buffersize = bufferincrease;
55 if (!oldpath || !newpath) /*safety check */
57 errno = EFAULT;
58 return -1;
61 if(oldpath = strdup(__path_u2a(oldpath)))
63 newpath = __path_u2a(newpath);
64 if (!newpath)
66 free(oldpath);
67 return -1;
70 if(lock = Lock((STRPTR)oldpath, SHARED_LOCK)) {
73 if(!(buffer = AllocVec(buffersize, MEMF_ANY)))
75 ioerr = ERROR_NO_FREE_STORE;
76 errorset = TRUE;
77 break;
80 /* Get the full path of oldpath */
81 if(NameFromLock(lock, buffer, buffersize))
83 if(MakeLink((STRPTR)newpath,
84 (STRPTR)buffer,
85 TRUE) == DOSTRUE)
86 retval = RETURN_OK;
87 else
89 ioerr = IoErr();
90 errorset = TRUE;
91 break;
94 else if(IoErr() != ERROR_LINE_TOO_LONG)
96 ioerr = IoErr();
97 errorset = TRUE;
98 break;
100 FreeVec(buffer);
101 buffersize += bufferincrease;
103 while(retval != RETURN_OK);
104 UnLock(lock);
106 else
108 ioerr = IoErr();
109 /* I'm not sure if MakeLink is allowed to create symlinks to
110 non-existing files or directories. If yes, then it's fine to
111 enable the following code */
112 #if 0
113 if(ioerr == ERROR_OBJECT_NOT_FOUND)
115 /* On Unices it's perfectly fine to create symlinks to
116 non-existing files or directories, however in this case it
117 may be difficult to get the full absolute path, so we are
118 simply trusting the user here for now */
119 if(MakeLink((STRPTR)newpath,
120 (STRPTR)oldpath,
121 TRUE) == DOSTRUE)
122 retval = RETURN_OK;
123 else
125 ioerr = IoErr();
126 errorset = TRUE;
129 else
130 #endif
131 errorset = TRUE;
133 free(oldpath);
136 if(errorset) errno = IoErr2errno(ioerr);
137 return retval;
138 } /* symlink */