sl@0: /* sl@0: * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: Implementation of link/symlink. sl@0: * sl@0: */ sl@0: sl@0: sl@0: // INCLUDE FILES sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "lposix.h" sl@0: #include sl@0: #include sl@0: #include "sysreent.h" sl@0: #include sl@0: #include "sysif.h" sl@0: #include "systemspecialfilercg.h" sl@0: #include "link.h" sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // Funcation name: link sl@0: // Description: Provides link functionality. sl@0: // Returns: 0 : On success sl@0: // -1 : On error sl@0: // In case of error, errno value set sl@0: // Remark: This is a simulated functionality and not supported by the platform sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: sl@0: extern "C" { sl@0: sl@0: #define MAXPATHLEN 260 /* E32STD.H: KMaxFullName + 4 to avoid data loss */ sl@0: sl@0: EXPORT_C int link(const char *oldpath, const char *newpath) sl@0: { sl@0: wchar_t _oldwidename[MAXPATHLEN+1]; sl@0: wchar_t _newwidename[MAXPATHLEN+1]; sl@0: sl@0: if ((size_t)-1 != mbstowcs(_oldwidename, oldpath, MAXPATHLEN) && \ sl@0: (size_t)-1 != mbstowcs(_newwidename, newpath, MAXPATHLEN)) sl@0: { sl@0: return _link_r(&errno, _oldwidename, _newwidename); sl@0: } sl@0: errno = EILSEQ; sl@0: return -1; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // Funcation name: symlink sl@0: // Description: Provides symlink functionality which is exactly similar to link sl@0: // in our case. sl@0: // Returns: ssize_t : On success sl@0: // -1 : On error sl@0: // In case of error, errno value set sl@0: // sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: sl@0: EXPORT_C int symlink(const char *oldpath, const char *newpath) sl@0: { sl@0: wchar_t _oldwidename[MAXPATHLEN+1]; sl@0: wchar_t _newwidename[MAXPATHLEN+1]; sl@0: sl@0: if ((size_t)-1 != mbstowcs(_oldwidename, oldpath, MAXPATHLEN) && \ sl@0: (size_t)-1 != mbstowcs(_newwidename, newpath, MAXPATHLEN)) sl@0: { sl@0: return _link_r(&errno, _oldwidename, _newwidename); sl@0: } sl@0: errno = EILSEQ; sl@0: return -1; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // Funcation name: readlink sl@0: // Description: Reads the link file. sl@0: // Returns: ssize_t : On success sl@0: // -1 : On error sl@0: // In case of error, errno value set sl@0: // sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: sl@0: EXPORT_C ssize_t readlink(const char *path, char *buf, int bufsize) sl@0: { sl@0: TSpecialFileType fileType; sl@0: struct SLinkInfo enBuf; sl@0: int err = KErrNone; sl@0: char name[MAXPATHLEN+1]; sl@0: sl@0: wchar_t widename[MAXPATHLEN+1]; sl@0: sl@0: if(path) sl@0: { sl@0: if ((size_t)-1 != mbstowcs(widename, path, MAXPATHLEN)) sl@0: { sl@0: /*Special file identification and read of IPC is utilized here*/ sl@0: if( (fileType = _SystemSpecialFileBasedFilePath(widename, err, Backend()->FileSession())) == EFileTypeSymLink) sl@0: { sl@0: if (err) sl@0: { sl@0: return MapError(err, errno); sl@0: } sl@0: err = _ReadSysSplFile(widename, (char*)&enBuf, sizeof(struct SLinkInfo), errno, Backend()->FileSession()); sl@0: if (err == KErrNone) sl@0: { sl@0: if((0 < bufsize && bufsize <= SSIZE_MAX) && NULL != buf ) sl@0: { sl@0: if ((size_t)-1 != wcstombs(name, enBuf.iParentPath, sizeof(enBuf.iParentPath))) sl@0: { sl@0: strncpy(buf, name, bufsize); sl@0: return (strlen(name) >= bufsize ? bufsize : strlen(buf)); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: errno = EINVAL; sl@0: return -1; sl@0: } sl@0: } sl@0: } sl@0: else if(err || (EFileNotFound == fileType)) sl@0: { sl@0: return MapError(err, errno); sl@0: } sl@0: errno = EINVAL; sl@0: return -1; sl@0: } sl@0: return MapError(EILSEQ, errno); sl@0: } sl@0: return MapError(EINVAL, errno); sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // Funcation name: unlink sl@0: // Description: Provides unlink functionality. sl@0: // Returns: 0 : On success sl@0: // -1 : On error sl@0: // In case of error, errno value set sl@0: // sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: sl@0: EXPORT_C int unlink(const char *pathname) sl@0: { sl@0: wchar_t _pathwidename[MAXPATHLEN+1]; sl@0: sl@0: if ((size_t)-1 != mbstowcs(_pathwidename, pathname, MAXPATHLEN)) sl@0: { sl@0: return _unlink_r(&errno, _pathwidename); sl@0: } sl@0: errno = EILSEQ; sl@0: return -1; sl@0: } sl@0: sl@0: // ----------------------------------------------------------------------------- sl@0: // Funcation name: lstat, __xstat, __lxstat sl@0: // Description: All these functions directly call stat by themself . sl@0: // Returns: 0 : On success sl@0: // -1 : On error sl@0: // In case of error, errno value set sl@0: // sl@0: // ----------------------------------------------------------------------------- sl@0: // sl@0: sl@0: EXPORT_C int lstat(const char *file_name, struct stat *buf) sl@0: { sl@0: if(!buf) sl@0: { sl@0: errno = EFAULT ; sl@0: return -1 ; sl@0: } sl@0: sl@0: wchar_t tmpbuf[MAXPATHLEN+1]; sl@0: if ((size_t)-1 != mbstowcs(tmpbuf, file_name, MAXPATHLEN)) sl@0: { sl@0: return _lstat_r(&errno, tmpbuf, buf); sl@0: } sl@0: errno = EILSEQ; sl@0: return -1; sl@0: } sl@0: EXPORT_C int __xstat(int /*vers*/, const char *file, struct stat *buf) sl@0: { sl@0: return stat(file, buf); sl@0: } sl@0: sl@0: EXPORT_C int __lxstat (int /*version*/, const char *file, struct stat *buf) sl@0: { sl@0: return lstat(file, buf); sl@0: } sl@0: sl@0: sl@0: } // extern "C" sl@0: sl@0: sl@0: // End of File