platform.h
author Ryan C. Gordon <icculus@icculus.org>
Thu, 18 Jun 2015 12:18:57 -0400
changeset 879 c2afc800b743
parent 805 4730a8dacfdd
permissions -rw-r--r--
Assorted spelling fixes (thanks, Francois!).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
249
220047a6719f Added licensing information to everything.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
     1
/**
220047a6719f Added licensing information to everything.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
     2
 * MojoSetup; a portable, flexible installation application.
220047a6719f Added licensing information to everything.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
     3
 *
220047a6719f Added licensing information to everything.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
     4
 * Please see the file LICENSE.txt in the source's root directory.
220047a6719f Added licensing information to everything.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
     5
 *
220047a6719f Added licensing information to everything.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
     6
 *  This file written by Ryan C. Gordon.
220047a6719f Added licensing information to everything.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
     7
 */
220047a6719f Added licensing information to everything.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
     8
5
92ac7b75db5d Added a bunch of structure, lots stolen from lighting.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
#ifndef _INCL_PLATFORM_H_
92ac7b75db5d Added a bunch of structure, lots stolen from lighting.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
#define _INCL_PLATFORM_H_
92ac7b75db5d Added a bunch of structure, lots stolen from lighting.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
92ac7b75db5d Added a bunch of structure, lots stolen from lighting.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
#include "universal.h"
92ac7b75db5d Added a bunch of structure, lots stolen from lighting.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
92ac7b75db5d Added a bunch of structure, lots stolen from lighting.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
#ifdef __cplusplus
92ac7b75db5d Added a bunch of structure, lots stolen from lighting.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
extern "C" {
92ac7b75db5d Added a bunch of structure, lots stolen from lighting.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
#endif
92ac7b75db5d Added a bunch of structure, lots stolen from lighting.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
10
d1f47c44bcdb Screw it, I'm using C++-style comments. If a compelling reason comes up to
Ryan C. Gordon <icculus@icculus.org>
parents: 8
diff changeset
    18
// this is called by your mainline.
8
7c47d20a4da8 A ton of work...slouching towards basic startup functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 5
diff changeset
    19
int MojoSetup_main(int argc, char **argv);
5
92ac7b75db5d Added a bunch of structure, lots stolen from lighting.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
69
7fbd50eb9de9 FIXME removal...appBinaryPath() returns a malloc()'d string, that caller must
Ryan C. Gordon <icculus@icculus.org>
parents: 64
diff changeset
    21
// Caller must free returned string!
70
6fdee5364ba9 Patched to compile...also, since appBinaryPath() returns a malloc()'d string
Ryan C. Gordon <icculus@icculus.org>
parents: 69
diff changeset
    22
char *MojoPlatform_appBinaryPath(void);
14
977ff37b4544 More mangling.
Ryan C. Gordon <icculus@icculus.org>
parents: 10
diff changeset
    23
234
32f44c3c43ea Added MojoSetup.info.homedir string.
Ryan C. Gordon <icculus@icculus.org>
parents: 189
diff changeset
    24
// Caller must free returned string!
299
2ff4115d3f7c A shot at a kludge for launching a different binary from inside the Base
Ryan C. Gordon <icculus@icculus.org>
parents: 283
diff changeset
    25
char *MojoPlatform_currentWorkingDir(void);
2ff4115d3f7c A shot at a kludge for launching a different binary from inside the Base
Ryan C. Gordon <icculus@icculus.org>
parents: 283
diff changeset
    26
2ff4115d3f7c A shot at a kludge for launching a different binary from inside the Base
Ryan C. Gordon <icculus@icculus.org>
parents: 283
diff changeset
    27
// Caller must free returned string!
234
32f44c3c43ea Added MojoSetup.info.homedir string.
Ryan C. Gordon <icculus@icculus.org>
parents: 189
diff changeset
    28
char *MojoPlatform_homedir(void);
32f44c3c43ea Added MojoSetup.info.homedir string.
Ryan C. Gordon <icculus@icculus.org>
parents: 189
diff changeset
    29
44
dee75f6e7ddb Added ticks counting.
Ryan C. Gordon <icculus@icculus.org>
parents: 43
diff changeset
    30
uint32 MojoPlatform_ticks(void);
dee75f6e7ddb Added ticks counting.
Ryan C. Gordon <icculus@icculus.org>
parents: 43
diff changeset
    31
64
0ef258e23558 FIXME cleanup...don't use _exit() directly, but wrap it in the platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
    32
// Make current process kill itself immediately, without any sort of internal
0ef258e23558 FIXME cleanup...don't use _exit() directly, but wrap it in the platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
    33
//  cleanup, like atexit() handlers or static destructors...the OS will have
0ef258e23558 FIXME cleanup...don't use _exit() directly, but wrap it in the platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
    34
//  to sort out the freeing of any resources, and no more code in this
0ef258e23558 FIXME cleanup...don't use _exit() directly, but wrap it in the platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
    35
//  process than necessary should run. This function does not return. Try to
0ef258e23558 FIXME cleanup...don't use _exit() directly, but wrap it in the platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
    36
//  avoid calling this.
0ef258e23558 FIXME cleanup...don't use _exit() directly, but wrap it in the platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
    37
void MojoPlatform_die(void);
0ef258e23558 FIXME cleanup...don't use _exit() directly, but wrap it in the platform layer.
Ryan C. Gordon <icculus@icculus.org>
parents: 44
diff changeset
    38
189
269764ece9af Implemented error handling: removal of half-written installs and rollback of
Ryan C. Gordon <icculus@icculus.org>
parents: 185
diff changeset
    39
// Delete a file from the physical filesystem. This should remove empty
269764ece9af Implemented error handling: removal of half-written installs and rollback of
Ryan C. Gordon <icculus@icculus.org>
parents: 185
diff changeset
    40
//  directories as well as files. Returns true on success, false on failure.
77
26863adbc056 FIXME removal: abstract out some Unixy things.
Ryan C. Gordon <icculus@icculus.org>
parents: 70
diff changeset
    41
boolean MojoPlatform_unlink(const char *fname);
26863adbc056 FIXME removal: abstract out some Unixy things.
Ryan C. Gordon <icculus@icculus.org>
parents: 70
diff changeset
    42
104
af286638e446 Rolled my own realpath(), which solves some problems.
Ryan C. Gordon <icculus@icculus.org>
parents: 98
diff changeset
    43
// Resolve symlinks, relative paths, etc. Caller free()'s buffer. Returns
af286638e446 Rolled my own realpath(), which solves some problems.
Ryan C. Gordon <icculus@icculus.org>
parents: 98
diff changeset
    44
//  NULL if path couldn't be resolved.
af286638e446 Rolled my own realpath(), which solves some problems.
Ryan C. Gordon <icculus@icculus.org>
parents: 98
diff changeset
    45
char *MojoPlatform_realpath(const char *path);
af286638e446 Rolled my own realpath(), which solves some problems.
Ryan C. Gordon <icculus@icculus.org>
parents: 98
diff changeset
    46
145
5e8a71c933e0 A metric ton of work on the main install loop and all the million support
Ryan C. Gordon <icculus@icculus.org>
parents: 131
diff changeset
    47
// Create a symlink in the physical filesystem. (src) is the NAME OF THE LINK
5e8a71c933e0 A metric ton of work on the main install loop and all the million support
Ryan C. Gordon <icculus@icculus.org>
parents: 131
diff changeset
    48
//  and (dst) is WHAT IT POINTS TO. This is backwards from the unix symlink()
5e8a71c933e0 A metric ton of work on the main install loop and all the million support
Ryan C. Gordon <icculus@icculus.org>
parents: 131
diff changeset
    49
//  syscall! Returns true if link was created, false otherwise.
5e8a71c933e0 A metric ton of work on the main install loop and all the million support
Ryan C. Gordon <icculus@icculus.org>
parents: 131
diff changeset
    50
boolean MojoPlatform_symlink(const char *src, const char *dst);
5e8a71c933e0 A metric ton of work on the main install loop and all the million support
Ryan C. Gordon <icculus@icculus.org>
parents: 131
diff changeset
    51
330
f16535778126 Whoops, apparently stat::st_size isn't set to the string length of a symlink's
Ryan C. Gordon <icculus@icculus.org>
parents: 299
diff changeset
    52
// Read the destination from symlink (linkname). Returns a pointer
f16535778126 Whoops, apparently stat::st_size isn't set to the string length of a symlink's
Ryan C. Gordon <icculus@icculus.org>
parents: 299
diff changeset
    53
//  allocated with xmalloc() containing the linkdest on success, and NULL
f16535778126 Whoops, apparently stat::st_size isn't set to the string length of a symlink's
Ryan C. Gordon <icculus@icculus.org>
parents: 299
diff changeset
    54
//  on failure. The caller is responsible for freeing the returned pointer!
f16535778126 Whoops, apparently stat::st_size isn't set to the string length of a symlink's
Ryan C. Gordon <icculus@icculus.org>
parents: 299
diff changeset
    55
char *MojoPlatform_readlink(const char *linkname);
f16535778126 Whoops, apparently stat::st_size isn't set to the string length of a symlink's
Ryan C. Gordon <icculus@icculus.org>
parents: 299
diff changeset
    56
345
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
    57
// !!! FIXME: we really can't do this in a 16-bit value...non-Unix platforms
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
    58
// !!! FIXME:  and Extended Attributes need more.
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
    59
// Create a directory in the physical filesystem, with (perms) permissions.
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
    60
//  returns true if directory is created, false otherwise.
283
421ccfedd6c6 Permissions support...let mkdir set permissions, and let config file specify
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
    61
boolean MojoPlatform_mkdir(const char *path, uint16 perms);
145
5e8a71c933e0 A metric ton of work on the main install loop and all the million support
Ryan C. Gordon <icculus@icculus.org>
parents: 131
diff changeset
    62
5e8a71c933e0 A metric ton of work on the main install loop and all the million support
Ryan C. Gordon <icculus@icculus.org>
parents: 131
diff changeset
    63
// Move a file to a new name. This has to be a fast (if not atomic) operation,
5e8a71c933e0 A metric ton of work on the main install loop and all the million support
Ryan C. Gordon <icculus@icculus.org>
parents: 131
diff changeset
    64
//  so if it would require a legitimate copy to another filesystem or device,
5e8a71c933e0 A metric ton of work on the main install loop and all the million support
Ryan C. Gordon <icculus@icculus.org>
parents: 131
diff changeset
    65
//  this should fail, as the standard Unix rename() function does.
5e8a71c933e0 A metric ton of work on the main install loop and all the million support
Ryan C. Gordon <icculus@icculus.org>
parents: 131
diff changeset
    66
// Returns true on successful rename, false otherwise.
5e8a71c933e0 A metric ton of work on the main install loop and all the million support
Ryan C. Gordon <icculus@icculus.org>
parents: 131
diff changeset
    67
boolean MojoPlatform_rename(const char *src, const char *dst);
5e8a71c933e0 A metric ton of work on the main install loop and all the million support
Ryan C. Gordon <icculus@icculus.org>
parents: 131
diff changeset
    68
345
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
    69
// Determine if dir/fname exists in the native filesystem. It doesn't matter
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
    70
//  if it's a directory, file, symlink, etc, we're just looking for the
879
c2afc800b743 Assorted spelling fixes (thanks, Francois!).
Ryan C. Gordon <icculus@icculus.org>
parents: 805
diff changeset
    71
//  existence of the entry itself. (fname) may be NULL, in which case,
345
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
    72
//  (dir) contains the whole path, otherwise, the platform layer needs to
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
    73
//  build the path: (on Unix: dir/path, on Windows: dir\\path, etc).
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
    74
//  This is a convenience thing for the caller.
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
    75
// Returns true if path in question exists, false otherwise.
131
c00506a75a2b Media detection code. Also untested. :/
Ryan C. Gordon <icculus@icculus.org>
parents: 104
diff changeset
    76
boolean MojoPlatform_exists(const char *dir, const char *fname);
c00506a75a2b Media detection code. Also untested. :/
Ryan C. Gordon <icculus@icculus.org>
parents: 104
diff changeset
    77
345
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
    78
// Returns true if (fname) in the native filesystem is writable. If (fname)
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
    79
//  is a directory, this means that the contents of the directory can be
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
    80
//  added to (create files, delete files, etc). If (fname) is a file, this
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
    81
//  means that this process has write access to the file.
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
    82
// Returns false if (fname) isn't writable.
237
feeb6f10e2c6 Only recommend paths that exist and can be written into by the current user.
Ryan C. Gordon <icculus@icculus.org>
parents: 234
diff changeset
    83
boolean MojoPlatform_writable(const char *fname);
feeb6f10e2c6 Only recommend paths that exist and can be written into by the current user.
Ryan C. Gordon <icculus@icculus.org>
parents: 234
diff changeset
    84
345
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
    85
// Returns true if (dir) is a directory in the physical filesystem, false
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
    86
//  otherwise (including if (dir) doesn't exist). Don't follow symlinks.
237
feeb6f10e2c6 Only recommend paths that exist and can be written into by the current user.
Ryan C. Gordon <icculus@icculus.org>
parents: 234
diff changeset
    87
boolean MojoPlatform_isdir(const char *dir);
feeb6f10e2c6 Only recommend paths that exist and can be written into by the current user.
Ryan C. Gordon <icculus@icculus.org>
parents: 234
diff changeset
    88
345
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
    89
// Returns true if (fname) is a symlink in the physical filesystem, false
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
    90
//  otherwise (including if (fname) doesn't exist). Don't follow symlinks.
339
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
    91
boolean MojoPlatform_issymlink(const char *fname);
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
    92
369
f6c0eff5a144 Spawn a terminal if we aren't using one and found no functioning GUI plugins.
Ryan C. Gordon <icculus@icculus.org>
parents: 345
diff changeset
    93
// Returns true if stdin and stdout are connected to a tty.
f6c0eff5a144 Spawn a terminal if we aren't using one and found no functioning GUI plugins.
Ryan C. Gordon <icculus@icculus.org>
parents: 345
diff changeset
    94
boolean MojoPlatform_istty(void);
f6c0eff5a144 Spawn a terminal if we aren't using one and found no functioning GUI plugins.
Ryan C. Gordon <icculus@icculus.org>
parents: 345
diff changeset
    95
345
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
    96
// Returns true if (fname) is a regular file in the physical filesystem, false
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
    97
//  otherwise (including if (fname) doesn't exist). Don't follow symlinks.
339
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
    98
boolean MojoPlatform_isfile(const char *fname);
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
    99
345
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   100
// Returns size, in bytes, of the file (fname) in the physical filesystem.
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   101
//  Return -1 if file is missing or not a file. Don't follow symlinks.
339
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   102
int64 MojoPlatform_filesize(const char *fname);
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   103
345
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   104
// !!! FIXME: we really can't do this in a 16-bit value...non-Unix platforms
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   105
// !!! FIXME:  and Extended Attributes need more.
339
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   106
// !!! FIXME: comment me.
155
fb27b89fb51f Initial file permission work.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   107
boolean MojoPlatform_perms(const char *fname, uint16 *p);
fb27b89fb51f Initial file permission work.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   108
345
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   109
// !!! FIXME: we really can't do this in a 16-bit value...non-Unix platforms
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   110
// !!! FIXME:  and Extended Attributes need more.
155
fb27b89fb51f Initial file permission work.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   111
// !!! FIXME: comment me.
fb27b89fb51f Initial file permission work.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   112
boolean MojoPlatform_chmod(const char *fname, uint16 p);
fb27b89fb51f Initial file permission work.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   113
345
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   114
// Try to locate a specific piece of media (usually an inserted CD or DVD).
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   115
//  (uniquefile) is a path that should exist on the media; its presence
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   116
//  should uniquely identify the media.
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   117
// Returns the path of the media's mount point in the physical filesystem
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   118
//  (something like "E:\\" on Windows or "/mnt/cdrom" on Unix), or NULL if
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   119
//  the media isn't found (needed disc isn't inserted, etc).
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   120
// Caller must free return value!
131
c00506a75a2b Media detection code. Also untested. :/
Ryan C. Gordon <icculus@icculus.org>
parents: 104
diff changeset
   121
char *MojoPlatform_findMedia(const char *uniquefile);
c00506a75a2b Media detection code. Also untested. :/
Ryan C. Gordon <icculus@icculus.org>
parents: 104
diff changeset
   122
339
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   123
// Flag values for MojoPlatform_fopen().
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   124
typedef enum
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   125
{
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   126
    MOJOFILE_READ=(1<<0),
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   127
    MOJOFILE_WRITE=(1<<1),
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   128
    MOJOFILE_CREATE=(1<<2),
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   129
    MOJOFILE_EXCLUSIVE=(1<<3),
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   130
    MOJOFILE_TRUNCATE=(1<<4),
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   131
    MOJOFILE_APPEND=(1<<5),
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   132
} MojoFileFlags;
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   133
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   134
typedef enum
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   135
{
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   136
    MOJOSEEK_SET,
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   137
    MOJOSEEK_CURRENT,
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   138
    MOJOSEEK_END
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   139
} MojoFileSeek;
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   140
345
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   141
// !!! FIXME: we really can't do this in a 16-bit value...non-Unix platforms
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   142
// !!! FIXME:  and Extended Attributes need more.
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   143
// Open file (fname). This wraps a subset of the Unix open() syscall. Use
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   144
//  MojoFileFlags for (flags). If creating a file, use (mode) for the new
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   145
//  file's permissions.
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   146
// Returns an opaque handle on success, NULL on error. Caller must free
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   147
//  handle with MojoPlatform_close() when done with it.
339
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   148
void *MojoPlatform_open(const char *fname, uint32 flags, uint16 mode);
345
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   149
411
e5d1865da5ec Lots of FIXME removals, clenaups, and tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 374
diff changeset
   150
// Return a handle that's compatible with MojoPlatform_open()'s return values
e5d1865da5ec Lots of FIXME removals, clenaups, and tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 374
diff changeset
   151
//  that represents stdout. May return NULL for platforms that don't support
e5d1865da5ec Lots of FIXME removals, clenaups, and tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 374
diff changeset
   152
//  this concept. You need to make sure that stdout itself doesn't really
e5d1865da5ec Lots of FIXME removals, clenaups, and tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 374
diff changeset
   153
//  close in MojoPlatform_close(), at least for now.
e5d1865da5ec Lots of FIXME removals, clenaups, and tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 374
diff changeset
   154
void *MojoPlatform_stdout(void);
e5d1865da5ec Lots of FIXME removals, clenaups, and tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 374
diff changeset
   155
345
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   156
// Read (bytes) bytes from (fd) into (buf). This wraps the Unix read() syscall.
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   157
//  Returns number of bytes read, -1 on error.
339
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   158
int64 MojoPlatform_read(void *fd, void *buf, uint32 bytes);
345
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   159
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   160
// Write (bytes) bytes from (buf) into (fd). This wraps the Unix write()
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   161
//  syscall. Returns number of bytes read, -1 on error.
339
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   162
int64 MojoPlatform_write(void *fd, const void *buf, uint32 bytes);
345
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   163
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   164
// Reports byte offset of file pointer in (fd), or -1 on error.
339
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   165
int64 MojoPlatform_tell(void *fd);
345
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   166
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   167
// Seek to (offset) byte offset of file pointer in (fd), relative to (whence).
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   168
//  This wraps the Unix lseek() syscall. Returns byte offset from the start
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   169
//  of the file, -1 on error.
339
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   170
int64 MojoPlatform_seek(void *fd, int64 offset, MojoFileSeek whence);
345
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   171
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   172
// Get the size, in bytes, of a file, referenced by its opaque handle.
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   173
//  (This pulls the data through an fstat() on Unix.) Retuns -1 on error.
339
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   174
int64 MojoPlatform_flen(void *fd);
345
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   175
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   176
// Force any pending data to disk, returns true on success, false if there
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   177
//  was an i/o error.
339
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   178
boolean MojoPlatform_flush(void *fd);
345
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   179
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   180
// Free any resources associated with (fd), flushing any pending data to disk,
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   181
//  and closing the file. (fd) becomes invalid after this call returns
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   182
//  successfully. This wraps the Unix close() syscall. Returns true on
a476d19c5767 Documented some of the platform layer interfaces.
Ryan C. Gordon <icculus@icculus.org>
parents: 339
diff changeset
   183
//  success, false on i/o error.
339
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   184
boolean MojoPlatform_close(void *fd);
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   185
338
a398b3027a4b Some initial work on abstracting Unix-specific bits from fileio.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 330
diff changeset
   186
// Enumerate a directory. Returns an opaque pointer that can be used with
a398b3027a4b Some initial work on abstracting Unix-specific bits from fileio.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 330
diff changeset
   187
//  repeated calls to MojoPlatform_readdir() to enumerate the names of
a398b3027a4b Some initial work on abstracting Unix-specific bits from fileio.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 330
diff changeset
   188
//  directory entries. Returns NULL on error. Non-NULL values should be passed
a398b3027a4b Some initial work on abstracting Unix-specific bits from fileio.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 330
diff changeset
   189
//  to MojoPlatform_closedir() for cleanup when you are done with them.
a398b3027a4b Some initial work on abstracting Unix-specific bits from fileio.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 330
diff changeset
   190
void *MojoPlatform_opendir(const char *dirname);
a398b3027a4b Some initial work on abstracting Unix-specific bits from fileio.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 330
diff changeset
   191
a398b3027a4b Some initial work on abstracting Unix-specific bits from fileio.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 330
diff changeset
   192
// Get the next entry in the directory. (dirhandle) is an opaque pointer
a398b3027a4b Some initial work on abstracting Unix-specific bits from fileio.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 330
diff changeset
   193
//  returned by MojoPlatform_opendir(). Returns NULL if we're at the end of
a398b3027a4b Some initial work on abstracting Unix-specific bits from fileio.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 330
diff changeset
   194
//  the directory, or a null-terminated UTF-8 string otherwise. The order of
a398b3027a4b Some initial work on abstracting Unix-specific bits from fileio.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 330
diff changeset
   195
//  results are not guaranteed, and may change between two iterations.
a398b3027a4b Some initial work on abstracting Unix-specific bits from fileio.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 330
diff changeset
   196
// Caller must free returned string!
a398b3027a4b Some initial work on abstracting Unix-specific bits from fileio.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 330
diff changeset
   197
char *MojoPlatform_readdir(void *dirhandle);
a398b3027a4b Some initial work on abstracting Unix-specific bits from fileio.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 330
diff changeset
   198
a398b3027a4b Some initial work on abstracting Unix-specific bits from fileio.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 330
diff changeset
   199
// Clean up resources used by a directory enumeration. (dirhandle) is an
a398b3027a4b Some initial work on abstracting Unix-specific bits from fileio.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 330
diff changeset
   200
//  opaque pointer returned by MojoPlatform_opendir(), and becomes invalid
a398b3027a4b Some initial work on abstracting Unix-specific bits from fileio.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 330
diff changeset
   201
//  after this call.
a398b3027a4b Some initial work on abstracting Unix-specific bits from fileio.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 330
diff changeset
   202
void MojoPlatform_closedir(void *dirhandle);
a398b3027a4b Some initial work on abstracting Unix-specific bits from fileio.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 330
diff changeset
   203
283
421ccfedd6c6 Permissions support...let mkdir set permissions, and let config file specify
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
   204
// Convert a string into a permissions bitmask. On Unix, this is currently
339
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   205
//  expected to be an octal string like "0755", but may expect other forms
283
421ccfedd6c6 Permissions support...let mkdir set permissions, and let config file specify
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
   206
//  in the future, and other platforms may need to interpret permissions
421ccfedd6c6 Permissions support...let mkdir set permissions, and let config file specify
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
   207
//  differently. (str) may be NULL for defaults, and is considered valid.
421ccfedd6c6 Permissions support...let mkdir set permissions, and let config file specify
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
   208
// If (str) is not valid, return a reasonable default and set (*valid) to
421ccfedd6c6 Permissions support...let mkdir set permissions, and let config file specify
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
   209
//  false. Otherwise, set (*valid) to true and return the converted value.
421ccfedd6c6 Permissions support...let mkdir set permissions, and let config file specify
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
   210
uint16 MojoPlatform_makePermissions(const char *str, boolean *valid);
421ccfedd6c6 Permissions support...let mkdir set permissions, and let config file specify
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
   211
421ccfedd6c6 Permissions support...let mkdir set permissions, and let config file specify
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
   212
// Return a default, sane set of permissions for a newly-created file.
421ccfedd6c6 Permissions support...let mkdir set permissions, and let config file specify
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
   213
uint16 MojoPlatform_defaultFilePerms(void);
421ccfedd6c6 Permissions support...let mkdir set permissions, and let config file specify
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
   214
421ccfedd6c6 Permissions support...let mkdir set permissions, and let config file specify
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
   215
// Return a default, sane set of permissions for a newly-created directory.
421ccfedd6c6 Permissions support...let mkdir set permissions, and let config file specify
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
   216
uint16 MojoPlatform_defaultDirPerms(void);
421ccfedd6c6 Permissions support...let mkdir set permissions, and let config file specify
Ryan C. Gordon <icculus@icculus.org>
parents: 249
diff changeset
   217
82
1f5e39f9a47d FIXME removal: cleaned up GUI plugin loading and dlopen() abstraction.
Ryan C. Gordon <icculus@icculus.org>
parents: 77
diff changeset
   218
// Wrappers for Unix dlopen/dlsym/dlclose, sort of. Instead of a filename,
1f5e39f9a47d FIXME removal: cleaned up GUI plugin loading and dlopen() abstraction.
Ryan C. Gordon <icculus@icculus.org>
parents: 77
diff changeset
   219
//  these take a memory buffer for the library. If you can't load this
1f5e39f9a47d FIXME removal: cleaned up GUI plugin loading and dlopen() abstraction.
Ryan C. Gordon <icculus@icculus.org>
parents: 77
diff changeset
   220
//  directly in RAM, the platform should write it to a temporary file first,
1f5e39f9a47d FIXME removal: cleaned up GUI plugin loading and dlopen() abstraction.
Ryan C. Gordon <icculus@icculus.org>
parents: 77
diff changeset
   221
//  and deal with cleanup in MojoPlatform_dlclose(). The memory buffer must be
1f5e39f9a47d FIXME removal: cleaned up GUI plugin loading and dlopen() abstraction.
Ryan C. Gordon <icculus@icculus.org>
parents: 77
diff changeset
   222
//  dereferenced in MojoPlatform_dlopen(), as the caller may free() it upon
1f5e39f9a47d FIXME removal: cleaned up GUI plugin loading and dlopen() abstraction.
Ryan C. Gordon <icculus@icculus.org>
parents: 77
diff changeset
   223
//  return. Everything else works like the usual Unix calls.
1f5e39f9a47d FIXME removal: cleaned up GUI plugin loading and dlopen() abstraction.
Ryan C. Gordon <icculus@icculus.org>
parents: 77
diff changeset
   224
void *MojoPlatform_dlopen(const uint8 *img, size_t len);
77
26863adbc056 FIXME removal: abstract out some Unixy things.
Ryan C. Gordon <icculus@icculus.org>
parents: 70
diff changeset
   225
void *MojoPlatform_dlsym(void *lib, const char *sym);
26863adbc056 FIXME removal: abstract out some Unixy things.
Ryan C. Gordon <icculus@icculus.org>
parents: 70
diff changeset
   226
void MojoPlatform_dlclose(void *lib);
26863adbc056 FIXME removal: abstract out some Unixy things.
Ryan C. Gordon <icculus@icculus.org>
parents: 70
diff changeset
   227
466
7ed76bfef8da Support for launching a web browser.
Ryan C. Gordon <icculus@icculus.org>
parents: 444
diff changeset
   228
// Launch the user's preferred browser to view the URL (url).
7ed76bfef8da Support for launching a web browser.
Ryan C. Gordon <icculus@icculus.org>
parents: 444
diff changeset
   229
//  Returns true if the browser launched, false otherwise. We can't know
7ed76bfef8da Support for launching a web browser.
Ryan C. Gordon <icculus@icculus.org>
parents: 444
diff changeset
   230
//  if the URL actually loaded, just if the browser launched. The hope is that
7ed76bfef8da Support for launching a web browser.
Ryan C. Gordon <icculus@icculus.org>
parents: 444
diff changeset
   231
//  the browser will inform the user if there's a problem loading the URL.
7ed76bfef8da Support for launching a web browser.
Ryan C. Gordon <icculus@icculus.org>
parents: 444
diff changeset
   232
boolean MojoPlatform_launchBrowser(const char *url);
7ed76bfef8da Support for launching a web browser.
Ryan C. Gordon <icculus@icculus.org>
parents: 444
diff changeset
   233
482
d46016ed7d57 First shot at desktop menu items.
Ryan C. Gordon <icculus@icculus.org>
parents: 466
diff changeset
   234
// Add a menu item to the Application menu or Start bar or whatever.
d46016ed7d57 First shot at desktop menu items.
Ryan C. Gordon <icculus@icculus.org>
parents: 466
diff changeset
   235
//  (data) is 100% platform dependent right now, and this interface will
d46016ed7d57 First shot at desktop menu items.
Ryan C. Gordon <icculus@icculus.org>
parents: 466
diff changeset
   236
//  likely change as we come to understand various systems' needs better.
d46016ed7d57 First shot at desktop menu items.
Ryan C. Gordon <icculus@icculus.org>
parents: 466
diff changeset
   237
//  On Unix, it expects this to be a path to a FreeDesktop .desktop file.
d46016ed7d57 First shot at desktop menu items.
Ryan C. Gordon <icculus@icculus.org>
parents: 466
diff changeset
   238
// Returns (true) on success and (false) on failure.
d46016ed7d57 First shot at desktop menu items.
Ryan C. Gordon <icculus@icculus.org>
parents: 466
diff changeset
   239
boolean MojoPlatform_installDesktopMenuItem(const char *data);
d46016ed7d57 First shot at desktop menu items.
Ryan C. Gordon <icculus@icculus.org>
parents: 466
diff changeset
   240
d46016ed7d57 First shot at desktop menu items.
Ryan C. Gordon <icculus@icculus.org>
parents: 466
diff changeset
   241
// Remove a menu item from the Application menu or Start bar or whatever.
d46016ed7d57 First shot at desktop menu items.
Ryan C. Gordon <icculus@icculus.org>
parents: 466
diff changeset
   242
//  (data) is 100% platform dependent right now, and this interface will
d46016ed7d57 First shot at desktop menu items.
Ryan C. Gordon <icculus@icculus.org>
parents: 466
diff changeset
   243
//  likely change as we come to understand various systems' needs better.
d46016ed7d57 First shot at desktop menu items.
Ryan C. Gordon <icculus@icculus.org>
parents: 466
diff changeset
   244
//  On Unix, it expects this to be a path to a FreeDesktop .desktop file.
d46016ed7d57 First shot at desktop menu items.
Ryan C. Gordon <icculus@icculus.org>
parents: 466
diff changeset
   245
// Returns (true) on success and (false) on failure.
d46016ed7d57 First shot at desktop menu items.
Ryan C. Gordon <icculus@icculus.org>
parents: 466
diff changeset
   246
boolean MojoPlatform_uninstallDesktopMenuItem(const char *data);
d46016ed7d57 First shot at desktop menu items.
Ryan C. Gordon <icculus@icculus.org>
parents: 466
diff changeset
   247
779
a05c33a9a681 Expose a MojoSetup.runScript function to allow running a non LUA script
Jeremy White <jwhite@codeweavers.com>
parents: 778
diff changeset
   248
// Run a script from the archive in the OS
a05c33a9a681 Expose a MojoSetup.runScript function to allow running a non LUA script
Jeremy White <jwhite@codeweavers.com>
parents: 778
diff changeset
   249
int MojoPlatform_runScript(const char *script, boolean devnull, const char **argv);
a05c33a9a681 Expose a MojoSetup.runScript function to allow running a non LUA script
Jeremy White <jwhite@codeweavers.com>
parents: 778
diff changeset
   250
778
5d624992ec19 Add a postexec option that can be used to chain the installer to a
Jeremy White <jwhite@codeweavers.com>
parents: 721
diff changeset
   251
// Exec a given process name
5d624992ec19 Add a postexec option that can be used to chain the installer to a
Jeremy White <jwhite@codeweavers.com>
parents: 721
diff changeset
   252
int MojoPlatform_exec(const char *cmd);
5d624992ec19 Add a postexec option that can be used to chain the installer to a
Jeremy White <jwhite@codeweavers.com>
parents: 721
diff changeset
   253
299
2ff4115d3f7c A shot at a kludge for launching a different binary from inside the Base
Ryan C. Gordon <icculus@icculus.org>
parents: 283
diff changeset
   254
#if !SUPPORT_MULTIARCH
2ff4115d3f7c A shot at a kludge for launching a different binary from inside the Base
Ryan C. Gordon <icculus@icculus.org>
parents: 283
diff changeset
   255
#define MojoPlatform_switchBin(img, len)
2ff4115d3f7c A shot at a kludge for launching a different binary from inside the Base
Ryan C. Gordon <icculus@icculus.org>
parents: 283
diff changeset
   256
#else
2ff4115d3f7c A shot at a kludge for launching a different binary from inside the Base
Ryan C. Gordon <icculus@icculus.org>
parents: 283
diff changeset
   257
void MojoPlatform_switchBin(const uint8 *img, size_t len);
2ff4115d3f7c A shot at a kludge for launching a different binary from inside the Base
Ryan C. Gordon <icculus@icculus.org>
parents: 283
diff changeset
   258
#endif
2ff4115d3f7c A shot at a kludge for launching a different binary from inside the Base
Ryan C. Gordon <icculus@icculus.org>
parents: 283
diff changeset
   259
721
77b8a1d2ad8d Allow MojoPlatform_spawnTerminal() to return on success.
Ryan C. Gordon <icculus@icculus.org>
parents: 482
diff changeset
   260
// Try to spawn a terminal, and possibly relaunch MojoSetup within it.
77b8a1d2ad8d Allow MojoPlatform_spawnTerminal() to return on success.
Ryan C. Gordon <icculus@icculus.org>
parents: 482
diff changeset
   261
//  If we can attach to a terminal without relaunching, do so and
77b8a1d2ad8d Allow MojoPlatform_spawnTerminal() to return on success.
Ryan C. Gordon <icculus@icculus.org>
parents: 482
diff changeset
   262
//  return true. false for failure to attach/spawn.
77b8a1d2ad8d Allow MojoPlatform_spawnTerminal() to return on success.
Ryan C. Gordon <icculus@icculus.org>
parents: 482
diff changeset
   263
//  May not return on success (process replaces itself).
77b8a1d2ad8d Allow MojoPlatform_spawnTerminal() to return on success.
Ryan C. Gordon <icculus@icculus.org>
parents: 482
diff changeset
   264
boolean MojoPlatform_spawnTerminal(void);
369
f6c0eff5a144 Spawn a terminal if we aren't using one and found no functioning GUI plugins.
Ryan C. Gordon <icculus@icculus.org>
parents: 345
diff changeset
   265
185
2ebaa8f06411 Framework for dealing with blocking MojoInputs.
Ryan C. Gordon <icculus@icculus.org>
parents: 155
diff changeset
   266
// Put the calling process to sleep for at least (ticks) milliseconds.
2ebaa8f06411 Framework for dealing with blocking MojoInputs.
Ryan C. Gordon <icculus@icculus.org>
parents: 155
diff changeset
   267
//  This is meant to yield the CPU while spinning in a loop that is polling
2ebaa8f06411 Framework for dealing with blocking MojoInputs.
Ryan C. Gordon <icculus@icculus.org>
parents: 155
diff changeset
   268
//  for input, etc. Pumping the GUI event queue happens elsewhere, not here.
2ebaa8f06411 Framework for dealing with blocking MojoInputs.
Ryan C. Gordon <icculus@icculus.org>
parents: 155
diff changeset
   269
void MojoPlatform_sleep(uint32 ticks);
131
c00506a75a2b Media detection code. Also untested. :/
Ryan C. Gordon <icculus@icculus.org>
parents: 104
diff changeset
   270
879
c2afc800b743 Assorted spelling fixes (thanks, Francois!).
Ryan C. Gordon <icculus@icculus.org>
parents: 805
diff changeset
   271
// Put a line of text to the system log, whatever that might be on a
89
d6c9b715996c Logging and command line support, and some other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 82
diff changeset
   272
//  given platform. (str) is a complete line, but won't end with any newline
d6c9b715996c Logging and command line support, and some other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 82
diff changeset
   273
//  characters. You should supply if needed.
d6c9b715996c Logging and command line support, and some other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 82
diff changeset
   274
void MojoPlatform_log(const char *str);
d6c9b715996c Logging and command line support, and some other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 82
diff changeset
   275
374
057e54666a4f Implement hooks for image decoding into MojoSetup.
Ryan C. Gordon <icculus@icculus.org>
parents: 369
diff changeset
   276
// This tries to decode a graphic file in memory into an RGBA framebuffer.
057e54666a4f Implement hooks for image decoding into MojoSetup.
Ryan C. Gordon <icculus@icculus.org>
parents: 369
diff changeset
   277
//  Most platforms return NULL here. No one should call this; use decodeImage()
057e54666a4f Implement hooks for image decoding into MojoSetup.
Ryan C. Gordon <icculus@icculus.org>
parents: 369
diff changeset
   278
//  instead, which will try included platform-independent code if this fails.
057e54666a4f Implement hooks for image decoding into MojoSetup.
Ryan C. Gordon <icculus@icculus.org>
parents: 369
diff changeset
   279
// This function is just here to allow a platform with the appropriate
057e54666a4f Implement hooks for image decoding into MojoSetup.
Ryan C. Gordon <icculus@icculus.org>
parents: 369
diff changeset
   280
//  functionality to work without compiling in stb_image.c, or supply more
057e54666a4f Implement hooks for image decoding into MojoSetup.
Ryan C. Gordon <icculus@icculus.org>
parents: 369
diff changeset
   281
//  formats over the built-in code.
057e54666a4f Implement hooks for image decoding into MojoSetup.
Ryan C. Gordon <icculus@icculus.org>
parents: 369
diff changeset
   282
// (data) points to the compressed data, (size) is the number of bytes
057e54666a4f Implement hooks for image decoding into MojoSetup.
Ryan C. Gordon <icculus@icculus.org>
parents: 369
diff changeset
   283
//  of compressed data. (*w) and (*h) will contain the images dimensions on
057e54666a4f Implement hooks for image decoding into MojoSetup.
Ryan C. Gordon <icculus@icculus.org>
parents: 369
diff changeset
   284
//  return.
057e54666a4f Implement hooks for image decoding into MojoSetup.
Ryan C. Gordon <icculus@icculus.org>
parents: 369
diff changeset
   285
// Returns NULL on failure (unsupported, etc) and a pointer to the
057e54666a4f Implement hooks for image decoding into MojoSetup.
Ryan C. Gordon <icculus@icculus.org>
parents: 369
diff changeset
   286
//  uncompressed data on success. Caller must free() the returned pointer!
057e54666a4f Implement hooks for image decoding into MojoSetup.
Ryan C. Gordon <icculus@icculus.org>
parents: 369
diff changeset
   287
uint8 *MojoPlatform_decodeImage(const uint8 *data, uint32 size,
057e54666a4f Implement hooks for image decoding into MojoSetup.
Ryan C. Gordon <icculus@icculus.org>
parents: 369
diff changeset
   288
                                uint32 *w, uint32 *h);
057e54666a4f Implement hooks for image decoding into MojoSetup.
Ryan C. Gordon <icculus@icculus.org>
parents: 369
diff changeset
   289
39
900184fd7a05 More work on Lua and localization.
Ryan C. Gordon <icculus@icculus.org>
parents: 25
diff changeset
   290
// Get the current locale, in the format "xx_YY" where "xx" is the language
900184fd7a05 More work on Lua and localization.
Ryan C. Gordon <icculus@icculus.org>
parents: 25
diff changeset
   291
//  (en, fr, de...) and "_YY" is the country. (_US, _CA, etc). The country
900184fd7a05 More work on Lua and localization.
Ryan C. Gordon <icculus@icculus.org>
parents: 25
diff changeset
   292
//  can be omitted. Don't include encoding, it's always UTF-8 at this time.
443
5865db42b7a3 Another attempt to stop being a game developer; some more MojoPlatform_*
Ryan C. Gordon <icculus@icculus.org>
parents: 411
diff changeset
   293
// Returns locale string, or NULL if it couldn't be determined.
5865db42b7a3 Another attempt to stop being a game developer; some more MojoPlatform_*
Ryan C. Gordon <icculus@icculus.org>
parents: 411
diff changeset
   294
//  Caller must free() the returned pointer!
5865db42b7a3 Another attempt to stop being a game developer; some more MojoPlatform_*
Ryan C. Gordon <icculus@icculus.org>
parents: 411
diff changeset
   295
char *MojoPlatform_locale(void);
39
900184fd7a05 More work on Lua and localization.
Ryan C. Gordon <icculus@icculus.org>
parents: 25
diff changeset
   296
443
5865db42b7a3 Another attempt to stop being a game developer; some more MojoPlatform_*
Ryan C. Gordon <icculus@icculus.org>
parents: 411
diff changeset
   297
// !!! FIXME: document me.
5865db42b7a3 Another attempt to stop being a game developer; some more MojoPlatform_*
Ryan C. Gordon <icculus@icculus.org>
parents: 411
diff changeset
   298
// Caller must free() the returned pointer!
5865db42b7a3 Another attempt to stop being a game developer; some more MojoPlatform_*
Ryan C. Gordon <icculus@icculus.org>
parents: 411
diff changeset
   299
char *MojoPlatform_osType(void);
5865db42b7a3 Another attempt to stop being a game developer; some more MojoPlatform_*
Ryan C. Gordon <icculus@icculus.org>
parents: 411
diff changeset
   300
5865db42b7a3 Another attempt to stop being a game developer; some more MojoPlatform_*
Ryan C. Gordon <icculus@icculus.org>
parents: 411
diff changeset
   301
// !!! FIXME: document me.
5865db42b7a3 Another attempt to stop being a game developer; some more MojoPlatform_*
Ryan C. Gordon <icculus@icculus.org>
parents: 411
diff changeset
   302
// Caller must free() the returned pointer!
805
4730a8dacfdd Fixed compiler warning.
Ryan C. Gordon <icculus@icculus.org>
parents: 779
diff changeset
   303
char *MojoPlatform_osMachine(void);
4730a8dacfdd Fixed compiler warning.
Ryan C. Gordon <icculus@icculus.org>
parents: 779
diff changeset
   304
4730a8dacfdd Fixed compiler warning.
Ryan C. Gordon <icculus@icculus.org>
parents: 779
diff changeset
   305
// !!! FIXME: document me.
4730a8dacfdd Fixed compiler warning.
Ryan C. Gordon <icculus@icculus.org>
parents: 779
diff changeset
   306
// Caller must free() the returned pointer!
443
5865db42b7a3 Another attempt to stop being a game developer; some more MojoPlatform_*
Ryan C. Gordon <icculus@icculus.org>
parents: 411
diff changeset
   307
char *MojoPlatform_osVersion(void);
5865db42b7a3 Another attempt to stop being a game developer; some more MojoPlatform_*
Ryan C. Gordon <icculus@icculus.org>
parents: 411
diff changeset
   308
444
068c2a42c62a A couple things cleaned up and patched to compile, and uid/euid/gid supplied
Ryan C. Gordon <icculus@icculus.org>
parents: 443
diff changeset
   309
// !!! FIXME: document me.
068c2a42c62a A couple things cleaned up and patched to compile, and uid/euid/gid supplied
Ryan C. Gordon <icculus@icculus.org>
parents: 443
diff changeset
   310
uint64 MojoPlatform_getuid(void);
068c2a42c62a A couple things cleaned up and patched to compile, and uid/euid/gid supplied
Ryan C. Gordon <icculus@icculus.org>
parents: 443
diff changeset
   311
068c2a42c62a A couple things cleaned up and patched to compile, and uid/euid/gid supplied
Ryan C. Gordon <icculus@icculus.org>
parents: 443
diff changeset
   312
// !!! FIXME: document me.
068c2a42c62a A couple things cleaned up and patched to compile, and uid/euid/gid supplied
Ryan C. Gordon <icculus@icculus.org>
parents: 443
diff changeset
   313
uint64 MojoPlatform_geteuid(void);
068c2a42c62a A couple things cleaned up and patched to compile, and uid/euid/gid supplied
Ryan C. Gordon <icculus@icculus.org>
parents: 443
diff changeset
   314
068c2a42c62a A couple things cleaned up and patched to compile, and uid/euid/gid supplied
Ryan C. Gordon <icculus@icculus.org>
parents: 443
diff changeset
   315
// !!! FIXME: document me.
068c2a42c62a A couple things cleaned up and patched to compile, and uid/euid/gid supplied
Ryan C. Gordon <icculus@icculus.org>
parents: 443
diff changeset
   316
uint64 MojoPlatform_getgid(void);
068c2a42c62a A couple things cleaned up and patched to compile, and uid/euid/gid supplied
Ryan C. Gordon <icculus@icculus.org>
parents: 443
diff changeset
   317
43
376615c7d502 Platform stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   318
376615c7d502 Platform stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   319
// Basic platform detection.
376615c7d502 Platform stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   320
#if PLATFORM_WINDOWS
376615c7d502 Platform stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   321
#define PLATFORM_NAME "windows"
376615c7d502 Platform stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   322
#elif PLATFORM_MACOSX
376615c7d502 Platform stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   323
#define PLATFORM_NAME "macosx"
376615c7d502 Platform stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   324
#elif PLATFORM_UNIX
376615c7d502 Platform stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   325
#define PLATFORM_NAME "unix"
98
64ac9e995fd3 More BeOS wankery.
Ryan C. Gordon <icculus@icculus.org>
parents: 89
diff changeset
   326
#elif PLATFORM_BEOS
64ac9e995fd3 More BeOS wankery.
Ryan C. Gordon <icculus@icculus.org>
parents: 89
diff changeset
   327
#define PLATFORM_NAME "beos"
43
376615c7d502 Platform stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   328
#else
82
1f5e39f9a47d FIXME removal: cleaned up GUI plugin loading and dlopen() abstraction.
Ryan C. Gordon <icculus@icculus.org>
parents: 77
diff changeset
   329
#error Unknown platform.
43
376615c7d502 Platform stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   330
#endif
376615c7d502 Platform stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   331
376615c7d502 Platform stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   332
// Basic architecture detection.
376615c7d502 Platform stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   333
376615c7d502 Platform stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   334
#if defined(__powerpc64__)
376615c7d502 Platform stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   335
#define PLATFORM_ARCH "powerpc64"
376615c7d502 Platform stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   336
#elif defined(__ppc__) || defined(__powerpc__) || defined(__POWERPC__)
376615c7d502 Platform stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   337
#define PLATFORM_ARCH "powerpc"
376615c7d502 Platform stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   338
#elif defined(__x86_64__) || defined(_M_X64)
376615c7d502 Platform stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   339
#define PLATFORM_ARCH "x86-64"
376615c7d502 Platform stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   340
#elif defined(__X86__) || defined(__i386__) || defined(i386) || defined (_M_IX86) || defined(__386__)
376615c7d502 Platform stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   341
#define PLATFORM_ARCH "x86"
376615c7d502 Platform stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   342
#else
376615c7d502 Platform stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   343
#error Unknown processor architecture.
376615c7d502 Platform stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   344
#endif
376615c7d502 Platform stuff.
Ryan C. Gordon <icculus@icculus.org>
parents: 39
diff changeset
   345
339
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   346
// Other basic truths...
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   347
#if PLATFORM_WINDOWS
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   348
#define MOJOPLATFORM_ENDLINE "\r\n"
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   349
#else
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   350
#define MOJOPLATFORM_ENDLINE "\n"
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   351
#endif
357703dfb348 Reworked the rest of the Unix-specific bits out of fileio.c ... untested!
Ryan C. Gordon <icculus@icculus.org>
parents: 338
diff changeset
   352
5
92ac7b75db5d Added a bunch of structure, lots stolen from lighting.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   353
#ifdef __cplusplus
92ac7b75db5d Added a bunch of structure, lots stolen from lighting.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   354
}
92ac7b75db5d Added a bunch of structure, lots stolen from lighting.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   355
#endif
92ac7b75db5d Added a bunch of structure, lots stolen from lighting.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   356
92ac7b75db5d Added a bunch of structure, lots stolen from lighting.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   357
#endif
92ac7b75db5d Added a bunch of structure, lots stolen from lighting.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   358
10
d1f47c44bcdb Screw it, I'm using C++-style comments. If a compelling reason comes up to
Ryan C. Gordon <icculus@icculus.org>
parents: 8
diff changeset
   359
// end of platform.h ...
5
92ac7b75db5d Added a bunch of structure, lots stolen from lighting.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   360