Don't try to setup and use X11 shared memory if
[tangerine.git] / compiler / clib / symlink.c
blobe0a74904c0dd912c0a2e23e44140b826d6e93f27
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 <proto/dos.h>
12 #include <errno.h>
13 #include "__errno.h"
14 #include "__upath.h"
15 #include <aros/debug.h>
17 /*****************************************************************************
19 NAME */
20 #include <unistd.h>
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 LONG ioerr = 0;
49 UBYTE *buffer;
50 int buffersize = 256;
52 if (!oldpath || !newpath) /*safety check */
54 errno = EFAULT;
55 return -1;
58 oldpath = __path_u2a(oldpath);
59 if(!oldpath)
60 return -1;
62 oldpath = strdup(oldpath);
63 if(!oldpath)
65 errno = ENOMEM;
66 return -1;
69 newpath = __path_u2a(newpath);
70 if (!newpath)
72 free((void*) oldpath);
73 return -1;
76 if((lock = Lock((STRPTR)oldpath, SHARED_LOCK)))
80 if(!(buffer = AllocVec(buffersize, MEMF_ANY)))
82 ioerr = ERROR_NO_FREE_STORE;
83 break;
86 /* Get the full path of oldpath */
87 if(NameFromLock(lock, buffer, buffersize))
89 if(MakeLink((STRPTR)newpath, (STRPTR)buffer, TRUE))
90 retval = 0;
91 else
93 ioerr = IoErr();
94 FreeVec(buffer);
95 break;
98 else if(IoErr() != ERROR_LINE_TOO_LONG)
100 ioerr = IoErr();
101 FreeVec(buffer);
102 break;
104 FreeVec(buffer);
105 buffersize *= 2;
107 while(retval != RETURN_OK);
108 UnLock(lock);
110 else
112 /* MakeLink can create symlinks to non-existing files or
113 directories. */
114 if(IoErr() == ERROR_OBJECT_NOT_FOUND)
116 /* In this case it may be difficult to get the full absolute
117 path, so we simply trust the caller here for now */
118 if(MakeLink((STRPTR)newpath, (STRPTR)oldpath, TRUE))
119 retval = 0;
120 else
121 ioerr = IoErr();
123 else
124 ioerr = IoErr();
126 free((void*) oldpath);
128 if(ioerr)
129 errno = IoErr2errno(ioerr);
131 return retval;
132 } /* symlink */