which/0001-which-fails-for-long-path.patch
2024-04-30 14:25:06 +08:00

60 lines
1.4 KiB
Diff

From 77420bf2e35444f348b19e0acaf1f77bb4ed3f76 Mon Sep 17 00:00:00 2001
From: fandeyuan <fandeyuan@kylinos.cn>
Date: Tue, 30 Apr 2024 14:18:20 +0800
Subject: [PATCH] which fails for long path
---
which.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/which.c b/which.c
index 1606052..525c0d0 100644
--- a/which.c
+++ b/which.c
@@ -19,10 +19,15 @@
#include "sys.h"
#include <stdio.h>
#include <ctype.h>
+#include <limits.h>
#include "getopt.h"
#include "tilde/tilde.h"
#include "bash.h"
+#ifndef PATH_MAX
+#define PATH_MAX 4096
+#endif
+
static const char *progname;
static void print_usage(FILE *out)
@@ -63,7 +68,7 @@ static void print_fail(const char *name, const char *path_list)
fprintf(stderr, "%s: no %s in (%s)\n", progname, name, path_list);
}
-static char home[256];
+static char home[PATH_MAX];
static size_t homelen = 0;
static int absolute_path_given;
@@ -162,7 +167,7 @@ static char *find_command_in_path(const char *name, const char *path_list, int *
return (found);
}
-static char cwd[256];
+static char cwd[PATH_MAX];
static size_t cwdlen;
static void get_current_working_directory(void)
@@ -194,7 +199,7 @@ static void get_current_working_directory(void)
static char *path_clean_up(const char *path)
{
- static char result[256];
+ static char result[PATH_MAX];
const char *p1 = path;
char *p2 = result;
--
2.33.0