muimaster.library: support Listview_List in List
[AROS.git] / compiler / posixc / readlink.c
blob506d25fcdd131cfadbf0433842d62d6bebe2c7d2
1 /*
2 Copyright © 1995-2013, 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 "__posixc_intbase.h"
15 #include "__upath.h"
17 /*****************************************************************************
19 NAME */
20 #include <unistd.h>
22 ssize_t readlink(
24 /* SYNOPSIS */
25 const char *path,
26 char *buf,
27 size_t bufsize)
29 /* FUNCTION
30 Places the contents of a symbolic link in a buffer of given size. No NUL
31 char is appended to the buffer.
33 INPUTS
34 path - the path to the symbolic link
35 buf - pointer to the buffer where to store the symbolic link content
36 bufsize - the size of the buffer in bytes
38 RESULT
39 The call returns the count of characters placed in the buffer if it
40 succeeds, or a -1 if an error occurs, placing the error code in the
41 global variable errno.
44 struct PosixCIntBase *PosixCBase =
45 (struct PosixCIntBase *)__aros_getbase_PosixCBase();
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 (PosixCBase->doupath && path && *path == '\0')
54 errno = ENOENT;
55 return res;
58 path = __path_u2a(path);
59 if (path == NULL)
60 return res;
62 dvp = GetDeviceProc(path, NULL);
64 res = ReadLink(dvp->dvp_Port, dvp->dvp_Lock, path, buf, bufsize);
65 if (res == -1) {
66 error = IoErr();
67 } else {
68 if (res == -2)
69 res = bufsize;
70 error = me->pr_Result2 = 0;
73 FreeDeviceProc(dvp);
75 if (error)
76 errno = __stdc_ioerr2errno(error);
78 return res;