genericopenlibs/cstdlib/LPOSIX/ACCESS.C
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     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 * The only thing we could fail on is write access to a read-only file
       
    16 * 
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 #include <fcntl.h>
       
    23 #include <sys/stat.h>
       
    24 #include <unistd.h>
       
    25 
       
    26 EXPORT_C int access(const char *fn, int flags)
       
    27 	{
       
    28 	struct stat s;
       
    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 		return -1;
       
    35 	return 0;
       
    36 	}
       
    37 
       
    38 EXPORT_C int waccess(const wchar_t *fn, int flags)
       
    39 	{
       
    40 	struct stat s;
       
    41 	if (wstat(fn, &s))
       
    42 		return -1;
       
    43 	if (s.st_mode & S_IFDIR)
       
    44 		return 0;
       
    45 	if ((flags&W_OK)&&(s.st_mode&S_IWRITE)==0)
       
    46 		return -1;
       
    47 	return 0;
       
    48 	}