mirror of
				https://github.com/AetherDroid/android_kernel_samsung_on5xelte.git
				synced 2025-10-31 08:08:51 +01:00 
			
		
		
		
	Fixed MTP to work with TWRP
This commit is contained in:
		
						commit
						f6dfaef42e
					
				
					 50820 changed files with 20846062 additions and 0 deletions
				
			
		
							
								
								
									
										54
									
								
								tools/perf/util/quote.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								tools/perf/util/quote.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,54 @@ | |||
| #include "cache.h" | ||||
| #include "quote.h" | ||||
| 
 | ||||
| /* Help to copy the thing properly quoted for the shell safety.
 | ||||
|  * any single quote is replaced with '\'', any exclamation point | ||||
|  * is replaced with '\!', and the whole thing is enclosed in a | ||||
|  * | ||||
|  * E.g. | ||||
|  *  original     sq_quote     result | ||||
|  *  name     ==> name      ==> 'name' | ||||
|  *  a b      ==> a b       ==> 'a b' | ||||
|  *  a'b      ==> a'\''b    ==> 'a'\''b' | ||||
|  *  a!b      ==> a'\!'b    ==> 'a'\!'b' | ||||
|  */ | ||||
| static inline int need_bs_quote(char c) | ||||
| { | ||||
| 	return (c == '\'' || c == '!'); | ||||
| } | ||||
| 
 | ||||
| static void sq_quote_buf(struct strbuf *dst, const char *src) | ||||
| { | ||||
| 	char *to_free = NULL; | ||||
| 
 | ||||
| 	if (dst->buf == src) | ||||
| 		to_free = strbuf_detach(dst, NULL); | ||||
| 
 | ||||
| 	strbuf_addch(dst, '\''); | ||||
| 	while (*src) { | ||||
| 		size_t len = strcspn(src, "'!"); | ||||
| 		strbuf_add(dst, src, len); | ||||
| 		src += len; | ||||
| 		while (need_bs_quote(*src)) { | ||||
| 			strbuf_addstr(dst, "'\\"); | ||||
| 			strbuf_addch(dst, *src++); | ||||
| 			strbuf_addch(dst, '\''); | ||||
| 		} | ||||
| 	} | ||||
| 	strbuf_addch(dst, '\''); | ||||
| 	free(to_free); | ||||
| } | ||||
| 
 | ||||
| void sq_quote_argv(struct strbuf *dst, const char** argv, size_t maxlen) | ||||
| { | ||||
| 	int i; | ||||
| 
 | ||||
| 	/* Copy into destination buffer. */ | ||||
| 	strbuf_grow(dst, 255); | ||||
| 	for (i = 0; argv[i]; ++i) { | ||||
| 		strbuf_addch(dst, ' '); | ||||
| 		sq_quote_buf(dst, argv[i]); | ||||
| 		if (maxlen && dst->len > maxlen) | ||||
| 			die("Too many or long arguments"); | ||||
| 	} | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 awab228
						awab228