mirror of
https://github.com/termux/termux-packages.git
synced 2024-12-04 18:45:52 +00:00
127 lines
3.4 KiB
Diff
127 lines
3.4 KiB
Diff
--- a/file.c
|
|
+++ b/file.c
|
|
@@ -30,6 +30,10 @@
|
|
* SUCH DAMAGE.
|
|
*/
|
|
|
|
+#ifdef BIONIC
|
|
+#define MAXNAMLEN 1024
|
|
+#endif
|
|
+
|
|
#ifdef FILEC
|
|
|
|
#include <sys/param.h>
|
|
@@ -82,7 +86,7 @@
|
|
static void beep(void);
|
|
static void print_recognized_stuff(Char *);
|
|
static void extract_dir_and_name(Char *, Char *, Char *);
|
|
-static Char *getentry(DIR *, int);
|
|
+static Char *getentry(DIR *);
|
|
static void free_items(Char **, int);
|
|
static int tsearch(Char *, COMMAND, int);
|
|
static int recognize(Char *, Char *, int, int);
|
|
@@ -373,16 +377,10 @@
|
|
}
|
|
|
|
static Char *
|
|
-getentry(DIR *dir_fd, int looking_for_lognames)
|
|
+getentry(DIR *dir_fd)
|
|
{
|
|
- struct passwd *pw;
|
|
struct dirent *dirp;
|
|
|
|
- if (looking_for_lognames) {
|
|
- if ((pw = getpwent()) == NULL)
|
|
- return (NULL);
|
|
- return (str2short(pw->pw_name));
|
|
- }
|
|
if ((dirp = readdir(dir_fd)) != NULL)
|
|
return (str2short(dirp->d_name));
|
|
return (NULL);
|
|
@@ -416,36 +414,27 @@
|
|
{
|
|
DIR *dir_fd;
|
|
int numitems = 0, ignoring = TRUE, nignored = 0;
|
|
- int name_length, looking_for_lognames;
|
|
+ int name_length;
|
|
Char tilded_dir[MAXPATHLEN], dir[MAXPATHLEN];
|
|
Char name[MAXNAMLEN + 1], extended_name[MAXNAMLEN + 1];
|
|
Char *entry;
|
|
Char **items = NULL;
|
|
size_t maxitems = 0;
|
|
|
|
- looking_for_lognames = (*word == '~') && (Strchr(word, '/') == NULL);
|
|
- if (looking_for_lognames) {
|
|
- (void) setpwent();
|
|
- copyn(name, &word[1], MAXNAMLEN); /* name sans ~ */
|
|
- dir_fd = NULL;
|
|
- }
|
|
- else {
|
|
- extract_dir_and_name(word, dir, name);
|
|
- if (tilde(tilded_dir, dir) == 0)
|
|
- return (0);
|
|
- dir_fd = opendir(*tilded_dir ? short2str(tilded_dir) : ".");
|
|
- if (dir_fd == NULL)
|
|
- return (0);
|
|
- }
|
|
+ extract_dir_and_name(word, dir, name);
|
|
+ if (tilde(tilded_dir, dir) == 0)
|
|
+ return (0);
|
|
+ dir_fd = opendir(*tilded_dir ? short2str(tilded_dir) : ".");
|
|
+ if (dir_fd == NULL)
|
|
+ return (0);
|
|
|
|
again: /* search for matches */
|
|
name_length = Strlen(name);
|
|
- for (numitems = 0; (entry = getentry(dir_fd, looking_for_lognames)) != NULL;) {
|
|
+ for (numitems = 0; (entry = getentry(dir_fd)) != NULL;) {
|
|
if (!is_prefix(name, entry))
|
|
continue;
|
|
/* Don't match . files on null prefix match */
|
|
- if (name_length == 0 && entry[0] == '.' &&
|
|
- !looking_for_lognames)
|
|
+ if (name_length == 0 && entry[0] == '.')
|
|
continue;
|
|
if (command == LIST) {
|
|
if (numitems >= maxitems) {
|
|
@@ -472,25 +461,16 @@
|
|
if (ignoring && numitems == 0 && nignored > 0) {
|
|
ignoring = FALSE;
|
|
nignored = 0;
|
|
- if (looking_for_lognames)
|
|
- (void) setpwent();
|
|
- else
|
|
- rewinddir(dir_fd);
|
|
+ rewinddir(dir_fd);
|
|
goto again;
|
|
}
|
|
|
|
- if (looking_for_lognames)
|
|
- (void) endpwent();
|
|
- else
|
|
- (void) closedir(dir_fd);
|
|
+ (void) closedir(dir_fd);
|
|
if (numitems == 0)
|
|
return (0);
|
|
if (command == RECOGNIZE) {
|
|
- if (looking_for_lognames)
|
|
- copyn(word, STRtilde, 1);
|
|
- else
|
|
- /* put back dir part */
|
|
- copyn(word, dir, max_word_length);
|
|
+ /* put back dir part */
|
|
+ copyn(word, dir, max_word_length);
|
|
/* add extended name */
|
|
catn(word, extended_name, max_word_length);
|
|
return (numitems);
|
|
@@ -498,8 +478,7 @@
|
|
else { /* LIST */
|
|
qsort((ptr_t) items, numitems, sizeof(*items),
|
|
(int (*)(const void *, const void *)) sortscmp);
|
|
- print_by_column(looking_for_lognames ? NULL : tilded_dir,
|
|
- items, numitems);
|
|
+ print_by_column(tilded_dir, items, numitems);
|
|
if (items != NULL)
|
|
FREE_ITEMS(items);
|
|
}
|