Skip to content

Commit

Permalink
main: Add error checks and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
k-takata committed Aug 23, 2015
1 parent ef6c3af commit 690fa22
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 4 additions & 1 deletion main/entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ extern void openTagFile (void)
/* Open the tags file.
*/
if (TagsToStdout)
/* Open a tempfile with read and write mode. Read mode is used when
* write the result to stdout. */
TagFile.fp = tempFile ("w+", &TagFile.name);
else
{
Expand Down Expand Up @@ -548,12 +550,13 @@ extern void closeTagFile (const boolean resize)

if (Option.etags)
writeEtagsIncludes (TagFile.fp);
abort_if_ferror (TagFile.fp);
fflush (TagFile.fp);
abort_if_ferror (TagFile.fp);
desiredSize = ftell (TagFile.fp);
fseek (TagFile.fp, 0L, SEEK_END);
size = ftell (TagFile.fp);
if (! TagsToStdout)
/* The tag file should be closed before resizing. */
if (fclose (TagFile.fp) != 0)
error (FATAL | PERROR, "cannot close tag file");

Expand Down
11 changes: 8 additions & 3 deletions main/sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,15 @@ extern void externalSortTags (const boolean toStdout)
int fdsave;

fdsave = dup (fdstdin);
dup2 (fileno (TagFile.fp), fdstdin);
lseek (fdstdin, 0, SEEK_SET);
if (fdsave < 0)
error (FATAL | PERROR, "cannot save stdin fd");
if (dup2 (fileno (TagFile.fp), fdstdin) < 0)
error (FATAL | PERROR, "cannot redirect stdin");
if (lseek (fdstdin, 0, SEEK_SET) != 0)
error (FATAL | PERROR, "cannot rewind tag file");
ret = system (cmd);
dup2 (fdsave, fdstdin);
if (dup2 (fdsave, fdstdin) < 0)
error (FATAL | PERROR, "cannot restore stdin fd");
close (fdsave);
}
else
Expand Down

1 comment on commit 690fa22

@masatake
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Please sign in to comment.