summaryrefslogtreecommitdiffhomepage
path: root/public/tools/ld.dyn/src/CommandLine.cc
blob: 90a7979628c057be1965b73e4a71099bc3cc84d1 (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
/*
 * Created on Thu Oct 17 08:00:42 CEST 2024
 *
 * Copyright (c) 2024-2025 Amlal El Mahrouss
 */

#include <user/SystemCalls.h>

/// @brief Library loader.

#define DYNLIB_FLAG  "-dyn"

SInt32 _NeMain(SInt32 argc, Char* argv[])
{
	SCI_UNUSED(argc);
	SCI_UNUSED(argv);

	PrintOut(nullptr, "%s", "ld.dyn: Dynamic Loader.\n");
	PrintOut(nullptr, "%s", "ld.dyn: © 2024-2025 Amlal El Mahrouss, All rights reserved.\n");

	for (SInt32 i = 1U; i < argc; ++i)
	{
		if (MmStrCmp(argv[i], DYNLIB_FLAG) == 0)
		{
			UIntPtr ret = RtlSpawnProcess(argv[i], 0, nullptr, nullptr, 0);

			if (0 < ret)
			{
				return RtlSpawnIB(ret);
			}

			PrintOut(nullptr, "%s", "ld.dyn: Failed to load the library.\n");
			PrintOut(nullptr, "%s", "ld.dyn: Make sure the library is valid.\n");

			break;
		}
		else
		{
			PrintOut(nullptr, "%s", "ld.dyn: Invalid argument.\n");
			PrintOut(nullptr, "%s", "ld.dyn: Use -dyn <path> to load a dynamic library.\n");
			
			break;
		}
	}

	return EXIT_FAILURE;
}