platform.h
author Ryan C. Gordon <icculus@icculus.org>
Fri, 28 Mar 2008 06:57:04 +0000
changeset 109 9fae2fac7b94
parent 108 0b8bcaef83e7
permissions -rw-r--r--
Updated copyright info.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
108
0b8bcaef83e7 Renamed some files, cleaned up the lack of headers on source files.
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
     1
/**
0b8bcaef83e7 Renamed some files, cleaned up the lack of headers on source files.
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
     2
 * MojoPatch; a tool for updating data in the field.
0b8bcaef83e7 Renamed some files, cleaned up the lack of headers on source files.
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
     3
 *
0b8bcaef83e7 Renamed some files, cleaned up the lack of headers on source files.
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
     4
 * Please see the file LICENSE.txt in the source's root directory.
0b8bcaef83e7 Renamed some files, cleaned up the lack of headers on source files.
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
     5
 *
0b8bcaef83e7 Renamed some files, cleaned up the lack of headers on source files.
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
     6
 *  This file written by Ryan C. Gordon.
0b8bcaef83e7 Renamed some files, cleaned up the lack of headers on source files.
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
     7
 */
0
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
#ifndef _INCL_PLATFORM_H_
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
#define _INCL_PLATFORM_H_
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
#ifdef __cplusplus
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
extern "C" {
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
#endif
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
98
4912346d49c9 Cleaned up some datatype sizes and handle byte order explicitly...this allows
Ryan C. Gordon <icculus@icculus.org>
parents: 91
diff changeset
    16
#ifdef __POWERPC__
103
0f2c360e6cf6 Whoops...endian defines are backwards.
Ryan C. Gordon <icculus@icculus.org>
parents: 98
diff changeset
    17
#define PLATFORM_BIGENDIAN 1
98
4912346d49c9 Cleaned up some datatype sizes and handle byte order explicitly...this allows
Ryan C. Gordon <icculus@icculus.org>
parents: 91
diff changeset
    18
#else
103
0f2c360e6cf6 Whoops...endian defines are backwards.
Ryan C. Gordon <icculus@icculus.org>
parents: 98
diff changeset
    19
#define PLATFORM_BIGENDIAN 0
98
4912346d49c9 Cleaned up some datatype sizes and handle byte order explicitly...this allows
Ryan C. Gordon <icculus@icculus.org>
parents: 91
diff changeset
    20
#endif
4912346d49c9 Cleaned up some datatype sizes and handle byte order explicitly...this allows
Ryan C. Gordon <icculus@icculus.org>
parents: 91
diff changeset
    21
36
9e60553d82bc Better fix for converting to Unix process exit codes.
Ryan C. Gordon <icculus@icculus.org>
parents: 27
diff changeset
    22
#define PATCHERROR    0
9e60553d82bc Better fix for converting to Unix process exit codes.
Ryan C. Gordon <icculus@icculus.org>
parents: 27
diff changeset
    23
#define PATCHSUCCESS  1
9e60553d82bc Better fix for converting to Unix process exit codes.
Ryan C. Gordon <icculus@icculus.org>
parents: 27
diff changeset
    24
0
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
#if PLATFORM_WIN32
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
#  include <io.h>
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
#  define PATH_SEP "\\"
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
#  if (defined _MSC_VER)
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
#    define inline __inline
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
#    define snprintf _snprintf
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
#    define mkdir(x, y) _mkdir(x)
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
#    define chdir(x) _chdir(x)
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
#  endif
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
#  define MAX_PATH 1024
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
#elif PLATFORM_UNIX
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
#  include <unistd.h>
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
#  include <sys/stat.h>
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
#  include <sys/types.h>
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
#  include <sys/param.h>
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
#  include <fcntl.h>
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
#  define PATH_SEP "/"
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
#  define MAX_PATH MAXPATHLEN
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
#else
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
#  #error please define your platform.
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
#endif
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
typedef struct MOJOPATCH_FILELIST
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
{
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
    char *fname;
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
    struct MOJOPATCH_FILELIST *next;
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
} file_list;
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
91
6db187bc77c7 Let scripts run before and after each patch, and upon successful execution of
Ryan C. Gordon <icculus@icculus.org>
parents: 89
diff changeset
    53
typedef enum
6db187bc77c7 Let scripts run before and after each patch, and upon successful execution of
Ryan C. Gordon <icculus@icculus.org>
parents: 89
diff changeset
    54
{
6db187bc77c7 Let scripts run before and after each patch, and upon successful execution of
Ryan C. Gordon <icculus@icculus.org>
parents: 89
diff changeset
    55
    SPAWN_FILENOTFOUND,
6db187bc77c7 Let scripts run before and after each patch, and upon successful execution of
Ryan C. Gordon <icculus@icculus.org>
parents: 89
diff changeset
    56
    SPAWN_FAILED,
6db187bc77c7 Let scripts run before and after each patch, and upon successful execution of
Ryan C. Gordon <icculus@icculus.org>
parents: 89
diff changeset
    57
    SPAWN_RETURNGOOD,
6db187bc77c7 Let scripts run before and after each patch, and upon successful execution of
Ryan C. Gordon <icculus@icculus.org>
parents: 89
diff changeset
    58
    SPAWN_RETURNBAD
6db187bc77c7 Let scripts run before and after each patch, and upon successful execution of
Ryan C. Gordon <icculus@icculus.org>
parents: 89
diff changeset
    59
} SpawnResult;
6db187bc77c7 Let scripts run before and after each patch, and upon successful execution of
Ryan C. Gordon <icculus@icculus.org>
parents: 89
diff changeset
    60
0
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
/* Your mainline calls this. */
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
int mojopatch_main(int argc, char **argv);
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
/* You call this for fatal error messages. */
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
void _fatal(const char *fmt, ...);
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
/* Call this for logging (not debug info). */
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
void _log(const char *fmt, ...);
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
/* Call this for logging (debug info). */
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
void _dlog(const char *fmt, ...);
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
/* platform-specific stuff you implement. */
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
int file_exists(const char *fname);
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
int file_is_directory(const char *fname);
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
int file_is_symlink(const char *fname);
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
file_list *make_filelist(const char *base);  /* must use malloc(). */
98
4912346d49c9 Cleaned up some datatype sizes and handle byte order explicitly...this allows
Ryan C. Gordon <icculus@icculus.org>
parents: 91
diff changeset
    78
int get_file_size(const char *fname, unsigned int *fsize);
89
0befb9dfdee4 Removed getcwd() and use get_current_dir() instead.
Ryan C. Gordon <icculus@icculus.org>
parents: 83
diff changeset
    79
char *get_current_dir(char *buf, size_t bufsize);
0
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
char *get_realpath(const char *path);
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
int update_version(const char *ver);
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
int calc_tmp_filenames(char **tmp1, char **tmp2);
81
50f6052737ce Did a lot of ripping things up.
Ryan C. Gordon <icculus@icculus.org>
parents: 76
diff changeset
    83
int locate_product_by_identifier(const char *str, char *buf, size_t bufsize);
83
2ab590824674 Moved a bunch of the versioning stuff into mojopatch.c and cleaned up patch
Ryan C. Gordon <icculus@icculus.org>
parents: 81
diff changeset
    84
int get_product_version(const char *ident, char *buf, size_t bufsize);
91
6db187bc77c7 Let scripts run before and after each patch, and upon successful execution of
Ryan C. Gordon <icculus@icculus.org>
parents: 89
diff changeset
    85
SpawnResult spawn_xdelta(const char *cmdline);
6db187bc77c7 Let scripts run before and after each patch, and upon successful execution of
Ryan C. Gordon <icculus@icculus.org>
parents: 89
diff changeset
    86
SpawnResult spawn_script(const char *scriptname, const char *dstdir);
0
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
#ifdef __cplusplus
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
}
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
#endif
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
#endif /* include-once blocker. */
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
/* end of platform.h ... */
31eee864ed5d Initial revision
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95