mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	core-util: introduce pa_fopen_cloexec()
This commit is contained in:
		
							parent
							
								
									a698ee3f52
								
							
						
					
					
						commit
						752727a13d
					
				
					 2 changed files with 29 additions and 3 deletions
				
			
		| 
						 | 
					@ -2961,7 +2961,7 @@ int pa_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef HAVE_ACCEPT4
 | 
					#ifdef HAVE_ACCEPT4
 | 
				
			||||||
    if ((fd = accept4(sockfd, addr, addrlen, SOCK_CLOEXEC)) >= 0)
 | 
					    if ((fd = accept4(sockfd, addr, addrlen, SOCK_CLOEXEC)) >= 0)
 | 
				
			||||||
        return fd;
 | 
					        goto finish;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (errno != EINVAL && errno != ENOSYS)
 | 
					    if (errno != EINVAL && errno != ENOSYS)
 | 
				
			||||||
        return fd;
 | 
					        return fd;
 | 
				
			||||||
| 
						 | 
					@ -2970,7 +2970,32 @@ int pa_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen) {
 | 
				
			||||||
    if ((fd = accept(sockfd, addr, addrlen)) < 0)
 | 
					    if ((fd = accept(sockfd, addr, addrlen)) < 0)
 | 
				
			||||||
        return fd;
 | 
					        return fd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					finish:
 | 
				
			||||||
    pa_make_fd_cloexec(fd);
 | 
					    pa_make_fd_cloexec(fd);
 | 
				
			||||||
 | 
					    return fd;
 | 
				
			||||||
    return 0;
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					FILE* pa_fopen_cloexec(const char *path, const char *mode) {
 | 
				
			||||||
 | 
					    FILE *f;
 | 
				
			||||||
 | 
					    char *m;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    m = pa_sprintf_malloc("%se", mode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    errno = 0;
 | 
				
			||||||
 | 
					    if ((f = fopen(path, m))) {
 | 
				
			||||||
 | 
					        pa_xfree(m);
 | 
				
			||||||
 | 
					        goto finish;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    pa_xfree(m);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (errno != EINVAL)
 | 
				
			||||||
 | 
					        return NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!(f = fopen(path, mode)))
 | 
				
			||||||
 | 
					        return NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					finish:
 | 
				
			||||||
 | 
					    pa_make_fd_cloexec(fileno(f));
 | 
				
			||||||
 | 
					    return f;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -263,5 +263,6 @@ int pa_open_cloexec(const char *fn, int flags, mode_t mode);
 | 
				
			||||||
int pa_socket_cloexec(int domain, int type, int protocol);
 | 
					int pa_socket_cloexec(int domain, int type, int protocol);
 | 
				
			||||||
int pa_pipe_cloexec(int pipefd[2]);
 | 
					int pa_pipe_cloexec(int pipefd[2]);
 | 
				
			||||||
int pa_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
 | 
					int pa_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
 | 
				
			||||||
 | 
					FILE* pa_fopen_cloexec(const char *path, const char *mode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue