Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs24-19fa
git_rec_nano
Commits
fd866966
Commit
fd866966
authored
7 years ago
by
Benno Schulenberg
Browse files
Options
Download
Email Patches
Plain Diff
tweaks: rename one variable once more
So that it is not a substring of some other name.
parent
09ab91c7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/history.c
+23
-22
src/history.c
with
23 additions
and
22 deletions
+23
-22
src/history.c
View file @
fd866966
...
...
@@ -293,7 +293,7 @@ void load_history(void)
char
*
histname
=
histfilename
();
char
*
legacyhist
=
legacyhistfilename
();
struct
stat
hstat
;
FILE
*
his
t
file
;
FILE
*
hisfile
;
/* If there is an old history file, migrate it. */
/* (To be removed in 2018.) */
...
...
@@ -308,9 +308,9 @@ void load_history(void)
legacyhist
,
histname
);
}
his
t
file
=
fopen
(
histname
,
"rb"
);
hisfile
=
fopen
(
histname
,
"rb"
);
if
(
his
t
file
==
NULL
)
{
if
(
hisfile
==
NULL
)
{
if
(
errno
!=
ENOENT
)
{
/* When reading failed, don't save history when we quit. */
UNSET
(
HISTORYLOG
);
...
...
@@ -326,7 +326,7 @@ void load_history(void)
size_t
buf_len
=
0
;
ssize_t
read
;
while
((
read
=
getline
(
&
line
,
&
buf_len
,
his
t
file
))
>
0
)
{
while
((
read
=
getline
(
&
line
,
&
buf_len
,
hisfile
))
>
0
)
{
line
[
--
read
]
=
'\0'
;
if
(
read
>
0
)
{
/* Encode any embedded NUL as 0x0A. */
...
...
@@ -339,7 +339,7 @@ void load_history(void)
}
fclose
(
his
t
file
);
fclose
(
hisfile
);
free
(
line
);
}
...
...
@@ -352,7 +352,7 @@ void load_history(void)
/* Write the lines of a history list, starting at head, from oldest to newest,
* to the given file. Return TRUE if writing succeeded, and FALSE otherwise. */
bool
write_list
(
const
filestruct
*
head
,
FILE
*
his
t
file
)
bool
write_list
(
const
filestruct
*
head
,
FILE
*
hisfile
)
{
const
filestruct
*
item
;
...
...
@@ -362,9 +362,9 @@ bool write_list(const filestruct *head, FILE *histfile)
/* Decode 0x0A bytes as embedded NULs. */
sunder
(
item
->
data
);
if
(
fwrite
(
item
->
data
,
sizeof
(
char
),
length
,
his
t
file
)
<
length
)
if
(
fwrite
(
item
->
data
,
sizeof
(
char
),
length
,
hisfile
)
<
length
)
return
FALSE
;
if
(
putc
(
'\n'
,
his
t
file
)
==
EOF
)
if
(
putc
(
'\n'
,
hisfile
)
==
EOF
)
return
FALSE
;
}
...
...
@@ -375,28 +375,29 @@ bool write_list(const filestruct *head, FILE *histfile)
void
save_history
(
void
)
{
char
*
histname
;
FILE
*
his
t
file
;
FILE
*
hisfile
;
/* If the histories are unchanged, don't bother saving them. */
if
(
!
history_changed
)
return
;
histname
=
histfilename
();
his
t
file
=
fopen
(
histname
,
"wb"
);
hisfile
=
fopen
(
histname
,
"wb"
);
if
(
his
t
file
==
NULL
)
if
(
hisfile
==
NULL
)
fprintf
(
stderr
,
_
(
"Error writing %s: %s
\n
"
),
histname
,
strerror
(
errno
));
else
{
/* Don't allow others to read or write the history file. */
chmod
(
histname
,
S_IRUSR
|
S_IWUSR
);
if
(
!
write_list
(
searchtop
,
histfile
)
||
!
write_list
(
replacetop
,
histfile
)
||
!
write_list
(
executetop
,
histfile
))
if
(
!
write_list
(
searchtop
,
hisfile
)
||
!
write_list
(
replacetop
,
hisfile
)
||
!
write_list
(
executetop
,
hisfile
))
fprintf
(
stderr
,
_
(
"Error writing %s: %s
\n
"
),
histname
,
strerror
(
errno
));
fclose
(
his
t
file
);
fclose
(
hisfile
);
}
free
(
histname
);
...
...
@@ -406,9 +407,9 @@ void save_history(void)
void
load_poshistory
(
void
)
{
char
*
poshist
=
poshistfilename
();
FILE
*
his
t
file
=
fopen
(
poshist
,
"rb"
);
FILE
*
hisfile
=
fopen
(
poshist
,
"rb"
);
if
(
his
t
file
==
NULL
)
{
if
(
hisfile
==
NULL
)
{
if
(
errno
!=
ENOENT
)
{
/* When reading failed, don't save history when we quit. */
UNSET
(
POS_HISTORY
);
...
...
@@ -421,7 +422,7 @@ void load_poshistory(void)
poshiststruct
*
record_ptr
=
NULL
,
*
newrecord
;
/* Read and parse each line, and store the extracted data. */
while
((
read
=
getline
(
&
line
,
&
buf_len
,
his
t
file
))
>
5
)
{
while
((
read
=
getline
(
&
line
,
&
buf_len
,
hisfile
))
>
5
)
{
/* Decode nulls as embedded newlines. */
unsunder
(
line
,
read
);
...
...
@@ -462,7 +463,7 @@ void load_poshistory(void)
free
(
drop_record
);
}
}
fclose
(
his
t
file
);
fclose
(
hisfile
);
free
(
line
);
}
free
(
poshist
);
...
...
@@ -473,9 +474,9 @@ void save_poshistory(void)
{
char
*
poshist
=
poshistfilename
();
poshiststruct
*
posptr
;
FILE
*
his
t
file
=
fopen
(
poshist
,
"wb"
);
FILE
*
hisfile
=
fopen
(
poshist
,
"wb"
);
if
(
his
t
file
==
NULL
)
if
(
hisfile
==
NULL
)
fprintf
(
stderr
,
_
(
"Error writing %s: %s
\n
"
),
poshist
,
strerror
(
errno
));
else
{
/* Don't allow others to read or write the history file. */
...
...
@@ -497,12 +498,12 @@ void save_poshistory(void)
/* Restore the terminating newline. */
path_and_place
[
length
-
1
]
=
'\n'
;
if
(
fwrite
(
path_and_place
,
sizeof
(
char
),
length
,
his
t
file
)
<
length
)
if
(
fwrite
(
path_and_place
,
sizeof
(
char
),
length
,
hisfile
)
<
length
)
fprintf
(
stderr
,
_
(
"Error writing %s: %s
\n
"
),
poshist
,
strerror
(
errno
));
free
(
path_and_place
);
}
fclose
(
his
t
file
);
fclose
(
hisfile
);
}
free
(
poshist
);
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment