mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	conf: write valid JSON by putting , between keys
Separate keys with , to make a valid json file
This commit is contained in:
		
							parent
							
								
									b40397d986
								
							
						
					
					
						commit
						8d5cc7013d
					
				
					 1 changed files with 4 additions and 4 deletions
				
			
		| 
						 | 
					@ -185,7 +185,7 @@ int pw_conf_save_state(const char *prefix, const char *name, struct pw_propertie
 | 
				
			||||||
	const struct spa_dict_item *it;
 | 
						const struct spa_dict_item *it;
 | 
				
			||||||
	char path[PATH_MAX];
 | 
						char path[PATH_MAX];
 | 
				
			||||||
	char *tmp_name;
 | 
						char *tmp_name;
 | 
				
			||||||
	int res, sfd, fd;
 | 
						int res, sfd, fd, count = 0;
 | 
				
			||||||
	FILE *f;
 | 
						FILE *f;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ((sfd = open_write_dir(path, sizeof(path), prefix)) < 0)
 | 
						if ((sfd = open_write_dir(path, sizeof(path), prefix)) < 0)
 | 
				
			||||||
| 
						 | 
					@ -200,16 +200,16 @@ int pw_conf_save_state(const char *prefix, const char *name, struct pw_propertie
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	f = fdopen(fd, "w");
 | 
						f = fdopen(fd, "w");
 | 
				
			||||||
	fprintf(f, "{ \n");
 | 
						fprintf(f, "{");
 | 
				
			||||||
	spa_dict_for_each(it, &conf->dict) {
 | 
						spa_dict_for_each(it, &conf->dict) {
 | 
				
			||||||
		char key[1024];
 | 
							char key[1024];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (spa_json_encode_string(key, sizeof(key)-1, it->key) >= (int)sizeof(key)-1)
 | 
							if (spa_json_encode_string(key, sizeof(key)-1, it->key) >= (int)sizeof(key)-1)
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		fprintf(f, " %s: %s\n", key, it->value);
 | 
							fprintf(f, "%s\n  %s: %s", count++ == 0 ? "" : ",", key, it->value);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	fprintf(f, "}\n");
 | 
						fprintf(f, "%s}", count == 0 ? " " : "\n");
 | 
				
			||||||
	fclose(f);
 | 
						fclose(f);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (renameat(sfd, tmp_name, sfd, name) < 0) {
 | 
						if (renameat(sfd, tmp_name, sfd, name) < 0) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue