Update contrib.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: Implementation of link/symlink.
21 #include <sys/errno.h>
22 #include <sys/types.h>
28 #include <sys/limits.h>
32 #include "systemspecialfilercg.h"
35 // -----------------------------------------------------------------------------
36 // Funcation name: link
37 // Description: Provides link functionality.
38 // Returns: 0 : On success
40 // In case of error, errno value set
41 // Remark: This is a simulated functionality and not supported by the platform
42 // -----------------------------------------------------------------------------
47 #define MAXPATHLEN 260 /* E32STD.H: KMaxFullName + 4 to avoid data loss */
49 EXPORT_C int link(const char *oldpath, const char *newpath)
51 wchar_t _oldwidename[MAXPATHLEN+1];
52 wchar_t _newwidename[MAXPATHLEN+1];
54 if ((size_t)-1 != mbstowcs(_oldwidename, oldpath, MAXPATHLEN) && \
55 (size_t)-1 != mbstowcs(_newwidename, newpath, MAXPATHLEN))
57 return _link_r(&errno, _oldwidename, _newwidename);
63 // -----------------------------------------------------------------------------
64 // Funcation name: symlink
65 // Description: Provides symlink functionality which is exactly similar to link
67 // Returns: ssize_t : On success
69 // In case of error, errno value set
71 // -----------------------------------------------------------------------------
74 EXPORT_C int symlink(const char *oldpath, const char *newpath)
76 wchar_t _oldwidename[MAXPATHLEN+1];
77 wchar_t _newwidename[MAXPATHLEN+1];
79 if ((size_t)-1 != mbstowcs(_oldwidename, oldpath, MAXPATHLEN) && \
80 (size_t)-1 != mbstowcs(_newwidename, newpath, MAXPATHLEN))
82 return _link_r(&errno, _oldwidename, _newwidename);
88 // -----------------------------------------------------------------------------
89 // Funcation name: readlink
90 // Description: Reads the link file.
91 // Returns: ssize_t : On success
93 // In case of error, errno value set
95 // -----------------------------------------------------------------------------
98 EXPORT_C ssize_t readlink(const char *path, char *buf, int bufsize)
100 TSpecialFileType fileType;
101 struct SLinkInfo enBuf;
103 char name[MAXPATHLEN+1];
105 wchar_t widename[MAXPATHLEN+1];
109 if ((size_t)-1 != mbstowcs(widename, path, MAXPATHLEN))
111 /*Special file identification and read of IPC is utilized here*/
112 if( (fileType = _SystemSpecialFileBasedFilePath(widename, err, Backend()->FileSession())) == EFileTypeSymLink)
116 return MapError(err, errno);
118 err = _ReadSysSplFile(widename, (char*)&enBuf, sizeof(struct SLinkInfo), errno, Backend()->FileSession());
121 if((0 < bufsize && bufsize <= SSIZE_MAX) && NULL != buf )
123 if ((size_t)-1 != wcstombs(name, enBuf.iParentPath, sizeof(enBuf.iParentPath)))
125 strncpy(buf, name, bufsize);
126 return (strlen(name) >= bufsize ? bufsize : strlen(buf));
136 else if(err || (EFileNotFound == fileType))
138 return MapError(err, errno);
143 return MapError(EILSEQ, errno);
145 return MapError(EINVAL, errno);
148 // -----------------------------------------------------------------------------
149 // Funcation name: unlink
150 // Description: Provides unlink functionality.
151 // Returns: 0 : On success
153 // In case of error, errno value set
155 // -----------------------------------------------------------------------------
158 EXPORT_C int unlink(const char *pathname)
160 wchar_t _pathwidename[MAXPATHLEN+1];
162 if ((size_t)-1 != mbstowcs(_pathwidename, pathname, MAXPATHLEN))
164 return _unlink_r(&errno, _pathwidename);
170 // -----------------------------------------------------------------------------
171 // Funcation name: lstat, __xstat, __lxstat
172 // Description: All these functions directly call stat by themself .
173 // Returns: 0 : On success
175 // In case of error, errno value set
177 // -----------------------------------------------------------------------------
180 EXPORT_C int lstat(const char *file_name, struct stat *buf)
188 wchar_t tmpbuf[MAXPATHLEN+1];
189 if ((size_t)-1 != mbstowcs(tmpbuf, file_name, MAXPATHLEN))
191 return _lstat_r(&errno, tmpbuf, buf);
196 EXPORT_C int __xstat(int /*vers*/, const char *file, struct stat *buf)
198 return stat(file, buf);
201 EXPORT_C int __lxstat (int /*version*/, const char *file, struct stat *buf)
203 return lstat(file, buf);