compiler/clib: Don't hide access to aroscbase behind a #define.
[AROS.git] / compiler / clib / readlink.c
blobaa3f91847ee51b831d5a3183ef0333b7222f9724
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 ANSI C function readlink().
6 */
8 #include <aros/debug.h>
10 #include <proto/dos.h>
12 #include <errno.h>
14 #include "__arosc_privdata.h"
15 #include "__errno.h"
16 #include "__filesystem_support.h"
17 #include "__upath.h"
19 /*****************************************************************************
21 NAME */
22 #include <unistd.h>
24 ssize_t readlink(
26 /* SYNOPSIS */
27 const char *path,
28 char *buf,
29 size_t bufsize)
31 /* FUNCTION
32 Places the contents of a symbolic link in a buffer of given size. No NUL
33 char is appended to the buffer.
35 INPUTS
36 path - the path to the symbolic link
37 buf - pointer to the buffer where to store the symbolic link content
38 bufsize - the size of the buffer in bytes
40 RESULT
41 The call returns the count of characters placed in the buffer if it
42 succeeds, or a -1 if an error occurs, placing the error code in the
43 global variable errno.
46 struct aroscbase *aroscbase = __GM_GetBase();
47 ssize_t res = -1;
48 struct DevProc *dvp = NULL;
49 LONG error;
50 struct Process *me = (struct Process *)FindTask(NULL);
52 /* check for empty path before potential conversion from "." to "" */
53 if (aroscbase->acb_doupath && path && *path == '\0')
55 errno = ENOENT;
56 return res;
59 path = __path_u2a(path);
60 if (path == NULL)
61 return res;
63 res = ReadLink(dvp->dvp_Port, dvp->dvp_Lock, path, buf, bufsize);
64 if (res == -1) {
65 error = IoErr();
66 } else {
67 if (res == -2)
68 res = bufsize;
69 error = me->pr_Result2 = 0;
72 FreeDeviceProc(dvp);
74 if (error)
75 errno = IoErr2errno(error);
77 return res;