Path: blob/main/sys/contrib/openzfs/lib/libspl/getexecname.c
48378 views
// SPDX-License-Identifier: CDDL-1.01/*2* CDDL HEADER START3*4* The contents of this file are subject to the terms of the5* Common Development and Distribution License, Version 1.0 only6* (the "License"). You may not use this file except in compliance7* with the License.8*9* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE10* or https://opensource.org/licenses/CDDL-1.0.11* See the License for the specific language governing permissions12* and limitations under the License.13*14* When distributing Covered Code, include this CDDL HEADER in each15* file and include the License file at usr/src/OPENSOLARIS.LICENSE.16* If applicable, add the following below this CDDL HEADER, with the17* fields enclosed by brackets "[]" replaced with your own identifying18* information: Portions Copyright [yyyy] [name of copyright owner]19*20* CDDL HEADER END21*/22/*23* Copyright 2007 Sun Microsystems, Inc. All rights reserved.24* Use is subject to license terms.25*/262728#include <limits.h>29#include <pthread.h>30#include <stdlib.h>31#include <string.h>32#include <unistd.h>33#include "libspl_impl.h"343536const char *37getexecname(void)38{39static char execname[PATH_MAX + 1] = "";40static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;4142char *ptr = execname;43ssize_t rc;4445(void) pthread_mutex_lock(&mtx);4647if (strlen(execname) == 0) {48rc = getexecname_impl(execname);49if (rc == -1) {50execname[0] = '\0';51ptr = NULL;52} else {53execname[rc] = '\0';54}55}5657(void) pthread_mutex_unlock(&mtx);58return (ptr);59}606162