From e614814eb45be55922eaa60747177a53163c2bd7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 11 Nov 2014 11:52:24 -0600 Subject: From Lorenz Meier: The implementation of access() as vararg macro has the issue that any function call with the same name (even in a C++ class) will match with it and result in a compile error. I have replaced it with a small function, and tried to have decent documentation as well. This resolves the compile issue, and shouldn’t have negative side effects for users of the function. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nuttx/include/unistd.h | 5 +-- nuttx/libc/unistd/Make.defs | 3 +- nuttx/libc/unistd/lib_access.c | 92 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 nuttx/libc/unistd/lib_access.c diff --git a/nuttx/include/unistd.h b/nuttx/include/unistd.h index 5108faa51..3fbf5698d 100644 --- a/nuttx/include/unistd.h +++ b/nuttx/include/unistd.h @@ -167,8 +167,9 @@ FAR char *getcwd(FAR char *buf, size_t size); /* File path operations */ -int unlink(FAR const char *pathname); +int access(FAR const char *path, int amode); int rmdir(FAR const char *pathname); +int unlink(FAR const char *pathname); /* Execution of programs from files */ @@ -190,8 +191,6 @@ FAR char **getoptargp(void); /* Optional argument following option */ int *getoptindp(void); /* Index into argv */ int *getoptoptp(void); /* unrecognized option character */ -#define access(...) (0) - #undef EXTERN #if defined(__cplusplus) } diff --git a/nuttx/libc/unistd/Make.defs b/nuttx/libc/unistd/Make.defs index 323e0a3b8..10cf5f0be 100644 --- a/nuttx/libc/unistd/Make.defs +++ b/nuttx/libc/unistd/Make.defs @@ -35,7 +35,8 @@ # Add the unistd C files to the build -CSRCS += lib_getopt.c lib_getoptargp.c lib_getoptindp.c lib_getoptoptp.c +CSRCS += lib_access.c lib_getopt.c lib_getoptargp.c lib_getoptindp.c +CSRCS += lib_getoptoptp.c ifneq ($(CONFIG_NFILE_DESCRIPTORS),0) ifneq ($(CONFIG_DISABLE_ENVIRON),y) diff --git a/nuttx/libc/unistd/lib_access.c b/nuttx/libc/unistd/lib_access.c new file mode 100644 index 000000000..487117950 --- /dev/null +++ b/nuttx/libc/unistd/lib_access.c @@ -0,0 +1,92 @@ +/**************************************************************************** + * lib/unistd/lib_access.c + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +/**************************************************************************** + * Preprocessor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Definitions + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * 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 + * 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. + * As there are no users in NuttX, the function always succeeds. + * + * Parameters: + * path - a pointer to the path + * amode - the access mode + * + * Returned Value: + * Always OK (zero) + * + * Assumptions: + * + ****************************************************************************/ + +int access(FAR const char *path, int amode) +{ + return 0; +} -- cgit v1.2.3