From ed1e4ddfa7d1dba8326421b27d16664feafa661e Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Mon, 29 Nov 2021 12:46:00 +0800 Subject: [PATCH] libc: Add getprogname function defined here: https://www.freebsd.org/cgi/man.cgi?query=getprogname&sektion=3 Signed-off-by: Xiang Xiao --- include/stdlib.h | 4 +++ libs/libc/stdlib/Make.defs | 2 +- libs/libc/stdlib/lib_getprogname.c | 44 ++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 libs/libc/stdlib/lib_getprogname.c diff --git a/include/stdlib.h b/include/stdlib.h index d3454a05305..690ac4c13d6 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -265,6 +265,10 @@ FAR void *bsearch(FAR const void *key, FAR const void *base, size_t nel, size_t width, CODE int (*compar)(FAR const void *, FAR const void *)); +/* Current program name manipulation */ + +FAR const char *getprogname(void); + #undef EXTERN #if defined(__cplusplus) } diff --git a/libs/libc/stdlib/Make.defs b/libs/libc/stdlib/Make.defs index 018130ce6fe..4643d53682e 100644 --- a/libs/libc/stdlib/Make.defs +++ b/libs/libc/stdlib/Make.defs @@ -20,7 +20,7 @@ # Add the stdlib C files to the build -CSRCS += lib_abs.c lib_abort.c lib_atof.c lib_atoi.c +CSRCS += lib_abs.c lib_abort.c lib_atof.c lib_atoi.c lib_getprogname.c CSRCS += lib_atol.c lib_atoll.c lib_div.c lib_ldiv.c lib_lldiv.c lib_Exit.c CSRCS += lib_itoa.c lib_labs.c lib_llabs.c lib_realpath.c lib_bsearch.c CSRCS += lib_rand.c lib_qsort.c lib_srand.c lib_strtol.c diff --git a/libs/libc/stdlib/lib_getprogname.c b/libs/libc/stdlib/lib_getprogname.c new file mode 100644 index 00000000000..a0a712151b2 --- /dev/null +++ b/libs/libc/stdlib/lib_getprogname.c @@ -0,0 +1,44 @@ +/**************************************************************************** + * libs/libc/stdlib/lib_getprogname.c + * + * 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 + +#include +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: getprogname + ****************************************************************************/ + +FAR const char *getprogname(void) +{ + FAR struct task_info_s *info; + + info = task_get_info(); + return info->argv[0]; +}