mcst-linux-kernel/patches-2024.06.26/zsh-5.9/0001-Patch-from-previous-ve...

363 lines
8.9 KiB
Diff

--- a/Src/compat.c 2023-03-17 13:39:29.094572979 +0300
+++ b/Src/compat.c 2023-03-17 15:27:00.226706517 +0300
@@ -27,6 +27,7 @@
*
*/
+#include <stdlib.h>
#include "zsh.mdh"
#include "compat.pro"
@@ -63,6 +64,7 @@
int
gethostname(char *name, size_t namelen)
{
+ /*
struct utsname uts;
uname(&uts);
@@ -71,6 +73,16 @@
return -1;
}
strcpy(name, uts.nodename);
+ */
+ char *str;
+ if (((str = getenv("HOST")) == NULL) && ((str = getenv("HOSTNAME")) == NULL))
+ str = name;
+ if(strlen(str) >= namelen) {
+ errno = EINVAL;
+ return -1;
+ }
+ strcpy(name, str);
+
return 0;
}
@@ -278,38 +290,36 @@
*
* Neither of these should happen, but resort to OPEN_MAX rather
* than return 0 or -1 just in case.
- *
- * We'll limit the open maximum to ZSH_INITIAL_OPEN_MAX to
- * avoid probing ridiculous numbers of file descriptors.
*/
/**/
mod_export long
zopenmax(void)
{
- long openmax;
+ static long openmax = 0;
+
+ if (openmax < 1) {
+ if ((openmax = sysconf(_SC_OPEN_MAX)) < 1) {
+ openmax = OPEN_MAX;
+ } else if (openmax > OPEN_MAX) {
+ /* On some systems, "limit descriptors unlimited" or the *
+ * equivalent will set openmax to a huge number. Unless *
+ * there actually is a file descriptor > OPEN_MAX already *
+ * open, nothing in zsh requires the true maximum, and in *
+ * fact it causes inefficiency elsewhere if we report it. *
+ * So, report the maximum of OPEN_MAX or the largest open *
+ * descriptor (is there a better way to find that?). */
+ long i, j = OPEN_MAX;
+ for (i = j; i < openmax; i += (errno != EINTR)) {
+ errno = 0;
+ if (fcntl(i, F_GETFL, 0) < 0 &&
+ (errno == EBADF || errno == EINTR))
+ continue;
+ j = i;
+ }
+ openmax = j;
+ }
- if ((openmax = sysconf(_SC_OPEN_MAX)) < 1) {
- openmax = OPEN_MAX;
- } else if (openmax > OPEN_MAX) {
- /* On some systems, "limit descriptors unlimited" or the *
- * equivalent will set openmax to a huge number. Unless *
- * there actually is a file descriptor > OPEN_MAX already *
- * open, nothing in zsh requires the true maximum, and in *
- * fact it causes inefficiency elsewhere if we report it. *
- * So, report the maximum of OPEN_MAX or the largest open *
- * descriptor (is there a better way to find that?). */
- long i, j = OPEN_MAX;
- if (openmax > ZSH_INITIAL_OPEN_MAX)
- openmax = ZSH_INITIAL_OPEN_MAX;
- for (i = j; i < openmax; i += (errno != EINTR)) {
- errno = 0;
- if (fcntl(i, F_GETFL, 0) < 0 &&
- (errno == EBADF || errno == EINTR))
- continue;
- j = i;
- }
- openmax = j;
}
return (max_zsh_fd > openmax) ? max_zsh_fd : openmax;
@@ -318,26 +328,6 @@
/**/
#endif
-/*
- * Rationalise the current directory, returning the string.
- *
- * If "d" is not NULL, it is used to store information about the
- * directory. The returned name is also present in d->dirname and is in
- * permanently allocated memory. The handling of this case depends on
- * whether the fchdir() system call is available; if it is, it is assumed
- * the caller is able to restore the current directory. On successfully
- * identifying the directory the function returns immediately rather
- * than ascending the hierarchy.
- *
- * If "d" is NULL, no assumption about the caller's behaviour is
- * made. The returned string is in heap memory. This case is
- * always handled by changing directory up the hierarchy.
- *
- * On Cygwin or other systems where USE_GETCWD is defined (at the
- * time of writing only QNX), we skip all the above and use the
- * getcwd() system call.
- */
-
/**/
mod_export char *
zgetdir(struct dirsav *d)
@@ -361,18 +351,21 @@
buf[pos] = '\0';
strcpy(nbuf, "../");
if (stat(".", &sbuf) < 0) {
- return NULL;
+ if (d)
+ return NULL;
+ buf[0] = '.';
+ buf[1] = '\0';
+ return buf;
}
- /* Record the initial inode and device */
pino = sbuf.st_ino;
pdev = sbuf.st_dev;
if (d)
- d->ino = pino, d->dev = pdev;
-#if !defined(__CYGWIN__) && !defined(USE_GETCWD)
+ d->ino = pino, d->dev = pdev;
#ifdef HAVE_FCHDIR
else
#endif
+#if !defined(__CYGWIN__) && !defined(USE_GETCWD)
holdintr();
for (;;) {
@@ -476,14 +469,14 @@
*/
if (d) {
#ifndef HAVE_FCHDIR
- if (buf[pos])
+ if (*buf)
zchdir(buf + pos + 1);
noholdintr();
#endif
return NULL;
}
- if (buf[pos])
+ if (*buf)
zchdir(buf + pos + 1);
noholdintr();
@@ -511,7 +504,9 @@
* We only get here from zgetcwd(); let that fall back to pwd.
*/
- return NULL;
+ buf[0] = '.';
+ buf[1] = '\0';
+ return buf;
}
/*
@@ -525,29 +520,7 @@
mod_export char *
zgetcwd(void)
{
- char *ret = zgetdir(NULL);
-#ifdef HAVE_GETCWD
- if (!ret) {
-#ifdef GETCWD_CALLS_MALLOC
- char *cwd = getcwd(NULL, 0);
- if (cwd) {
- ret = dupstring(cwd);
- free(cwd);
- }
-#else
- char *cwdbuf = zalloc(PATH_MAX+1);
- ret = getcwd(cwdbuf, PATH_MAX);
- if (ret)
- ret = dupstring(ret);
- zfree(cwdbuf, PATH_MAX+1);
-#endif /* GETCWD_CALLS_MALLOC */
- }
-#endif /* HAVE_GETCWD */
- if (!ret)
- ret = unmeta(pwd);
- if (!ret || *ret == '\0')
- ret = dupstring(".");
- return ret;
+ return zgetdir(NULL);
}
/*
@@ -627,152 +600,3 @@
}
/**/
#endif /* ZSH_64_BIT_TYPE */
-
-/**/
-#ifndef HAVE_STRTOUL
-
-/*
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * 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 of the University 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 REGENTS 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 REGENTS 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.
- */
-
-/*
- * Convert a string to an unsigned long integer.
- *
- * Ignores `locale' stuff. Assumes that the upper and lower case
- * alphabets and digits are each contiguous.
- */
-
-/**/
-unsigned long
-strtoul(nptr, endptr, base)
- const char *nptr;
- char **endptr;
- int base;
-{
- const char *s;
- unsigned long acc, cutoff;
- int c;
- int neg, any, cutlim;
-
- /* endptr may be NULL */
-
- s = nptr;
- do {
- c = (unsigned char) *s++;
- } while (isspace(c));
- if (c == '-') {
- neg = 1;
- c = *s++;
- } else {
- neg = 0;
- if (c == '+')
- c = *s++;
- }
- if ((base == 0 || base == 16) &&
- c == '0' && (*s == 'x' || *s == 'X')) {
- c = s[1];
- s += 2;
- base = 16;
- }
- if (base == 0)
- base = c == '0' ? 8 : 10;
-
- cutoff = ULONG_MAX / (unsigned long)base;
- cutlim = (int)(ULONG_MAX % (unsigned long)base);
- for (acc = 0, any = 0;; c = (unsigned char) *s++) {
- if (isdigit(c))
- c -= '0';
- else if (isalpha(c)) {
- c -= isupper(c) ? 'A' - 10 : 'a' - 10;
- } else
- break;
- if (c >= base)
- break;
- if (any < 0)
- continue;
- if (acc > cutoff || (acc == cutoff && c > cutlim)) {
- any = -1;
- acc = ULONG_MAX;
- errno = ERANGE;
- } else {
- any = 1;
- acc *= (unsigned long)base;
- acc += c;
- }
- }
- if (neg && any > 0)
- acc = -acc;
- if (endptr != NULL)
- *endptr = any ? s - 1 : nptr;
- return (acc);
-}
-
-/**/
-#endif /* HAVE_STRTOUL */
-
-/**/
-#ifdef ENABLE_UNICODE9
-#include "./wcwidth9.h"
-
-/**/
-int
-u9_wcwidth(wchar_t ucs)
-{
- int w = wcwidth9(ucs);
- if (w < -1)
- return 1;
- return w;
-}
-
-/**/
-int
-u9_iswprint(wint_t ucs)
-{
- if (ucs == 0)
- return 0;
- return wcwidth9(ucs) != -1;
-}
-
-/**/
-#endif /* ENABLE_UNICODE9 */
-
-/**/
-#if defined(__APPLE__) && defined(BROKEN_ISPRINT)
-
-/**/
-int
-isprint_ascii(int c)
-{
- if (!strcmp(nl_langinfo(CODESET), "UTF-8"))
- return (c >= 0x20 && c <= 0x7e);
- else
- return isprint(c);
-}
-
-/**/
-#endif /* __APPLE__ && BROKEN_ISPRINT */