summaryrefslogtreecommitdiff
path: root/src/pal/src/examples/example1.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/src/examples/example1.cpp')
-rw-r--r--src/pal/src/examples/example1.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/pal/src/examples/example1.cpp b/src/pal/src/examples/example1.cpp
new file mode 100644
index 0000000000..071f42e4f9
--- /dev/null
+++ b/src/pal/src/examples/example1.cpp
@@ -0,0 +1,49 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*
+
+ *
+ * Example of minimal program running under PAL.
+ *
+ * Run it using:
+ * export PAL_DBG_CHANNELS="+all.all"
+ * export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:..
+ * ./example1
+ *
+ * With the PAL_DEBUG_CHANNELS environment variable set as above you
+ * should see a trace output when the program runs. Setting
+ * LD_LIBRARY_PATH is necessary unless you have installed librotor_pal.so in
+ * a standard location.
+ *
+ * Build notes :
+ * Since the PAL uses pthreads, some options must be passed to gcc to tell it
+ * to link against thread-safe versions of the standard libraries.
+ * On FreeBSD, use gcc -pthread
+ *
+ */
+
+#include <pal.h>
+extern void *dlopen(const char *file, int mode);
+
+int main(int argc, char *argv[])
+{
+ WCHAR src[4] = {'f', 'o', 'o', '\0'};
+ WCHAR dest[4] = {'b', 'a', 'r', '\0'};
+ WCHAR dir[5] = {'/', 't', 'm', 'p', '\0'};
+ HANDLE h;
+ unsigned int b;
+
+ PAL_Initialize(argc, (const char**)argv);
+ SetCurrentDirectoryW(dir);
+ SetCurrentDirectoryW(dir);
+ h = CreateFileW(src, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, 0, NULL);
+ WriteFile(h, "Testing\n", 8, &b, FALSE);
+ CloseHandle(h);
+ CopyFileW(src, dest, FALSE);
+ DeleteFileW(src);
+ PAL_Terminate();
+ return 0;
+}
+