summaryrefslogtreecommitdiff
path: root/src/pal/src/examples/example1.cpp
blob: 071f42e4f9142278150bfa0b23c48092a4775954 (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
48
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;
}