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