Commits

Wez Furlong committed e7166dd

While testing to see if this version has the same problems as SF bug ID
1724372, valgrind complained about the overlapped buffer use in the progress
bar code. So, rewrite it.

Also handle ENOSYS as an acceptable (silent) error condition when using
splice(2); valgrind does not implement that syscall.

  • Participants
  • Parent commits 230e7f0

Comments (0)

Files changed (1)

File src/AtomicParsley.cpp

 	}
 	update_count = 0;
 
-	strcpy(file_progress_buffer, " Progress: ");
-	
 	double dispprog = (double)bytes_written / (double)new_file_size
 						* max_display_width;
 	int display_progress = (int)lroundf(dispprog);
 	double percomp = 100.0 * (double)bytes_written / (double)new_file_size;
 	int percentage_complete = (int)lroundf(percomp);
-		
-	for (int i = 0; i <= max_display_width; i++) {
-		if (i < display_progress ) {
-			strcat(file_progress_buffer, "=");
-		} else if (i == display_progress) {
-			sprintf(file_progress_buffer, "%s>%d%%", file_progress_buffer, percentage_complete);
-		} else {
-			strcat(file_progress_buffer, "-");
-		}
-	}
-	if (percentage_complete < 100) {
-		strcat(file_progress_buffer, "-");
-		if (percentage_complete < 10) {
-			strcat(file_progress_buffer, "-");
-		}
-	}
 	
-	strcat(file_progress_buffer, "|");
-		
+	char *p = file_progress_buffer;
+	strcpy(p, " Progress: ");
+	p += strlen(p);
+
+	memset(p, '=', display_progress);
+	p += display_progress;
+
+	sprintf(p, ">%3d%% ", percentage_complete);
+	p += strlen(p);
+
+	memset(p, '-', max_display_width - display_progress);
+	p += max_display_width - display_progress;
+	p[0] = '|';
+	p[1] = '\0';
+
 	fprintf(stdout, "%s\r", file_progress_buffer);
 	fflush(stdout);
 }
 			SPLICE_F_MORE|SPLICE_F_MOVE);
 
 		if (didread <= 0) {
-			if (errno == EINVAL) {
+			if (errno == EINVAL || errno == ENOSYS) {
 				/* splice is not supported by source */
 				break;
 			}
 					SPLICE_F_MORE|SPLICE_F_MOVE);
 
 			if (didwrite <= 0) {
-				if (errno == EINVAL) {
+				if (errno == EINVAL || errno == ENOSYS) {
 					/* splice is not supported by dest */
 					break;
 				}