2014-11-11 18:52:24 +01:00
|
|
|
/****************************************************************************
|
2021-03-08 22:39:04 +01:00
|
|
|
* libs/libc/unistd/lib_access.c
|
2014-11-11 18:52:24 +01:00
|
|
|
*
|
2021-03-02 15:54:21 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2014-11-11 18:52:24 +01:00
|
|
|
*
|
2021-03-02 15:54:21 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2014-11-11 18:52:24 +01:00
|
|
|
*
|
2021-03-02 15:54:21 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2014-11-11 18:52:24 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2020-09-10 06:10:52 +02:00
|
|
|
#include <sys/stat.h>
|
2014-11-11 18:52:24 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-04-08 15:32:08 +02:00
|
|
|
* Pre-processor Definitions
|
2014-11-11 18:52:24 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Type Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-10-03 00:30:35 +02:00
|
|
|
* Public Data
|
2014-11-11 18:52:24 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2016-02-22 01:08:58 +01:00
|
|
|
* Private Data
|
2014-11-11 18:52:24 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: access
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The access() function shall check the file named by the pathname pointed
|
|
|
|
* to by the path argument for accessibility according to the bit pattern
|
2020-09-10 06:10:52 +02:00
|
|
|
* contained in amode, using the real user ID in place of the effective
|
|
|
|
* user ID and the real group ID in place of the effective group ID.
|
2014-11-11 18:52:24 +01:00
|
|
|
* As there are no users in NuttX, the function always succeeds.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2014-11-11 18:52:24 +01:00
|
|
|
* path - a pointer to the path
|
|
|
|
* amode - the access mode
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2020-09-10 06:10:52 +02:00
|
|
|
* Return OK (zero) if the caller can access the file with the required
|
|
|
|
* permission, otherwise return -1.
|
2014-11-11 18:52:24 +01:00
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int access(FAR const char *path, int amode)
|
|
|
|
{
|
2020-09-10 06:10:52 +02:00
|
|
|
struct stat s;
|
|
|
|
|
|
|
|
if (stat(path, &s))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s.st_mode & S_IFDIR)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (amode & W_OK)
|
|
|
|
{
|
|
|
|
if (s.st_mode & S_IWUSR)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-11 18:52:24 +01:00
|
|
|
return 0;
|
|
|
|
}
|