fixdep: factor out common code for reading files
authorMasahiro Yamada <yamada.masahiro@socionext.com>
Thu, 11 Jan 2018 13:05:42 +0000 (22:05 +0900)
committerMasahiro Yamada <yamada.masahiro@socionext.com>
Thu, 18 Jan 2018 00:37:38 +0000 (09:37 +0900)
commit4003fd80cba967e4044ebac96f13746153e87c4d
tree006b763982e18bb1625de91fd02ddd030d93a545
parent01b5cbe7012fb1eeffc5c143865569835bcd405e
fixdep: factor out common code for reading files

Now, do_config_files() and print_deps() are almost the same.  Only
the difference is the parser function called (parse_config_file vs
parse_dep_file).

We can reduce the code duplication by factoring out the common code
into read_file() - this function allocates a buffer and loads a file
to it.  It returns the pointer to the allocated buffer.  (As before,
it bails out by exit(2) for any error.)  The caller must free the
buffer when done.

Having empty source files is possible; fixdep should simply skip them.
I deleted the "st.st_size == 0" check, so read_file() allocates 1-byte
buffer for an empty file.  strstr() will immediately return NULL, and
this is what we expect.

On the other hand, an empty dep_file should be treated as an error.
In this case, parse_dep_file() will error out with "no targets found"
and it is a correct error message.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
scripts/basic/fixdep.c