summaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2013-05-04 13:10:56 -0400
committerPaul Smith <psmith@gnu.org>2013-05-04 13:10:56 -0400
commitb8467292c9be14b31c028d472107946770ed977e (patch)
tree83a4a38f0209303e73e93d03218528e1ba07c366 /misc.c
parentcb2be0db36b9730d9879dec4332141ee4db9377f (diff)
downloadgunmake-b8467292c9be14b31c028d472107946770ed977e.tar.gz
Improve sync handling for -Ojob/-Otarget and recursion.
If we are not going to sync a command line then dump any collected output first to preserve ordering. Do some code cleanup: * Move the handle init to a separate function. * Move the temp file truncation to the output function. * Remember whether we sync in a variable for readability. * Handle EINTR and short writes in child_out(). * Always call sync_output() in case output_sync was changed due to error.
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/misc.c b/misc.c
index 12b9d3d..766874f 100644
--- a/misc.c
+++ b/misc.c
@@ -182,7 +182,8 @@ concat (unsigned int num, ...)
/* If we had a standard-compliant vsnprintf() this would be a lot simpler.
Maybe in the future we'll include gnulib's version. */
-/* Return a formatted string buffer. */
+/* Return a formatted string buffer.
+ LENGTH must be the maximum length of all format arguments, stringified. */
const char *
message_s (unsigned int length, int prefix, const char *fmt, ...)
@@ -193,7 +194,7 @@ message_s (unsigned int length, int prefix, const char *fmt, ...)
va_list args;
/* Compute the maximum buffer size we'll need, and make sure we have it. */
- length += strlen (fmt) + strlen (program) + 4 + INTEGER_LENGTH + 1;
+ length += strlen (fmt) + strlen (program) + 4 + INTEGER_LENGTH + 2;
if (length > bsize)
{
bsize = length * 2;
@@ -214,10 +215,13 @@ message_s (unsigned int length, int prefix, const char *fmt, ...)
vsprintf (bp, fmt, args);
va_end (args);
+ strcat (bp, "\n");
+
return buffer;
}
-/* Return a formatted error message in a buffer. */
+/* Return a formatted error message in a buffer.
+ LENGTH must be the maximum length of all format arguments, stringified. */
const char *
error_s (unsigned int length, const gmk_floc *flocp, const char *fmt, ...)
@@ -228,7 +232,7 @@ error_s (unsigned int length, const gmk_floc *flocp, const char *fmt, ...)
va_list args;
/* Compute the maximum buffer size we'll need, and make sure we have it. */
- length += (strlen (fmt) + strlen (program) + 4 + INTEGER_LENGTH + 1
+ length += (strlen (fmt) + strlen (program) + 4 + INTEGER_LENGTH + 2
+ (flocp && flocp->filenm ? strlen (flocp->filenm) : 0));
if (length > bsize)
{
@@ -249,10 +253,13 @@ error_s (unsigned int length, const gmk_floc *flocp, const char *fmt, ...)
vsprintf (bp, fmt, args);
va_end (args);
+ strcat (bp, "\n");
+
return buffer;
}
-/* Print a message on stdout. */
+/* Print a message on stdout. We could use message_s() to format it but then
+ we'd need a va_list version... */
void
message (int prefix, const char *fmt, ...)
@@ -950,7 +957,7 @@ char *mktemp (char *template);
# endif
#endif
-/* This is only used by output-sync, and it may not be portable to Windows. */
+/* This is only used by output-sync, and it may not be portable. */
#ifdef OUTPUT_SYNC
/* Returns a file descriptor to a temporary file. The file is automatically