Upgraded GRUB2 to 2.00 release.
[AROS.git] / compiler / clib / readlink.c
blobe21d41c65dbc2176943291a64cfdff1b32e5a38d
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 POSIX.1-2008 function readlink().
6 */
8 #include <aros/debug.h>
10 #include <proto/dos.h>
12 #include <errno.h>
14 #include "__arosc_privdata.h"
15 #include "__filesystem_support.h"
16 #include "__upath.h"
18 /*****************************************************************************
20 NAME */
21 #include <unistd.h>
23 ssize_t readlink(
25 /* SYNOPSIS */
26 const char *path,
27 char *buf,
28 size_t bufsize)
30 /* FUNCTION
31 Places the contents of a symbolic link in a buffer of given size. No NUL
32 char is appended to the buffer.
34 INPUTS
35 path - the path to the symbolic link
36 buf - pointer to the buffer where to store the symbolic link content
37 bufsize - the size of the buffer in bytes
39 RESULT
40 The call returns the count of characters placed in the buffer if it
41 succeeds, or a -1 if an error occurs, placing the error code in the
42 global variable errno.
45 struct aroscbase *aroscbase = __aros_getbase();
46 ssize_t res = -1;
47 struct DevProc *dvp = NULL;
48 LONG error;
49 struct Process *me = (struct Process *)FindTask(NULL);
51 /* check for empty path before potential conversion from "." to "" */
52 if (aroscbase->acb_doupath && path && *path == '\0')
54 errno = ENOENT;
55 return res;
58 path = __path_u2a(path);
59 if (path == NULL)
60 return res;
62 res = ReadLink(dvp->dvp_Port, dvp->dvp_Lock, path, buf, bufsize);
63 if (res == -1) {
64 error = IoErr();
65 } else {
66 if (res == -2)
67 res = bufsize;
68 error = me->pr_Result2 = 0;
71 FreeDeviceProc(dvp);
73 if (error)
74 errno = __arosc_ioerr2errno(error);
76 return res;