summaryrefslogtreecommitdiffhomepage
path: root/public/frameworks/LaunchHelpers.fwrk/headers/Foundation.h
blob: 81c6b5a1fd0957620fe85896c4f430cd0f24d586 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org)
// Licensed under the Apache License, Version 2.0 (see LICENSE file)
// Official repository: https://github.com/ne-foss-org/nekernel

#ifndef HEADERS_FOUNDATION_H
#define HEADERS_FOUNDATION_H

#include <CoreFoundation.fwrk/headers/Foundation.h>
#include <CoreFoundation.fwrk/headers/String.h>

namespace LaunchHelpers {
struct LHLaunchInfo;

inline constexpr auto kMaxPath = 4096;
inline constexpr auto kMaxArgs = 256;

/// @brief Launch information structure.
/// @note This structure is read-only. Modyfing its members wo't have any effect.
struct LHLaunchInfo final {
  CF::CFString            fExecutablePath{kMaxPath};
  CF::CFString            fWorkingDirectory{kMaxPath};
  CF::CFRef<CF::CFString> fArguments[kMaxArgs];
  CF::CFString            fEnvironment{kMaxPath};
  CF::CFInteger64         fUID{0};
  CF::CFInteger64         fGID{0};

  LHLaunchInfo()  = default;
  ~LHLaunchInfo() = default;

  LIBSYS_COPY_DELETE(LHLaunchInfo)

  explicit operator bool() { return fUID && fGID; }

  CF::CFRef<CF::CFString>* begin() { return fArguments; }
  CF::CFRef<CF::CFString>* end() { return fArguments + kMaxArgs; }

  SizeT size() { return kMaxArgs; }
};

using LHLaunchInfoPtr = LHLaunchInfo*;

/// @brief Get launch information.
/// @return the launch information structure.
CF::CFRef<LHLaunchInfo> LHGetLaunchInfo(Void);
}  // namespace LaunchHelpers

#endif