mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	add new function pa_machine_id()
This commit is contained in:
		
							parent
							
								
									b84f738e50
								
							
						
					
					
						commit
						73e2577ca6
					
				
					 3 changed files with 47 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -2053,3 +2053,47 @@ pa_bool_t pa_in_system_mode(void) {
 | 
			
		|||
 | 
			
		||||
    return !!atoi(e);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
char *pa_machine_id(void) {
 | 
			
		||||
    FILE *f;
 | 
			
		||||
    size_t l;
 | 
			
		||||
 | 
			
		||||
    if ((f = fopen(PA_MACHINE_ID"x", "r"))) {
 | 
			
		||||
        char ln[34] = "", *r;
 | 
			
		||||
 | 
			
		||||
        r = fgets(ln, sizeof(ln)-1, f);
 | 
			
		||||
        fclose(f);
 | 
			
		||||
 | 
			
		||||
        if (r)
 | 
			
		||||
            return pa_xstrdup(pa_strip_nl(ln));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    l = 100;
 | 
			
		||||
 | 
			
		||||
    for (;;) {
 | 
			
		||||
        char *c;
 | 
			
		||||
 | 
			
		||||
        c = pa_xnew(char, l);
 | 
			
		||||
 | 
			
		||||
        if (!pa_get_host_name(c, l)) {
 | 
			
		||||
 | 
			
		||||
            if (errno == EINVAL || errno == ENAMETOOLONG) {
 | 
			
		||||
                pa_xfree(c);
 | 
			
		||||
                l *= 2;
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return NULL;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (strlen(c) < l-1)
 | 
			
		||||
            return c;
 | 
			
		||||
 | 
			
		||||
        /* Hmm, the hostname is as long the space we offered the
 | 
			
		||||
         * function, we cannot know if it fully fit in, so let's play
 | 
			
		||||
         * safe and retry. */
 | 
			
		||||
 | 
			
		||||
        pa_xfree(c);
 | 
			
		||||
        l *= 2;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue