- if (r < 0) bb_error_msg_and_die(bb_msg_memory_exhausted);
- return string_ptr;
-}
-
-// Die with an error message if we can't copy an entire FILE * to stdout, then
-// close that file.
-void xprint_and_close_file(FILE *file)
-{
- fflush(stdout);
- // copyfd outputs error messages for us.
- if (bb_copyfd_eof(fileno(file), 1) == -1)
- exit(xfunc_error_retval);
-
- fclose(file);
-}
-
-// Die if we can't chdir to a new path.
-void xchdir(const char *path)
-{
- if (chdir(path))
- bb_perror_msg_and_die("chdir(%s)", path);
-}
-
-// Print a warning message if opendir() fails, but don't die.
-DIR *warn_opendir(const char *path)
-{
- DIR *dp;
-
- if ((dp = opendir(path)) == NULL) {
- bb_perror_msg("cannot open '%s'", path);
- return NULL;
- }
- return dp;
-}
-
-// Die with an error message if opendir() fails.
-DIR *xopendir(const char *path)
-{
- DIR *dp;
-
- if ((dp = opendir(path)) == NULL)
- bb_perror_msg_and_die("cannot open '%s'", path);
- return dp;
-}
-
-#ifndef BB_NOMMU
-// Die with an error message if we can't daemonize.
-void xdaemon(int nochdir, int noclose)
-{
- if (daemon(nochdir, noclose))
- bb_perror_msg_and_die("daemon");
-}
-#endif
-
-// Die with an error message if we can't open a new socket.
-int xsocket(int domain, int type, int protocol)
-{
- int r = socket(domain, type, protocol);
-
- if (r < 0) bb_perror_msg_and_die("socket");
-
- return r;
-}
-
-// Die with an error message if we can't bind a socket to an address.
-void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen)
-{
- if (bind(sockfd, my_addr, addrlen)) bb_perror_msg_and_die("bind");
-}
-
-// Die with an error message if we can't listen for connections on a socket.
-void xlisten(int s, int backlog)
-{
- if (listen(s, backlog)) bb_perror_msg_and_die("listen");
-}
-
-// xstat() - a stat() which dies on failure with meaningful error message
-void xstat(char *name, struct stat *stat_buf)
-{
- if (stat(name, stat_buf))
- bb_perror_msg_and_die("can't stat '%s'", name);
-}
-