Skip to content

Latest commit

 

History

History
153 lines (119 loc) · 5.43 KB

platform.h

File metadata and controls

153 lines (119 loc) · 5.43 KB
 
May 12, 2007
May 12, 2007
1
2
3
4
5
6
7
8
/**
* MojoSetup; a portable, flexible installation application.
*
* Please see the file LICENSE.txt in the source's root directory.
*
* This file written by Ryan C. Gordon.
*/
9
10
11
12
13
14
15
16
17
#ifndef _INCL_PLATFORM_H_
#define _INCL_PLATFORM_H_
#include "universal.h"
#ifdef __cplusplus
extern "C" {
#endif
Mar 25, 2006
Mar 25, 2006
18
// this is called by your mainline.
Mar 25, 2006
Mar 25, 2006
19
int MojoSetup_main(int argc, char **argv);
Dec 9, 2006
Dec 9, 2006
21
// Caller must free returned string!
Dec 9, 2006
Dec 9, 2006
22
char *MojoPlatform_appBinaryPath(void);
Mar 25, 2006
Mar 25, 2006
23
May 10, 2007
May 10, 2007
24
25
26
// Caller must free returned string!
char *MojoPlatform_homedir(void);
Dec 4, 2006
Dec 4, 2006
27
28
uint32 MojoPlatform_ticks(void);
Dec 9, 2006
Dec 9, 2006
29
30
31
32
33
34
35
// 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);
May 7, 2007
May 7, 2007
36
37
// Delete a file from the physical filesystem. This should remove empty
// directories as well as files. Returns true on success, false on failure.
Dec 9, 2006
Dec 9, 2006
38
39
boolean MojoPlatform_unlink(const char *fname);
Dec 14, 2006
Dec 14, 2006
40
41
42
43
// Resolve symlinks, relative paths, etc. Caller free()'s buffer. Returns
// NULL if path couldn't be resolved.
char *MojoPlatform_realpath(const char *path);
May 1, 2007
May 1, 2007
44
45
46
47
48
49
// Create a symlink in the physical filesystem. (src) is the NAME OF THE LINK
// and (dst) is WHAT IT POINTS TO. This is backwards from the unix symlink()
// syscall! Returns true if link was created, false otherwise.
boolean MojoPlatform_symlink(const char *src, const char *dst);
// !!! FIXME: comment me.
May 18, 2007
May 18, 2007
50
boolean MojoPlatform_mkdir(const char *path, uint16 perms);
May 1, 2007
May 1, 2007
51
52
53
54
55
56
57
// Move a file to a new name. This has to be a fast (if not atomic) operation,
// so if it would require a legitimate copy to another filesystem or device,
// this should fail, as the standard Unix rename() function does.
// Returns true on successful rename, false otherwise.
boolean MojoPlatform_rename(const char *src, const char *dst);
Apr 22, 2007
Apr 22, 2007
58
59
60
// !!! FIXME: comment me.
boolean MojoPlatform_exists(const char *dir, const char *fname);
May 10, 2007
May 10, 2007
61
62
63
64
65
66
// !!! FIXME: comment me.
boolean MojoPlatform_writable(const char *fname);
// !!! FIXME: comment me.
boolean MojoPlatform_isdir(const char *dir);
May 3, 2007
May 3, 2007
67
68
69
70
71
72
// !!! FIXME: comment me.
boolean MojoPlatform_perms(const char *fname, uint16 *p);
// !!! FIXME: comment me.
boolean MojoPlatform_chmod(const char *fname, uint16 p);
Apr 22, 2007
Apr 22, 2007
73
74
75
// !!! FIXME: comment me.
char *MojoPlatform_findMedia(const char *uniquefile);
May 18, 2007
May 18, 2007
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Convert a string into a permissions bitmask. On Unix, this is currently
// expected to be an octal string like "0755", but may except other forms
// in the future, and other platforms may need to interpret permissions
// differently. (str) may be NULL for defaults, and is considered valid.
// If (str) is not valid, return a reasonable default and set (*valid) to
// false. Otherwise, set (*valid) to true and return the converted value.
uint16 MojoPlatform_makePermissions(const char *str, boolean *valid);
// Return a default, sane set of permissions for a newly-created file.
uint16 MojoPlatform_defaultFilePerms(void);
// Return a default, sane set of permissions for a newly-created directory.
uint16 MojoPlatform_defaultDirPerms(void);
Dec 9, 2006
Dec 9, 2006
90
91
92
93
94
95
96
// 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
97
98
99
void *MojoPlatform_dlsym(void *lib, const char *sym);
void MojoPlatform_dlclose(void *lib);
May 7, 2007
May 7, 2007
100
101
102
103
// Put the calling process to sleep for at least (ticks) milliseconds.
// This is meant to yield the CPU while spinning in a loop that is polling
// for input, etc. Pumping the GUI event queue happens elsewhere, not here.
void MojoPlatform_sleep(uint32 ticks);
Apr 22, 2007
Apr 22, 2007
104
Dec 10, 2006
Dec 10, 2006
105
106
107
108
109
// 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
110
111
112
113
114
115
// 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
116
117
118
119
120
121
122
123
124
125
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
126
127
#elif PLATFORM_BEOS
#define PLATFORM_NAME "beos"
Dec 4, 2006
Dec 4, 2006
128
#else
Dec 9, 2006
Dec 9, 2006
129
#error Unknown platform.
Dec 4, 2006
Dec 4, 2006
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#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
146
147
148
149
150
151
#ifdef __cplusplus
}
#endif
#endif
Mar 25, 2006
Mar 25, 2006
152
// end of platform.h ...