pmt: revert 7f8090b
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
# By YZBruh
|
||||
|
||||
# Copyright 2024 Partition Manager
|
||||
#
|
||||
# Licensed 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.
|
||||
|
||||
########
|
||||
# 3.0.2
|
||||
########
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := libicrt
|
||||
LOCAL_SRC_FILES := \
|
||||
$(LOCAL_PATH)/allocator.c \
|
||||
$(LOCAL_PATH)/areadlink.c \
|
||||
$(LOCAL_PATH)/binary-io.c \
|
||||
$(LOCAL_PATH)/careadlinkat.c \
|
||||
$(LOCAL_PATH)/fd-hook.c \
|
||||
$(LOCAL_PATH)/getprogname.c \
|
||||
$(LOCAL_PATH)/unistd.c \
|
||||
$(LOCAL_PATH)/xreadlink.c
|
||||
LOCAL_C_INCLUDES := \
|
||||
$(LOCAL_PATH)/../lib \
|
||||
$(LOCAL_PATH)/../srclib
|
||||
LOCAL_CFLAGS := \
|
||||
-Wall \
|
||||
-Wextra \
|
||||
-Wno-sign-compare \
|
||||
-Wno-unused-const-variable \
|
||||
-Wno-unused-parameter \
|
||||
-Wno-unused-function \
|
||||
-Wno-unused-but-set-variable \
|
||||
-Wno-missing-field-initializers \
|
||||
-fPIC
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
@@ -1,22 +0,0 @@
|
||||
/* Memory allocators such as malloc+free.
|
||||
|
||||
Copyright (C) 2011-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#define _GL_USE_STDLIB_ALLOC 1
|
||||
#include <config.h>
|
||||
#include "allocator.h"
|
||||
#include <stdlib.h>
|
||||
struct allocator const stdlib_allocator = { malloc, realloc, free, NULL };
|
||||
@@ -1,56 +0,0 @@
|
||||
/* areadlink.c -- readlink wrapper to return the link name in malloc'd storage
|
||||
Unlike xreadlink and xreadlink_with_size, don't ever call exit.
|
||||
|
||||
Copyright (C) 2001, 2003-2007, 2009-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Jim Meyering <jim@meyering.net>
|
||||
and Bruno Haible <bruno@clisp.org>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "areadlink.h"
|
||||
|
||||
#include "careadlinkat.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Get the symbolic link value of FILENAME and put it into BUFFER, with
|
||||
size BUFFER_SIZE. This function acts like readlink but has
|
||||
readlinkat's signature. */
|
||||
static ssize_t
|
||||
careadlinkatcwd (int fd, char const *filename, char *buffer,
|
||||
size_t buffer_size)
|
||||
{
|
||||
/* FD must be AT_FDCWD here, otherwise the caller is using this
|
||||
function in contexts it was not meant for. */
|
||||
if (fd != AT_FDCWD)
|
||||
abort ();
|
||||
return readlink (filename, buffer, buffer_size);
|
||||
}
|
||||
|
||||
/* Call readlink to get the symbolic link value of FILENAME.
|
||||
Return a pointer to that NUL-terminated string in malloc'd storage.
|
||||
If readlink fails, return NULL and set errno.
|
||||
If allocation fails, or if the link value is longer than SIZE_MAX :-),
|
||||
return NULL and set errno to ENOMEM. */
|
||||
|
||||
char *
|
||||
areadlink (char const *filename)
|
||||
{
|
||||
return careadlinkat (AT_FDCWD, filename, NULL, 0, NULL, careadlinkatcwd);
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/* Binary mode I/O.
|
||||
Copyright 2017-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#define BINARY_IO_INLINE _GL_EXTERN_INLINE
|
||||
#include "binary-io.h"
|
||||
|
||||
#if defined __DJGPP__ || defined __EMX__
|
||||
# include <unistd.h>
|
||||
|
||||
int
|
||||
set_binary_mode (int fd, int mode)
|
||||
{
|
||||
if (isatty (fd))
|
||||
/* If FD refers to a console (not a pipe, not a regular file),
|
||||
O_TEXT is the only reasonable mode, both on input and on output.
|
||||
Silently ignore the request. If we were to return -1 here,
|
||||
all programs that use xset_binary_mode would fail when run
|
||||
with console input or console output. */
|
||||
return O_TEXT;
|
||||
else
|
||||
return __gl_setmode (fd, mode);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,184 +0,0 @@
|
||||
/* Read symbolic links into a buffer without size limitation, relative to fd.
|
||||
|
||||
Copyright (C) 2001, 2003-2004, 2007, 2009-2022 Free Software Foundation,
|
||||
Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "careadlinkat.h"
|
||||
|
||||
#include "idx.h"
|
||||
#include "minmax.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Define this independently so that stdint.h is not a prerequisite. */
|
||||
#ifndef SIZE_MAX
|
||||
# define SIZE_MAX ((size_t) -1)
|
||||
#endif
|
||||
|
||||
#ifndef SSIZE_MAX
|
||||
# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
|
||||
#endif
|
||||
|
||||
#include "allocator.h"
|
||||
|
||||
enum { STACK_BUF_SIZE = 1024 };
|
||||
|
||||
/* Act like careadlinkat (see below), with an additional argument
|
||||
STACK_BUF that can be used as temporary storage.
|
||||
|
||||
If GCC_LINT is defined, do not inline this function with GCC 10.1
|
||||
and later, to avoid creating a pointer to the stack that GCC
|
||||
-Wreturn-local-addr incorrectly complains about. See:
|
||||
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93644
|
||||
Although the noinline attribute can hurt performance a bit, no better way
|
||||
to pacify GCC is known; even an explicit #pragma does not pacify GCC.
|
||||
When the GCC bug is fixed this workaround should be limited to the
|
||||
broken GCC versions. */
|
||||
#if _GL_GNUC_PREREQ (10, 1)
|
||||
# if defined GCC_LINT || defined lint
|
||||
__attribute__ ((__noinline__))
|
||||
# elif __OPTIMIZE__ && !__NO_INLINE__
|
||||
# define GCC_BOGUS_WRETURN_LOCAL_ADDR
|
||||
# endif
|
||||
#endif
|
||||
static char *
|
||||
readlink_stk (int fd, char const *filename,
|
||||
char *buffer, size_t buffer_size,
|
||||
struct allocator const *alloc,
|
||||
ssize_t (*preadlinkat) (int, char const *, char *, size_t),
|
||||
char stack_buf[STACK_BUF_SIZE])
|
||||
{
|
||||
if (! alloc)
|
||||
alloc = &stdlib_allocator;
|
||||
|
||||
if (!buffer)
|
||||
{
|
||||
buffer = stack_buf;
|
||||
buffer_size = STACK_BUF_SIZE;
|
||||
}
|
||||
|
||||
char *buf = buffer;
|
||||
idx_t buf_size_max = MIN (IDX_MAX, MIN (SSIZE_MAX, SIZE_MAX));
|
||||
idx_t buf_size = MIN (buffer_size, buf_size_max);
|
||||
|
||||
while (buf)
|
||||
{
|
||||
/* Attempt to read the link into the current buffer. */
|
||||
idx_t link_length = preadlinkat (fd, filename, buf, buf_size);
|
||||
if (link_length < 0)
|
||||
{
|
||||
if (buf != buffer)
|
||||
{
|
||||
int readlinkat_errno = errno;
|
||||
alloc->free (buf);
|
||||
errno = readlinkat_errno;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
idx_t link_size = link_length;
|
||||
|
||||
if (link_size < buf_size)
|
||||
{
|
||||
buf[link_size++] = '\0';
|
||||
|
||||
if (buf == stack_buf)
|
||||
{
|
||||
char *b = alloc->allocate (link_size);
|
||||
buf_size = link_size;
|
||||
if (! b)
|
||||
break;
|
||||
return memcpy (b, buf, link_size);
|
||||
}
|
||||
|
||||
if (link_size < buf_size && buf != buffer && alloc->reallocate)
|
||||
{
|
||||
/* Shrink BUF before returning it. */
|
||||
char *b = alloc->reallocate (buf, link_size);
|
||||
if (b)
|
||||
return b;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
if (buf != buffer)
|
||||
alloc->free (buf);
|
||||
|
||||
if (buf_size_max / 2 <= buf_size)
|
||||
{
|
||||
errno = ENAMETOOLONG;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buf_size = 2 * buf_size + 1;
|
||||
buf = alloc->allocate (buf_size);
|
||||
}
|
||||
|
||||
if (alloc->die)
|
||||
alloc->die (buf_size);
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* Assuming the current directory is FD, get the symbolic link value
|
||||
of FILENAME as a null-terminated string and put it into a buffer.
|
||||
If FD is AT_FDCWD, FILENAME is interpreted relative to the current
|
||||
working directory, as in openat.
|
||||
|
||||
If the link is small enough to fit into BUFFER put it there.
|
||||
BUFFER's size is BUFFER_SIZE, and BUFFER can be null
|
||||
if BUFFER_SIZE is zero.
|
||||
|
||||
If the link is not small, put it into a dynamically allocated
|
||||
buffer managed by ALLOC. It is the caller's responsibility to free
|
||||
the returned value if it is nonnull and is not BUFFER. A null
|
||||
ALLOC stands for the standard allocator.
|
||||
|
||||
The PREADLINKAT function specifies how to read links. It operates
|
||||
like POSIX readlinkat()
|
||||
<https://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html>
|
||||
but can assume that its first argument is the same as FD.
|
||||
|
||||
If successful, return the buffer address; otherwise return NULL and
|
||||
set errno. */
|
||||
|
||||
char *
|
||||
careadlinkat (int fd, char const *filename,
|
||||
char *buffer, size_t buffer_size,
|
||||
struct allocator const *alloc,
|
||||
ssize_t (*preadlinkat) (int, char const *, char *, size_t))
|
||||
{
|
||||
/* Allocate the initial buffer on the stack. This way, in the
|
||||
common case of a symlink of small size, we get away with a
|
||||
single small malloc instead of a big malloc followed by a
|
||||
shrinking realloc. */
|
||||
#ifdef GCC_BOGUS_WRETURN_LOCAL_ADDR
|
||||
#warning "GCC might issue a bogus -Wreturn-local-addr warning here."
|
||||
#warning "See <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93644>."
|
||||
#endif
|
||||
char stack_buf[STACK_BUF_SIZE];
|
||||
return readlink_stk (fd, filename, buffer, buffer_size, alloc,
|
||||
preadlinkat, stack_buf);
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
/* Hook for making file descriptor functions close(), ioctl() extensible.
|
||||
Copyright (C) 2009-2022 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2009.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "fd-hook.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/* Currently, this entire code is only needed for the handling of sockets
|
||||
on native Windows platforms. */
|
||||
#if WINDOWS_SOCKETS
|
||||
|
||||
/* The first and last link in the doubly linked list.
|
||||
Initially the list is empty. */
|
||||
static struct fd_hook anchor = { &anchor, &anchor, NULL, NULL };
|
||||
|
||||
int
|
||||
execute_close_hooks (const struct fd_hook *remaining_list, gl_close_fn primary,
|
||||
int fd)
|
||||
{
|
||||
if (remaining_list == &anchor)
|
||||
/* End of list reached. */
|
||||
return primary (fd);
|
||||
else
|
||||
return remaining_list->private_close_fn (remaining_list->private_next,
|
||||
primary, fd);
|
||||
}
|
||||
|
||||
int
|
||||
execute_all_close_hooks (gl_close_fn primary, int fd)
|
||||
{
|
||||
return execute_close_hooks (anchor.private_next, primary, fd);
|
||||
}
|
||||
|
||||
int
|
||||
execute_ioctl_hooks (const struct fd_hook *remaining_list, gl_ioctl_fn primary,
|
||||
int fd, int request, void *arg)
|
||||
{
|
||||
if (remaining_list == &anchor)
|
||||
/* End of list reached. */
|
||||
return primary (fd, request, arg);
|
||||
else
|
||||
return remaining_list->private_ioctl_fn (remaining_list->private_next,
|
||||
primary, fd, request, arg);
|
||||
}
|
||||
|
||||
int
|
||||
execute_all_ioctl_hooks (gl_ioctl_fn primary,
|
||||
int fd, int request, void *arg)
|
||||
{
|
||||
return execute_ioctl_hooks (anchor.private_next, primary, fd, request, arg);
|
||||
}
|
||||
|
||||
void
|
||||
register_fd_hook (close_hook_fn close_hook, ioctl_hook_fn ioctl_hook, struct fd_hook *link)
|
||||
{
|
||||
if (close_hook == NULL)
|
||||
close_hook = execute_close_hooks;
|
||||
if (ioctl_hook == NULL)
|
||||
ioctl_hook = execute_ioctl_hooks;
|
||||
|
||||
if (link->private_next == NULL && link->private_prev == NULL)
|
||||
{
|
||||
/* Add the link to the doubly linked list. */
|
||||
link->private_next = anchor.private_next;
|
||||
link->private_prev = &anchor;
|
||||
link->private_close_fn = close_hook;
|
||||
link->private_ioctl_fn = ioctl_hook;
|
||||
anchor.private_next->private_prev = link;
|
||||
anchor.private_next = link;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The link is already in use. */
|
||||
if (link->private_close_fn != close_hook
|
||||
|| link->private_ioctl_fn != ioctl_hook)
|
||||
abort ();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
unregister_fd_hook (struct fd_hook *link)
|
||||
{
|
||||
struct fd_hook *next = link->private_next;
|
||||
struct fd_hook *prev = link->private_prev;
|
||||
|
||||
if (next != NULL && prev != NULL)
|
||||
{
|
||||
/* The link is in use. Remove it from the doubly linked list. */
|
||||
prev->private_next = next;
|
||||
next->private_prev = prev;
|
||||
/* Clear the link, to mark it unused. */
|
||||
link->private_next = NULL;
|
||||
link->private_prev = NULL;
|
||||
link->private_close_fn = NULL;
|
||||
link->private_ioctl_fn = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,302 +0,0 @@
|
||||
/* Program name management.
|
||||
Copyright (C) 2016-2022 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "getprogname.h"
|
||||
|
||||
#include <errno.h> /* get program_invocation_name declaration */
|
||||
#include <stdlib.h> /* get __argv declaration */
|
||||
|
||||
#ifdef _AIX
|
||||
# include <unistd.h>
|
||||
# include <procinfo.h>
|
||||
# include <string.h>
|
||||
#endif
|
||||
|
||||
#ifdef __MVS__
|
||||
# ifndef _OPEN_SYS
|
||||
# define _OPEN_SYS
|
||||
# endif
|
||||
# include <string.h>
|
||||
# include <sys/ps.h>
|
||||
#endif
|
||||
|
||||
#ifdef __hpux
|
||||
# include <unistd.h>
|
||||
# include <sys/param.h>
|
||||
# include <sys/pstat.h>
|
||||
# include <string.h>
|
||||
#endif
|
||||
|
||||
#if defined __sgi || defined __osf__
|
||||
# include <string.h>
|
||||
# include <unistd.h>
|
||||
# include <stdio.h>
|
||||
# include <fcntl.h>
|
||||
# include <sys/procfs.h>
|
||||
#endif
|
||||
|
||||
#if defined __SCO_VERSION__ || defined __sysv5__
|
||||
# include <fcntl.h>
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
#endif
|
||||
|
||||
#include "basename-lgpl.h"
|
||||
|
||||
#ifndef HAVE_GETPROGNAME /* not Mac OS X, FreeBSD, NetBSD, OpenBSD >= 5.4, Cygwin */
|
||||
char const *
|
||||
getprogname (void)
|
||||
{
|
||||
# if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME /* glibc, BeOS */
|
||||
/* https://www.gnu.org/software/libc/manual/html_node/Error-Messages.html */
|
||||
return program_invocation_short_name;
|
||||
# elif HAVE_DECL_PROGRAM_INVOCATION_NAME /* glibc, BeOS */
|
||||
/* https://www.gnu.org/software/libc/manual/html_node/Error-Messages.html */
|
||||
return last_component (program_invocation_name);
|
||||
# elif HAVE_GETEXECNAME /* Solaris */
|
||||
/* https://docs.oracle.com/cd/E19253-01/816-5168/6mbb3hrb1/index.html */
|
||||
const char *p = getexecname ();
|
||||
if (!p)
|
||||
p = "?";
|
||||
return last_component (p);
|
||||
# elif HAVE_DECL___ARGV /* mingw, MSVC */
|
||||
/* https://docs.microsoft.com/en-us/cpp/c-runtime-library/argc-argv-wargv */
|
||||
const char *p = __argv && __argv[0] ? __argv[0] : "?";
|
||||
return last_component (p);
|
||||
# elif HAVE_VAR___PROGNAME /* OpenBSD, Android, QNX */
|
||||
/* https://man.openbsd.org/style.9 */
|
||||
/* http://www.qnx.de/developers/docs/6.5.0/index.jsp?topic=%2Fcom.qnx.doc.neutrino_lib_ref%2Fp%2F__progname.html */
|
||||
/* Be careful to declare this only when we absolutely need it
|
||||
(OpenBSD 5.1), rather than when it's available. Otherwise,
|
||||
its mere declaration makes program_invocation_short_name
|
||||
malfunction (have zero length) with Fedora 25's glibc. */
|
||||
extern char *__progname;
|
||||
const char *p = __progname;
|
||||
# if defined __ANDROID__
|
||||
return last_component (p);
|
||||
# else
|
||||
return p && p[0] ? p : "?";
|
||||
# endif
|
||||
# elif _AIX /* AIX */
|
||||
/* Idea by Bastien ROUCARIÈS,
|
||||
https://lists.gnu.org/r/bug-gnulib/2010-12/msg00095.html
|
||||
Reference: https://www.ibm.com/support/knowledgecenter/en/ssw_aix_61/com.ibm.aix.basetrf1/getprocs.htm
|
||||
*/
|
||||
static char *p;
|
||||
static int first = 1;
|
||||
if (first)
|
||||
{
|
||||
first = 0;
|
||||
pid_t pid = getpid ();
|
||||
struct procentry64 procs;
|
||||
p = (0 < getprocs64 (&procs, sizeof procs, NULL, 0, &pid, 1)
|
||||
? strdup (procs.pi_comm)
|
||||
: NULL);
|
||||
if (!p)
|
||||
p = "?";
|
||||
}
|
||||
return p;
|
||||
# elif defined __hpux
|
||||
static char *p;
|
||||
static int first = 1;
|
||||
if (first)
|
||||
{
|
||||
first = 0;
|
||||
pid_t pid = getpid ();
|
||||
struct pst_status status;
|
||||
if (pstat_getproc (&status, sizeof status, 0, pid) > 0)
|
||||
{
|
||||
char *ucomm = status.pst_ucomm;
|
||||
char *cmd = status.pst_cmd;
|
||||
if (strlen (ucomm) < PST_UCOMMLEN - 1)
|
||||
p = ucomm;
|
||||
else
|
||||
{
|
||||
/* ucomm is truncated to length PST_UCOMMLEN - 1.
|
||||
Look at cmd instead. */
|
||||
char *space = strchr (cmd, ' ');
|
||||
if (space != NULL)
|
||||
*space = '\0';
|
||||
p = strrchr (cmd, '/');
|
||||
if (p != NULL)
|
||||
p++;
|
||||
else
|
||||
p = cmd;
|
||||
if (strlen (p) > PST_UCOMMLEN - 1
|
||||
&& memcmp (p, ucomm, PST_UCOMMLEN - 1) == 0)
|
||||
/* p is less truncated than ucomm. */
|
||||
;
|
||||
else
|
||||
p = ucomm;
|
||||
}
|
||||
p = strdup (p);
|
||||
}
|
||||
else
|
||||
{
|
||||
# if !defined __LP64__
|
||||
/* Support for 32-bit programs running in 64-bit HP-UX.
|
||||
The documented way to do this is to use the same source code
|
||||
as above, but in a compilation unit where '#define _PSTAT64 1'
|
||||
is in effect. I prefer a single compilation unit; the struct
|
||||
size and the offsets are not going to change. */
|
||||
char status64[1216];
|
||||
if (__pstat_getproc64 (status64, sizeof status64, 0, pid) > 0)
|
||||
{
|
||||
char *ucomm = status64 + 288;
|
||||
char *cmd = status64 + 168;
|
||||
if (strlen (ucomm) < PST_UCOMMLEN - 1)
|
||||
p = ucomm;
|
||||
else
|
||||
{
|
||||
/* ucomm is truncated to length PST_UCOMMLEN - 1.
|
||||
Look at cmd instead. */
|
||||
char *space = strchr (cmd, ' ');
|
||||
if (space != NULL)
|
||||
*space = '\0';
|
||||
p = strrchr (cmd, '/');
|
||||
if (p != NULL)
|
||||
p++;
|
||||
else
|
||||
p = cmd;
|
||||
if (strlen (p) > PST_UCOMMLEN - 1
|
||||
&& memcmp (p, ucomm, PST_UCOMMLEN - 1) == 0)
|
||||
/* p is less truncated than ucomm. */
|
||||
;
|
||||
else
|
||||
p = ucomm;
|
||||
}
|
||||
p = strdup (p);
|
||||
}
|
||||
else
|
||||
# endif
|
||||
p = NULL;
|
||||
}
|
||||
if (!p)
|
||||
p = "?";
|
||||
}
|
||||
return p;
|
||||
# elif __MVS__ /* z/OS */
|
||||
/* https://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/com.ibm.zos.v2r1.bpxbd00/rtwgetp.htm */
|
||||
static char *p = "?";
|
||||
static int first = 1;
|
||||
if (first)
|
||||
{
|
||||
pid_t pid = getpid ();
|
||||
int token;
|
||||
W_PSPROC buf;
|
||||
first = 0;
|
||||
memset (&buf, 0, sizeof(buf));
|
||||
buf.ps_cmdptr = (char *) malloc (buf.ps_cmdlen = PS_CMDBLEN_LONG);
|
||||
buf.ps_conttyptr = (char *) malloc (buf.ps_conttylen = PS_CONTTYBLEN);
|
||||
buf.ps_pathptr = (char *) malloc (buf.ps_pathlen = PS_PATHBLEN);
|
||||
if (buf.ps_cmdptr && buf.ps_conttyptr && buf.ps_pathptr)
|
||||
{
|
||||
for (token = 0; token >= 0;
|
||||
token = w_getpsent (token, &buf, sizeof(buf)))
|
||||
{
|
||||
if (token > 0 && buf.ps_pid == pid)
|
||||
{
|
||||
char *s = strdup (last_component (buf.ps_pathptr));
|
||||
if (s)
|
||||
p = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
free (buf.ps_cmdptr);
|
||||
free (buf.ps_conttyptr);
|
||||
free (buf.ps_pathptr);
|
||||
}
|
||||
return p;
|
||||
# elif defined __sgi || defined __osf__ /* IRIX or Tru64 */
|
||||
char filename[50];
|
||||
int fd;
|
||||
|
||||
# if defined __sgi
|
||||
sprintf (filename, "/proc/pinfo/%d", (int) getpid ());
|
||||
# else
|
||||
sprintf (filename, "/proc/%d", (int) getpid ());
|
||||
# endif
|
||||
fd = open (filename, O_RDONLY | O_CLOEXEC);
|
||||
if (0 <= fd)
|
||||
{
|
||||
prpsinfo_t buf;
|
||||
int ioctl_ok = 0 <= ioctl (fd, PIOCPSINFO, &buf);
|
||||
close (fd);
|
||||
if (ioctl_ok)
|
||||
{
|
||||
char *name = buf.pr_fname;
|
||||
size_t namesize = sizeof buf.pr_fname;
|
||||
/* It may not be NUL-terminated. */
|
||||
char *namenul = memchr (name, '\0', namesize);
|
||||
size_t namelen = namenul ? namenul - name : namesize;
|
||||
char *namecopy = malloc (namelen + 1);
|
||||
if (namecopy)
|
||||
{
|
||||
namecopy[namelen] = '\0';
|
||||
return memcpy (namecopy, name, namelen);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
# elif defined __SCO_VERSION__ || defined __sysv5__ /* SCO OpenServer6/UnixWare */
|
||||
char buf[80];
|
||||
int fd;
|
||||
sprintf (buf, "/proc/%d/cmdline", getpid());
|
||||
fd = open (buf, O_RDONLY);
|
||||
if (0 <= fd)
|
||||
{
|
||||
size_t n = read (fd, buf, 79);
|
||||
if (n > 0)
|
||||
{
|
||||
buf[n] = '\0'; /* Guarantee null-termination */
|
||||
char *progname;
|
||||
progname = strrchr (buf, '/');
|
||||
if (progname)
|
||||
{
|
||||
progname = progname + 1; /* Skip the '/' */
|
||||
}
|
||||
else
|
||||
{
|
||||
progname = buf;
|
||||
}
|
||||
char *ret;
|
||||
ret = malloc (strlen (progname) + 1);
|
||||
if (ret)
|
||||
{
|
||||
strcpy (ret, progname);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
close (fd);
|
||||
}
|
||||
return "?";
|
||||
# else
|
||||
# error "getprogname module not ported to this OS"
|
||||
# endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Hey Emacs!
|
||||
* Local Variables:
|
||||
* coding: utf-8
|
||||
* End:
|
||||
*/
|
||||
@@ -1,22 +0,0 @@
|
||||
/* Inline functions for <unistd.h>.
|
||||
|
||||
Copyright (C) 2012-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#define _GL_UNISTD_INLINE _GL_EXTERN_INLINE
|
||||
#include "unistd.h"
|
||||
typedef int dummy;
|
||||
@@ -1,44 +0,0 @@
|
||||
/* xreadlink.c -- readlink wrapper to return the link name in malloc'd storage
|
||||
|
||||
Copyright (C) 2001, 2003-2007, 2009-2022 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Written by Jim Meyering <jim@meyering.net>
|
||||
and Bruno Haible <bruno@clisp.org>. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
/* Specification. */
|
||||
#include "xreadlink.h"
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "areadlink.h"
|
||||
#include "xalloc.h"
|
||||
|
||||
/* Call readlink to get the symbolic link value of FILENAME.
|
||||
Return a pointer to that NUL-terminated string in malloc'd storage.
|
||||
If readlink fails, return NULL and set errno.
|
||||
If realloc fails, or if the link value is longer than SIZE_MAX :-),
|
||||
give a diagnostic and exit. */
|
||||
|
||||
char *
|
||||
xreadlink (char const *filename)
|
||||
{
|
||||
char *result = areadlink (filename);
|
||||
if (result == NULL && errno == ENOMEM)
|
||||
xalloc_die ();
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user