Skip to content

Latest commit

 

History

History
91 lines (72 loc) · 2.96 KB

platform.h

File metadata and controls

91 lines (72 loc) · 2.96 KB
 
1
2
3
4
5
6
7
8
9
#ifndef _INCL_PLATFORM_H_
#define _INCL_PLATFORM_H_
#include "universal.h"
#ifdef __cplusplus
extern "C" {
#endif
Mar 25, 2006
Mar 25, 2006
10
// this is called by your mainline.
Mar 25, 2006
Mar 25, 2006
11
int MojoSetup_main(int argc, char **argv);
Dec 9, 2006
Dec 9, 2006
13
// Caller must free returned string!
Dec 9, 2006
Dec 9, 2006
14
char *MojoPlatform_appBinaryPath(void);
Mar 25, 2006
Mar 25, 2006
15
Dec 4, 2006
Dec 4, 2006
16
17
uint32 MojoPlatform_ticks(void);
Dec 9, 2006
Dec 9, 2006
18
19
20
21
22
23
24
// Make current process kill itself immediately, without any sort of internal
// cleanup, like atexit() handlers or static destructors...the OS will have
// to sort out the freeing of any resources, and no more code in this
// process than necessary should run. This function does not return. Try to
// avoid calling this.
void MojoPlatform_die(void);
Dec 9, 2006
Dec 9, 2006
25
26
27
28
// Delete a file from the physical filesystem. Returns true on success, false
// on failure.
boolean MojoPlatform_unlink(const char *fname);
Dec 14, 2006
Dec 14, 2006
29
30
31
32
// Resolve symlinks, relative paths, etc. Caller free()'s buffer. Returns
// NULL if path couldn't be resolved.
char *MojoPlatform_realpath(const char *path);
Dec 9, 2006
Dec 9, 2006
33
34
35
36
37
38
39
// Wrappers for Unix dlopen/dlsym/dlclose, sort of. Instead of a filename,
// these take a memory buffer for the library. If you can't load this
// directly in RAM, the platform should write it to a temporary file first,
// and deal with cleanup in MojoPlatform_dlclose(). The memory buffer must be
// dereferenced in MojoPlatform_dlopen(), as the caller may free() it upon
// return. Everything else works like the usual Unix calls.
void *MojoPlatform_dlopen(const uint8 *img, size_t len);
Dec 9, 2006
Dec 9, 2006
40
41
42
void *MojoPlatform_dlsym(void *lib, const char *sym);
void MojoPlatform_dlclose(void *lib);
Dec 10, 2006
Dec 10, 2006
43
44
45
46
47
// Put a line of text to the the system log, whatever that might be on a
// given platform. (str) is a complete line, but won't end with any newline
// characters. You should supply if needed.
void MojoPlatform_log(const char *str);
Dec 3, 2006
Dec 3, 2006
48
49
50
51
52
53
// Get the current locale, in the format "xx_YY" where "xx" is the language
// (en, fr, de...) and "_YY" is the country. (_US, _CA, etc). The country
// can be omitted. Don't include encoding, it's always UTF-8 at this time.
// Return true if locale is known, false otherwise.
boolean MojoPlatform_locale(char *buf, size_t len);
Dec 4, 2006
Dec 4, 2006
54
55
56
57
58
59
60
61
62
63
boolean MojoPlatform_osType(char *buf, size_t len);
boolean MojoPlatform_osVersion(char *buf, size_t len);
// Basic platform detection.
#if PLATFORM_WINDOWS
#define PLATFORM_NAME "windows"
#elif PLATFORM_MACOSX
#define PLATFORM_NAME "macosx"
#elif PLATFORM_UNIX
#define PLATFORM_NAME "unix"
Dec 13, 2006
Dec 13, 2006
64
65
#elif PLATFORM_BEOS
#define PLATFORM_NAME "beos"
Dec 4, 2006
Dec 4, 2006
66
#else
Dec 9, 2006
Dec 9, 2006
67
#error Unknown platform.
Dec 4, 2006
Dec 4, 2006
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#endif
// Basic architecture detection.
#if defined(__powerpc64__)
#define PLATFORM_ARCH "powerpc64"
#elif defined(__ppc__) || defined(__powerpc__) || defined(__POWERPC__)
#define PLATFORM_ARCH "powerpc"
#elif defined(__x86_64__) || defined(_M_X64)
#define PLATFORM_ARCH "x86-64"
#elif defined(__X86__) || defined(__i386__) || defined(i386) || defined (_M_IX86) || defined(__386__)
#define PLATFORM_ARCH "x86"
#else
#error Unknown processor architecture.
#endif
84
85
86
87
88
89
#ifdef __cplusplus
}
#endif
#endif
Mar 25, 2006
Mar 25, 2006
90
// end of platform.h ...