2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
5 ANSI C function readlink().
8 #include <aros/debug.h>
10 #include <dos/filesystem.h>
11 #include <proto/dos.h>
15 #include "__arosc_privdata.h"
17 #include "__filesystem_support.h"
20 /*****************************************************************************
33 Places the contents of a symbolic link in a buffer of given size. No NUL
34 char is appended to the buffer.
37 path - the path to the symbolic link
38 buf - pointer to the buffer where to store the symbolic link content
39 bufsize - the size of the buffer in bytes
42 The call returns the count of characters placed in the buffer if it
43 succeeds, or a -1 if an error occurs, placing the error code in the
44 global variable errno.
48 struct IOFileSys iofs
;
49 struct DevProc
*dvp
= NULL
;
51 struct Process
*me
= (struct Process
*)FindTask(NULL
);
53 /* check for empty path before potential conversion from "." to "" */
54 if (__doupath
&& path
&& *path
== '\0')
60 path
= __path_u2a(path
);
64 /* we need to know if it is really a soft link */
65 InitIOFS(&iofs
, FSA_OPEN
, DOSBase
);
66 iofs
.io_Union
.io_OPEN
.io_FileMode
= FMF_READ
;
67 iofs
.io_Union
.io_OPEN
.io_Filename
= StripVolume(path
);
71 if ((dvp
= GetDeviceProc(path
, dvp
)) == NULL
)
77 error
= DoIOFS(&iofs
, dvp
, NULL
, DOSBase
);
79 while (error
== ERROR_OBJECT_NOT_FOUND
);
81 if (error
== ERROR_NO_MORE_ENTRIES
)
82 error
= me
->pr_Result2
= ERROR_OBJECT_NOT_FOUND
;
85 /* open I/O request successful, but this is not*/
86 /* what we want, don't forget to close again */
87 InitIOFS(&iofs
, FSA_CLOSE
, DOSBase
);
88 DoIO((struct IORequest
*) &iofs
);
89 /* set an error that translates to EINVAL */
90 error
= me
->pr_Result2
= ERROR_OBJECT_WRONG_TYPE
;
92 else if (error
== ERROR_IS_SOFT_LINK
)
94 /* it is a soft link, try to read it */
95 res
= ReadLink(dvp
->dvp_Port
, dvp
->dvp_Lock
, path
, buf
, bufsize
);
103 /* clear the soft link error */
104 error
= me
->pr_Result2
= 0;
111 errno
= IoErr2errno(error
);