Skip to content

Commit

Permalink
Merge pull request universal-ctags#247 from masatake/more-ferror
Browse files Browse the repository at this point in the history
check the file output error more frequently
  • Loading branch information
masatake committed Feb 25, 2015
2 parents b68ed3c + c389dd0 commit 09f98f0
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ extern const char *tagFileName (void)
* Pseudo tag support
*/

static void abort_if_ferror(FILE *const fp)
{
if (ferror (fp))
error (FATAL | PERROR, "cannot write tag file");
}

static void rememberMaxLengths (const size_t nameLength, const size_t lineLength)
{
if (nameLength > TagFile.max.tag)
Expand All @@ -139,6 +145,8 @@ extern void writePseudoTag (
: fprintf (TagFile.fp, "%s%s\t%s\t/%s/\n",
PSEUDO_TAG_PREFIX, tagName, fileName, pattern);

abort_if_ferror (TagFile.fp);

++TagFile.numTags.added;
rememberMaxLengths (strlen (tagName), (size_t) length);
}
Expand Down Expand Up @@ -430,10 +438,7 @@ extern void openTagFile (void)
}
}
if (TagFile.fp == NULL)
{
error (FATAL | PERROR, "cannot open tag file");
exit (1);
}
}
if (TagsToStdout)
TagFile.directory = eStrdup (CurrentDirectory);
Expand Down Expand Up @@ -530,10 +535,13 @@ extern void closeTagFile (const boolean resize)

if (Option.etags)
writeEtagsIncludes (TagFile.fp);
abort_if_ferror (TagFile.fp);
desiredSize = ftell (TagFile.fp);
fseek (TagFile.fp, 0L, SEEK_END);
size = ftell (TagFile.fp);
fclose (TagFile.fp);
if (fclose (TagFile.fp) != 0)
error (FATAL | PERROR, "cannot close tag file");

if (resize && desiredSize < size)
{
DebugStatement (
Expand All @@ -557,6 +565,8 @@ extern void endEtagsFile (const char *const name)
const char *line;

fprintf (TagFile.fp, "\f\n%s,%ld\n", name, (long) TagFile.etags.byteCount);
abort_if_ferror (TagFile.fp);

if (TagFile.etags.fp != NULL)
{
rewind (TagFile.etags.fp);
Expand Down Expand Up @@ -835,12 +845,11 @@ extern void makeTagEntry (const tagEntryInfo *const tag)
else
length = writeCtagsEntry (tag);

if (ferror (TagFile.fp))
error (FATAL | PERROR, "cannot write tag file");

++TagFile.numTags.added;
rememberMaxLengths (strlen (tag->name), (size_t) length);
DebugStatement ( fflush (TagFile.fp); )

abort_if_ferror (TagFile.fp);
}
}

Expand Down

0 comments on commit 09f98f0

Please sign in to comment.