os/ossrv/genericopenlibs/openenvcore/libc/src/access.c
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:
    15 *
    16 */
    17 
    18 
    19 #include <unistd.h>
    20 #include <fcntl.h>
    21 #include <sys/stat.h>
    22 #include <errno.h>
    23 #include <wchar.h>
    24 	
    25 EXPORT_C int access(const char *fn , int flags)
    26 	{
    27     struct stat s;
    28     
    29 	if (stat(fn, &s))
    30 		return -1;
    31 	if (s.st_mode & S_IFDIR)
    32 		return 0;
    33 	if ((flags&W_OK)&&(s.st_mode&S_IWRITE)==0) 
    34 		{
    35 	    errno = EACCES ; 
    36 		return -1 ;
    37 		}
    38 		
    39 	return 0;
    40 	}
    41 #ifdef __SYMBIAN_COMPILE_UNUSED__	
    42 int _access(const char *fn , int flags)
    43 	{
    44     return access(fn, flags);
    45 	}
    46 #endif
    47 
    48 EXPORT_C int waccess(const wchar_t *fn, int flags)
    49 	{
    50 	struct stat s;
    51 	if (wstat(fn, &s))
    52 		return -1;
    53 	if (s.st_mode & S_IFDIR)
    54 		return 0;
    55 	if ((flags&W_OK)&&(s.st_mode&S_IWRITE)==0)
    56 		{
    57 		errno = EACCES ;
    58 		return -1;
    59 		}
    60 		
    61 	return 0;
    62 	}