【问题标题】:Win32 equivalent of getgid [closed]Win32相当于getgid [关闭]
【发布时间】:2020-01-13 12:12:07
【问题描述】:

我正在尝试将一些 C Linux 代码转换为 Win32 C++。我有 getgid 功能。如何将此 Linux C 函数转换为 Win32?

这是 getgid 的文档:http://man7.org/linux/man-pages/man2/getgid.2.html

这里是使用上下文:

struct SEC_CONTEXT* scx;
scx->gid = getgid();

其中 SEC_CONTEXT 定义为:

struct SEC_CONTEXT {
ntfs_volume* vol;
gid_t gid; /* gid of user requesting (not the mounter) */
pid_t tid; /* thread id of thread requesting */
};

此外,scx 这个对象在 ntfs_mapping 函数内部使用,等等……而 git_t 是一个简单的 无符号整数

【问题讨论】:

  • Windows 不像 POSIX 系统那样具有“组”,因此在 Windows 中没有等效的功能。
  • 您是否需要打印“组”ID?原程序在做什么?
  • 你只是在谈论力学。你应该做的是捕捉逻辑。您需要首先回答几个问题:源应用程序对这些信息做了什么?可以将这种用法转换为更通用的概念吗?你能把这个概念翻译到 Windows 上吗?在你得到这些问题的答案之前,不要编写任何代码。
  • 由于我们不知道它的用途或程序在做什么,所以我们真的无从得知。
  • "... 到 ntfs_build_mapping 函数中。这个函数是 NTFS Linux 库的一部分..." 因为 NTFS 是 MS-Windows 原生的,首先要删除这一层 .. . 你的其他问题我就消失了。

标签: c++ windows winapi visual-c++ mfc


【解决方案1】:

Windows 没有 POSIX 进程组的概念。使该代码可移植需要了解组 ID 的用途。

不过,作为灵感,下面是 GnuWin 的实现方式:

/* Get the real group ID of the calling process.  */
gid_t
__getgid ()
{
  return 0;
}

getpgid 获得了一个更有用的值,因为默认情况下,windows 按父 PID 对进程进行分组;所以组 id 等于进程 id 值。

【讨论】:

  • getpgid 在 Win32 中也没有等价物......但我想返回 0 是可以的。
  • @flaviu2 getpgid 在 Win32 中将简单地返回传递的值。或者,另一种方式,而不是getpgid,您可以只获取该进程的 pid。
  • 那我需要一种 GetProcessID() 吗?比如:docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/… ?
  • 我们不知道您需要做什么来解决您的问题,因为您只询问了您提出的解决方案。
  • 我有这样的圆顶,希望没问题:scx->gid = GetProcessId(::GetCurrentProcess());如有错误请指正。
猜你喜欢
  • 2010-09-30
  • 1970-01-01
  • 2019-06-25
  • 2013-12-30
  • 2010-10-03
  • 2023-03-05
  • 1970-01-01
  • 1970-01-01
  • 2010-09-07
相关资源
最近更新 更多