Change the behavior of the parse_unit code to return the number of
bytes needed to print the whole string (minus the trailing '\0'), just like snprintf. Idea from bugreport from Gabriel Kihlman <gk@stacken.kth.se>. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@14324 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
		| @@ -107,7 +107,11 @@ and | |||||||
| .Fn unparse_time_approx  | .Fn unparse_time_approx  | ||||||
| return the number of characters written to  | return the number of characters written to  | ||||||
| .Fa buf . | .Fa buf . | ||||||
| .\".Sh EXAMPLES | if the return value is greater than or equal to the | ||||||
|  | .Fa len | ||||||
|  | argument, the string was too short and some of the printed characters | ||||||
|  | were discarded. | ||||||
|  | .Sh EXAMPLES | ||||||
| .Bd -literal | .Bd -literal | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <parse_time.h> | #include <parse_time.h> | ||||||
|   | |||||||
| @@ -212,9 +212,13 @@ unparse_something (int num, const struct units *units, char *s, size_t len, | |||||||
| 	    tmp = (*print) (s, len, div, u->name, num); | 	    tmp = (*print) (s, len, div, u->name, num); | ||||||
| 	    if (tmp < 0) | 	    if (tmp < 0) | ||||||
| 		return tmp; | 		return tmp; | ||||||
|  | 	    if (tmp > len) { | ||||||
| 	    len -= tmp; | 		len = 0; | ||||||
| 	    s += tmp; | 		s = NULL; | ||||||
|  | 	    } else { | ||||||
|  | 		len -= tmp; | ||||||
|  | 		s += tmp; | ||||||
|  | 	    } | ||||||
| 	    ret += tmp; | 	    ret += tmp; | ||||||
| 	} | 	} | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Love Hörnquist Åstrand
					Love Hörnquist Åstrand