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