unistd: add support for confstr()
add support for POSIX defined confstr() Signed-off-by: p-szafonimateusz <p-szafonimateusz@xiaomi.com>
This commit is contained in:
parent
8108aad1a4
commit
396f5b40ce
5 changed files with 132 additions and 4 deletions
|
|
@ -28,7 +28,7 @@ Units of Functionality Requirements:
|
||||||
+------------------------------+----------------+---------+
|
+------------------------------+----------------+---------+
|
||||||
| `POSIX_FILE_LOCKING`_ | Yes | |
|
| `POSIX_FILE_LOCKING`_ | Yes | |
|
||||||
+------------------------------+----------------+---------+
|
+------------------------------+----------------+---------+
|
||||||
| `POSIX_SINGLE_PROCESS`_ | 7/9 | |
|
| `POSIX_SINGLE_PROCESS`_ | 8/9 | |
|
||||||
+------------------------------+----------------+---------+
|
+------------------------------+----------------+---------+
|
||||||
| `POSIX_THREADS_BASE`_ | Yes | |
|
| `POSIX_THREADS_BASE`_ | Yes | |
|
||||||
+------------------------------+----------------+---------+
|
+------------------------------+----------------+---------+
|
||||||
|
|
@ -631,7 +631,7 @@ Single Process:
|
||||||
+--------------------------------+---------+
|
+--------------------------------+---------+
|
||||||
| API | Support |
|
| API | Support |
|
||||||
+================================+=========+
|
+================================+=========+
|
||||||
| confstr() | No |
|
| confstr() | Yes |
|
||||||
+--------------------------------+---------+
|
+--------------------------------+---------+
|
||||||
| environ | Yes |
|
| environ | Yes |
|
||||||
+--------------------------------+---------+
|
+--------------------------------+---------+
|
||||||
|
|
|
||||||
|
|
@ -260,6 +260,23 @@
|
||||||
#define _SC_NPROCESSORS_CONF 0x007d
|
#define _SC_NPROCESSORS_CONF 0x007d
|
||||||
#define _SC_NPROCESSORS_ONLN 0x007e
|
#define _SC_NPROCESSORS_ONLN 0x007e
|
||||||
|
|
||||||
|
/* Constants used with POSIX confstr(). */
|
||||||
|
|
||||||
|
#define _CS_PATH 1
|
||||||
|
#define _CS_POSIX_V6_ILP32_OFF32_CFLAGS 2
|
||||||
|
#define _CS_POSIX_V6_ILP32_OFF32_LDFLAGS 3
|
||||||
|
#define _CS_POSIX_V6_ILP32_OFF32_LIBS 4
|
||||||
|
#define _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS 5
|
||||||
|
#define _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS 6
|
||||||
|
#define _CS_POSIX_V6_ILP32_OFFBIG_LIBS 7
|
||||||
|
#define _CS_POSIX_V6_LP64_OFF64_CFLAGS 8
|
||||||
|
#define _CS_POSIX_V6_LP64_OFF64_LDFLAGS 9
|
||||||
|
#define _CS_POSIX_V6_LP64_OFF64_LIBS 10
|
||||||
|
#define _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS 11
|
||||||
|
#define _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS 12
|
||||||
|
#define _CS_POSIX_V6_LPBIG_OFFBIG_LIBS 13
|
||||||
|
#define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS 14
|
||||||
|
|
||||||
/* The following symbolic constants must be defined for file streams: */
|
/* The following symbolic constants must be defined for file streams: */
|
||||||
|
|
||||||
#define STDERR_FILENO 2 /* File number of stderr */
|
#define STDERR_FILENO 2 /* File number of stderr */
|
||||||
|
|
@ -446,6 +463,7 @@ int sethostname(FAR const char *name, size_t namelen);
|
||||||
long sysconf(int name);
|
long sysconf(int name);
|
||||||
long fpathconf(int fildes, int name);
|
long fpathconf(int fildes, int name);
|
||||||
long pathconf(FAR const char *path, int name);
|
long pathconf(FAR const char *path, int name);
|
||||||
|
size_t confstr(int name, FAR char *buf, size_t len);
|
||||||
|
|
||||||
/* User and group identity management */
|
/* User and group identity management */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,8 @@ set(SRCS
|
||||||
lib_flock.c
|
lib_flock.c
|
||||||
lib_getpass.c
|
lib_getpass.c
|
||||||
lib_chdir.c
|
lib_chdir.c
|
||||||
lib_fchdir.c)
|
lib_fchdir.c
|
||||||
|
lib_confstr.c)
|
||||||
|
|
||||||
if(NOT CONFIG_SCHED_USER_IDENTITY)
|
if(NOT CONFIG_SCHED_USER_IDENTITY)
|
||||||
list(
|
list(
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ CSRCS += lib_futimes.c lib_lutimes.c lib_gethostname.c lib_sethostname.c
|
||||||
CSRCS += lib_fchownat.c lib_linkat.c lib_readlinkat.c lib_symlinkat.c
|
CSRCS += lib_fchownat.c lib_linkat.c lib_readlinkat.c lib_symlinkat.c
|
||||||
CSRCS += lib_unlinkat.c lib_usleep.c lib_getpgrp.c lib_getpgid.c
|
CSRCS += lib_unlinkat.c lib_usleep.c lib_getpgrp.c lib_getpgid.c
|
||||||
CSRCS += lib_lockf.c lib_flock.c lib_getpass.c
|
CSRCS += lib_lockf.c lib_flock.c lib_getpass.c
|
||||||
CSRCS += lib_chdir.c lib_fchdir.c
|
CSRCS += lib_chdir.c lib_fchdir.c lib_confstr.c
|
||||||
|
|
||||||
ifneq ($(CONFIG_SCHED_USER_IDENTITY),y)
|
ifneq ($(CONFIG_SCHED_USER_IDENTITY),y)
|
||||||
CSRCS += lib_setuid.c lib_setgid.c lib_getuid.c lib_getgid.c
|
CSRCS += lib_setuid.c lib_setgid.c lib_getuid.c lib_getgid.c
|
||||||
|
|
|
||||||
109
libs/libc/unistd/lib_confstr.c
Normal file
109
libs/libc/unistd/lib_confstr.c
Normal file
|
|
@ -0,0 +1,109 @@
|
||||||
|
/****************************************************************************
|
||||||
|
* libs/libc/unistd/lib_confstr.c
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: confstr
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* The confstr() function shall return the value of configuration-defined
|
||||||
|
* string variables associated with the name argument.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* If name is an invalid value, confstr() shall return 0 and set errno to
|
||||||
|
* indicate the error.
|
||||||
|
*
|
||||||
|
* If name doesn't have a configuration-defined value, confstr() returns 0
|
||||||
|
* and leaves errno unchanged.
|
||||||
|
*
|
||||||
|
* If name has a configuration-defined value, confstr() returns the size
|
||||||
|
* of the buffer that would be needed to hold the entire string value.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
size_t confstr(int name, FAR char *buf, size_t len)
|
||||||
|
{
|
||||||
|
FAR const char *p;
|
||||||
|
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
/* System-defined default PATH */
|
||||||
|
|
||||||
|
case _CS_PATH:
|
||||||
|
{
|
||||||
|
#ifdef CONFIG_PATH_INITIAL
|
||||||
|
p = CONFIG_PATH_INITIAL;
|
||||||
|
#else
|
||||||
|
p = "\0";
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Programming environment is not supported on NuttX, so all
|
||||||
|
* _CS_POSIX_V6 configuration variables are empty.
|
||||||
|
*/
|
||||||
|
|
||||||
|
case _CS_POSIX_V6_ILP32_OFF32_CFLAGS:
|
||||||
|
case _CS_POSIX_V6_ILP32_OFF32_LDFLAGS:
|
||||||
|
case _CS_POSIX_V6_ILP32_OFF32_LIBS:
|
||||||
|
case _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS:
|
||||||
|
case _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS:
|
||||||
|
case _CS_POSIX_V6_ILP32_OFFBIG_LIBS:
|
||||||
|
case _CS_POSIX_V6_LP64_OFF64_CFLAGS:
|
||||||
|
case _CS_POSIX_V6_LP64_OFF64_LDFLAGS:
|
||||||
|
case _CS_POSIX_V6_LP64_OFF64_LIBS:
|
||||||
|
case _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS:
|
||||||
|
case _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS:
|
||||||
|
case _CS_POSIX_V6_LPBIG_OFFBIG_LIBS:
|
||||||
|
case _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS:
|
||||||
|
{
|
||||||
|
p = "\0";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
set_errno(EINVAL);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len != 0 && buf != NULL)
|
||||||
|
{
|
||||||
|
strlcpy(buf, p, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (strlen(p) + 1);
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue