forked from mirrors/linux
		
	lib/string_helpers: string_get_size() now returns characters wrote
printbuf now needs to know the number of characters that would have been written if the buffer was too small, like snprintf(); this changes string_get_size() to return the the return value of snprintf(). Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
		
							parent
							
								
									7d672f4094
								
							
						
					
					
						commit
						83feeb1955
					
				
					 2 changed files with 8 additions and 6 deletions
				
			
		|  | @ -24,7 +24,7 @@ enum string_size_units { | ||||||
| 	STRING_UNITS_2,		/* use binary powers of 2^10 */ | 	STRING_UNITS_2,		/* use binary powers of 2^10 */ | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| void string_get_size(u64 size, u64 blk_size, enum string_size_units units, | int string_get_size(u64 size, u64 blk_size, enum string_size_units units, | ||||||
| 		    char *buf, int len); | 		    char *buf, int len); | ||||||
| 
 | 
 | ||||||
| int parse_int_array_user(const char __user *from, size_t count, int **array); | int parse_int_array_user(const char __user *from, size_t count, int **array); | ||||||
|  |  | ||||||
|  | @ -31,8 +31,10 @@ | ||||||
|  * giving the size in the required units.  @buf should have room for |  * giving the size in the required units.  @buf should have room for | ||||||
|  * at least 9 bytes and will always be zero terminated. |  * at least 9 bytes and will always be zero terminated. | ||||||
|  * |  * | ||||||
|  |  * Return value: number of characters of output that would have been written | ||||||
|  |  * (which may be greater than len, if output was truncated). | ||||||
|  */ |  */ | ||||||
| void string_get_size(u64 size, u64 blk_size, const enum string_size_units units, | int string_get_size(u64 size, u64 blk_size, const enum string_size_units units, | ||||||
| 		    char *buf, int len) | 		    char *buf, int len) | ||||||
| { | { | ||||||
| 	static const char *const units_10[] = { | 	static const char *const units_10[] = { | ||||||
|  | @ -126,7 +128,7 @@ void string_get_size(u64 size, u64 blk_size, const enum string_size_units units, | ||||||
| 	else | 	else | ||||||
| 		unit = units_str[units][i]; | 		unit = units_str[units][i]; | ||||||
| 
 | 
 | ||||||
| 	snprintf(buf, len, "%u%s %s", (u32)size, | 	return snprintf(buf, len, "%u%s %s", (u32)size, | ||||||
| 			tmp, unit); | 			tmp, unit); | ||||||
| } | } | ||||||
| EXPORT_SYMBOL(string_get_size); | EXPORT_SYMBOL(string_get_size); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Kent Overstreet
						Kent Overstreet