From b9feec71ff66c703ede03364d37f8244aa8670a4 Mon Sep 17 00:00:00 2001 From: Ken Brown Date: Mon, 16 Nov 2020 15:06:48 -0500 Subject: [PATCH] Cygwin: fhandler_base::set_name_from _handle: new method This is based on a new static member function dtable::handle_to_fn, which was previously a static function in dtable.cc. --- winsup/cygwin/dtable.cc | 6 ++---- winsup/cygwin/dtable.h | 2 ++ winsup/cygwin/fhandler.cc | 13 +++++++++++++ winsup/cygwin/fhandler.h | 1 + 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc index 6a91e33bc..a86fc875c 100644 --- a/winsup/cygwin/dtable.cc +++ b/winsup/cygwin/dtable.cc @@ -31,8 +31,6 @@ details. */ static const DWORD std_consts[] = {STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, STD_ERROR_HANDLE}; -static bool handle_to_fn (HANDLE, char *); - #define WCLEN(x) ((sizeof (x) / sizeof (WCHAR)) - 1) static const char unknown_file[] = "some disk file"; static const WCHAR DEV_NULL[] = L"\\Device\\Null"; @@ -937,8 +935,8 @@ decode_tty (char *buf, WCHAR *w32) /* Try to derive posix filename from given handle. Return true if the handle is associated with a cygwin tty. */ -static bool -handle_to_fn (HANDLE h, char *posix_fn) +bool +dtable::handle_to_fn (HANDLE h, char *posix_fn) { tmp_pathbuf tp; ULONG len = 0; diff --git a/winsup/cygwin/dtable.h b/winsup/cygwin/dtable.h index 0f745a75a..2dbcca325 100644 --- a/winsup/cygwin/dtable.h +++ b/winsup/cygwin/dtable.h @@ -78,6 +78,8 @@ public: void fixup_before_fork (DWORD win_proc_id); void lock () {lock_process::locker.acquire ();} void unlock () {lock_process::locker.release ();} + + static bool handle_to_fn (HANDLE, char *); }; fhandler_base *build_fh_dev (const device&, const char * = NULL); diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc index 8a184a71b..83929f1f3 100644 --- a/winsup/cygwin/fhandler.cc +++ b/winsup/cygwin/fhandler.cc @@ -29,6 +29,7 @@ details. */ #include "shared_info.h" #include #include "cygwait.h" +#include "tls_pbuf.h" #define MAX_OVERLAPPED_WRITE_LEN (64 * 1024 * 1024) #define MIN_OVERLAPPED_WRITE_LEN (1 * 1024 * 1024) @@ -135,6 +136,18 @@ fhandler_base::set_name (path_conv &in_pc) pc << in_pc; } +/* Preliminary version. */ +void +fhandler_base::set_name_from_handle () +{ + tmp_pathbuf tp; + char *name = tp.c_get (); + + name[0] = '\0'; + dtable::handle_to_fn (get_handle (), name); + set_name (cstrdup (name)); +} + char *fhandler_base::get_proc_fd_name (char *buf) { IO_STATUS_BLOCK io; diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 542f15e2b..a6a807c32 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -237,6 +237,7 @@ class fhandler_base pc.set_posix (s); pc.set_path (s); } + virtual void set_name_from_handle (); int error () const {return pc.error;} void set_error (int error) {pc.error = error;} bool exists () const {return pc.exists ();}