platform.h
author Ryan C. Gordon <icculus@icculus.org>
Sun, 20 May 2007 23:24:36 +0000
changeset 299 2ff4115d3f7c
parent 283 421ccfedd6c6
child 330 f16535778126
permissions -rw-r--r--
A shot at a kludge for launching a different binary from inside the Base
Archive, so you can download/run a 32-bit installer but launch a real 64-bit
process...this may help with amd64 systems that, say, have GTK+ support in
the normal system, but not in their 32-bit compatibility layer.
icculus@249
     1
/**
icculus@249
     2
 * MojoSetup; a portable, flexible installation application.
icculus@249
     3
 *
icculus@249
     4
 * Please see the file LICENSE.txt in the source's root directory.
icculus@249
     5
 *
icculus@249
     6
 *  This file written by Ryan C. Gordon.
icculus@249
     7
 */
icculus@249
     8
icculus@5
     9
#ifndef _INCL_PLATFORM_H_
icculus@5
    10
#define _INCL_PLATFORM_H_
icculus@5
    11
icculus@5
    12
#include "universal.h"
icculus@5
    13
icculus@5
    14
#ifdef __cplusplus
icculus@5
    15
extern "C" {
icculus@5
    16
#endif
icculus@5
    17
icculus@10
    18
// this is called by your mainline.
icculus@8
    19
int MojoSetup_main(int argc, char **argv);
icculus@5
    20
icculus@69
    21
// Caller must free returned string!
icculus@70
    22
char *MojoPlatform_appBinaryPath(void);
icculus@14
    23
icculus@234
    24
// Caller must free returned string!
icculus@299
    25
char *MojoPlatform_currentWorkingDir(void);
icculus@299
    26
icculus@299
    27
// Caller must free returned string!
icculus@234
    28
char *MojoPlatform_homedir(void);
icculus@234
    29
icculus@44
    30
uint32 MojoPlatform_ticks(void);
icculus@44
    31
icculus@64
    32
// Make current process kill itself immediately, without any sort of internal
icculus@64
    33
//  cleanup, like atexit() handlers or static destructors...the OS will have
icculus@64
    34
//  to sort out the freeing of any resources, and no more code in this
icculus@64
    35
//  process than necessary should run. This function does not return. Try to
icculus@64
    36
//  avoid calling this.
icculus@64
    37
void MojoPlatform_die(void);
icculus@64
    38
icculus@189
    39
// Delete a file from the physical filesystem. This should remove empty
icculus@189
    40
//  directories as well as files. Returns true on success, false on failure.
icculus@77
    41
boolean MojoPlatform_unlink(const char *fname);
icculus@77
    42
icculus@104
    43
// Resolve symlinks, relative paths, etc. Caller free()'s buffer. Returns
icculus@104
    44
//  NULL if path couldn't be resolved.
icculus@104
    45
char *MojoPlatform_realpath(const char *path);
icculus@104
    46
icculus@145
    47
// Create a symlink in the physical filesystem. (src) is the NAME OF THE LINK
icculus@145
    48
//  and (dst) is WHAT IT POINTS TO. This is backwards from the unix symlink()
icculus@145
    49
//  syscall! Returns true if link was created, false otherwise.
icculus@145
    50
boolean MojoPlatform_symlink(const char *src, const char *dst);
icculus@145
    51
icculus@145
    52
// !!! FIXME: comment me.
icculus@283
    53
boolean MojoPlatform_mkdir(const char *path, uint16 perms);
icculus@145
    54
icculus@145
    55
// Move a file to a new name. This has to be a fast (if not atomic) operation,
icculus@145
    56
//  so if it would require a legitimate copy to another filesystem or device,
icculus@145
    57
//  this should fail, as the standard Unix rename() function does.
icculus@145
    58
// Returns true on successful rename, false otherwise.
icculus@145
    59
boolean MojoPlatform_rename(const char *src, const char *dst);
icculus@145
    60
icculus@131
    61
// !!! FIXME: comment me.
icculus@131
    62
boolean MojoPlatform_exists(const char *dir, const char *fname);
icculus@131
    63
icculus@131
    64
// !!! FIXME: comment me.
icculus@237
    65
boolean MojoPlatform_writable(const char *fname);
icculus@237
    66
icculus@237
    67
// !!! FIXME: comment me.
icculus@237
    68
boolean MojoPlatform_isdir(const char *dir);
icculus@237
    69
icculus@237
    70
// !!! FIXME: comment me.
icculus@155
    71
boolean MojoPlatform_perms(const char *fname, uint16 *p);
icculus@155
    72
icculus@155
    73
// !!! FIXME: comment me.
icculus@155
    74
boolean MojoPlatform_chmod(const char *fname, uint16 p);
icculus@155
    75
icculus@155
    76
// !!! FIXME: comment me.
icculus@131
    77
char *MojoPlatform_findMedia(const char *uniquefile);
icculus@131
    78
icculus@283
    79
// Convert a string into a permissions bitmask. On Unix, this is currently
icculus@283
    80
//  expected to be an octal string like "0755", but may except other forms
icculus@283
    81
//  in the future, and other platforms may need to interpret permissions
icculus@283
    82
//  differently. (str) may be NULL for defaults, and is considered valid.
icculus@283
    83
// If (str) is not valid, return a reasonable default and set (*valid) to
icculus@283
    84
//  false. Otherwise, set (*valid) to true and return the converted value.
icculus@283
    85
uint16 MojoPlatform_makePermissions(const char *str, boolean *valid);
icculus@283
    86
icculus@283
    87
// Return a default, sane set of permissions for a newly-created file.
icculus@283
    88
uint16 MojoPlatform_defaultFilePerms(void);
icculus@283
    89
icculus@283
    90
// Return a default, sane set of permissions for a newly-created directory.
icculus@283
    91
uint16 MojoPlatform_defaultDirPerms(void);
icculus@283
    92
icculus@82
    93
// Wrappers for Unix dlopen/dlsym/dlclose, sort of. Instead of a filename,
icculus@82
    94
//  these take a memory buffer for the library. If you can't load this
icculus@82
    95
//  directly in RAM, the platform should write it to a temporary file first,
icculus@82
    96
//  and deal with cleanup in MojoPlatform_dlclose(). The memory buffer must be
icculus@82
    97
//  dereferenced in MojoPlatform_dlopen(), as the caller may free() it upon
icculus@82
    98
//  return. Everything else works like the usual Unix calls.
icculus@82
    99
void *MojoPlatform_dlopen(const uint8 *img, size_t len);
icculus@77
   100
void *MojoPlatform_dlsym(void *lib, const char *sym);
icculus@77
   101
void MojoPlatform_dlclose(void *lib);
icculus@77
   102
icculus@299
   103
#if !SUPPORT_MULTIARCH
icculus@299
   104
#define MojoPlatform_switchBin(img, len)
icculus@299
   105
#else
icculus@299
   106
void MojoPlatform_switchBin(const uint8 *img, size_t len);
icculus@299
   107
#endif
icculus@299
   108
icculus@185
   109
// Put the calling process to sleep for at least (ticks) milliseconds.
icculus@185
   110
//  This is meant to yield the CPU while spinning in a loop that is polling
icculus@185
   111
//  for input, etc. Pumping the GUI event queue happens elsewhere, not here.
icculus@185
   112
void MojoPlatform_sleep(uint32 ticks);
icculus@131
   113
icculus@89
   114
// Put a line of text to the the system log, whatever that might be on a
icculus@89
   115
//  given platform. (str) is a complete line, but won't end with any newline
icculus@89
   116
//  characters. You should supply if needed.
icculus@89
   117
void MojoPlatform_log(const char *str);
icculus@89
   118
icculus@39
   119
// Get the current locale, in the format "xx_YY" where "xx" is the language
icculus@39
   120
//  (en, fr, de...) and "_YY" is the country. (_US, _CA, etc). The country
icculus@39
   121
//  can be omitted. Don't include encoding, it's always UTF-8 at this time.
icculus@39
   122
// Return true if locale is known, false otherwise.
icculus@39
   123
boolean MojoPlatform_locale(char *buf, size_t len);
icculus@39
   124
icculus@43
   125
boolean MojoPlatform_osType(char *buf, size_t len);
icculus@43
   126
boolean MojoPlatform_osVersion(char *buf, size_t len);
icculus@43
   127
icculus@43
   128
// Basic platform detection.
icculus@43
   129
#if PLATFORM_WINDOWS
icculus@43
   130
#define PLATFORM_NAME "windows"
icculus@43
   131
#elif PLATFORM_MACOSX
icculus@43
   132
#define PLATFORM_NAME "macosx"
icculus@43
   133
#elif PLATFORM_UNIX
icculus@43
   134
#define PLATFORM_NAME "unix"
icculus@98
   135
#elif PLATFORM_BEOS
icculus@98
   136
#define PLATFORM_NAME "beos"
icculus@43
   137
#else
icculus@82
   138
#error Unknown platform.
icculus@43
   139
#endif
icculus@43
   140
icculus@43
   141
// Basic architecture detection.
icculus@43
   142
icculus@43
   143
#if defined(__powerpc64__)
icculus@43
   144
#define PLATFORM_ARCH "powerpc64"
icculus@43
   145
#elif defined(__ppc__) || defined(__powerpc__) || defined(__POWERPC__)
icculus@43
   146
#define PLATFORM_ARCH "powerpc"
icculus@43
   147
#elif defined(__x86_64__) || defined(_M_X64)
icculus@43
   148
#define PLATFORM_ARCH "x86-64"
icculus@43
   149
#elif defined(__X86__) || defined(__i386__) || defined(i386) || defined (_M_IX86) || defined(__386__)
icculus@43
   150
#define PLATFORM_ARCH "x86"
icculus@43
   151
#else
icculus@43
   152
#error Unknown processor architecture.
icculus@43
   153
#endif
icculus@43
   154
icculus@5
   155
#ifdef __cplusplus
icculus@5
   156
}
icculus@5
   157
#endif
icculus@5
   158
icculus@5
   159
#endif
icculus@5
   160
icculus@10
   161
// end of platform.h ...
icculus@5
   162