Loading base/include/android-base/unique_fd.h +12 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include <sys/socket.h> #endif #include <stdio.h> #include <sys/types.h> #include <unistd.h> Loading Loading @@ -199,6 +200,17 @@ inline bool Socketpair(int type, unique_fd_impl<Closer>* left, unique_fd_impl<Cl return Socketpair(AF_UNIX, type, 0, left, right); } // Using fdopen with unique_fd correctly is more annoying than it should be, // because fdopen doesn't close the file descriptor received upon failure. inline FILE* Fdopen(unique_fd&& ufd, const char* mode) { int fd = ufd.release(); FILE* file = fdopen(fd, mode); if (!file) { close(fd); } return file; } #endif // !defined(_WIN32) } // namespace base Loading Loading
base/include/android-base/unique_fd.h +12 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include <sys/socket.h> #endif #include <stdio.h> #include <sys/types.h> #include <unistd.h> Loading Loading @@ -199,6 +200,17 @@ inline bool Socketpair(int type, unique_fd_impl<Closer>* left, unique_fd_impl<Cl return Socketpair(AF_UNIX, type, 0, left, right); } // Using fdopen with unique_fd correctly is more annoying than it should be, // because fdopen doesn't close the file descriptor received upon failure. inline FILE* Fdopen(unique_fd&& ufd, const char* mode) { int fd = ufd.release(); FILE* file = fdopen(fd, mode); if (!file) { close(fd); } return file; } #endif // !defined(_WIN32) } // namespace base Loading