(_rl_read_file): Use O_BINARY in open. Enable the test for incomplete
read. Strip the CR characters by hand after readin the file. (rl_read_init_file): Allow for ~/_intputrc on 8+3 filesystems.
This commit is contained in:
parent
511fec4d92
commit
a27688aa9f
|
@ -62,6 +62,10 @@ extern int errno;
|
||||||
extern char *strchr (), *strrchr ();
|
extern char *strchr (), *strrchr ();
|
||||||
#endif /* !strchr && !__STDC__ */
|
#endif /* !strchr && !__STDC__ */
|
||||||
|
|
||||||
|
#ifndef O_BINARY
|
||||||
|
# define O_BINARY 0
|
||||||
|
#endif
|
||||||
|
|
||||||
extern int _rl_horizontal_scroll_mode;
|
extern int _rl_horizontal_scroll_mode;
|
||||||
extern int _rl_mark_modified_lines;
|
extern int _rl_mark_modified_lines;
|
||||||
extern int _rl_bell_preference;
|
extern int _rl_bell_preference;
|
||||||
|
@ -646,7 +650,7 @@ _rl_read_file (filename, sizep)
|
||||||
char *buffer;
|
char *buffer;
|
||||||
int i, file;
|
int i, file;
|
||||||
|
|
||||||
if ((stat (filename, &finfo) < 0) || (file = open (filename, O_RDONLY, 0666)) < 0)
|
if ((stat (filename, &finfo) < 0) || (file = open (filename, O_RDONLY | O_BINARY, 0666)) < 0)
|
||||||
return ((char *)NULL);
|
return ((char *)NULL);
|
||||||
|
|
||||||
file_size = (size_t)finfo.st_size;
|
file_size = (size_t)finfo.st_size;
|
||||||
|
@ -667,7 +671,7 @@ _rl_read_file (filename, sizep)
|
||||||
i = read (file, buffer, file_size);
|
i = read (file, buffer, file_size);
|
||||||
close (file);
|
close (file);
|
||||||
|
|
||||||
#if 0
|
#if 1
|
||||||
if (i < file_size)
|
if (i < file_size)
|
||||||
#else
|
#else
|
||||||
if (i < 0)
|
if (i < 0)
|
||||||
|
@ -678,6 +682,30 @@ _rl_read_file (filename, sizep)
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer[file_size] = '\0';
|
buffer[file_size] = '\0';
|
||||||
|
|
||||||
|
#if O_BINARY
|
||||||
|
{
|
||||||
|
/* Systems which distinguish between text and binary files need
|
||||||
|
to strip the CR characters before each Newline, otherwise the
|
||||||
|
parsing functions won't work. */
|
||||||
|
char *s, *d;
|
||||||
|
size_t removed = 0;
|
||||||
|
|
||||||
|
for (s = buffer, d = buffer; s < buffer + file_size; s++)
|
||||||
|
{
|
||||||
|
if (removed)
|
||||||
|
*d = *s;
|
||||||
|
if (*s != '\r' || s[1] != '\n')
|
||||||
|
d++;
|
||||||
|
else
|
||||||
|
removed++;
|
||||||
|
}
|
||||||
|
|
||||||
|
file_size -= removed;
|
||||||
|
buffer[file_size] = '\0';
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (sizep)
|
if (sizep)
|
||||||
*sizep = file_size;
|
*sizep = file_size;
|
||||||
return (buffer);
|
return (buffer);
|
||||||
|
@ -699,6 +727,7 @@ rl_re_read_init_file (count, ignore)
|
||||||
1. the filename used for the previous call
|
1. the filename used for the previous call
|
||||||
2. the value of the shell variable `INPUTRC'
|
2. the value of the shell variable `INPUTRC'
|
||||||
3. ~/.inputrc
|
3. ~/.inputrc
|
||||||
|
4. (for __MSDOS__ only) ~/_inputrc
|
||||||
If the file existed and could be opened and read, 0 is returned,
|
If the file existed and could be opened and read, 0 is returned,
|
||||||
otherwise errno is returned. */
|
otherwise errno is returned. */
|
||||||
int
|
int
|
||||||
|
@ -718,6 +747,20 @@ rl_read_init_file (filename)
|
||||||
if (*filename == 0)
|
if (*filename == 0)
|
||||||
filename = DEFAULT_INPUTRC;
|
filename = DEFAULT_INPUTRC;
|
||||||
|
|
||||||
|
#ifdef __MSDOS__
|
||||||
|
{
|
||||||
|
/* DOS doesn't allow leading dots in file names. If the original
|
||||||
|
name fails (it could work if we are on Windows), fall back to
|
||||||
|
~/_inputrc. */
|
||||||
|
int retval = _rl_read_init_file (filename, 0);
|
||||||
|
|
||||||
|
if (retval == 0)
|
||||||
|
return retval;
|
||||||
|
else if (strcmp (filename, "~/.inputrc") == 0)
|
||||||
|
filename = "~/_inputrc";
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return (_rl_read_init_file (filename, 0));
|
return (_rl_read_init_file (filename, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue