platform.h
author Ryan C. Gordon <icculus@icculus.org>
Wed, 18 May 2005 19:51:28 +0000
changeset 91 6db187bc77c7
parent 89 0befb9dfdee4
child 98 4912346d49c9
permissions -rw-r--r--
Let scripts run before and after each patch, and upon successful execution of
all patches.
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@36
     9
#define PATCHERROR    0
icculus@36
    10
#define PATCHSUCCESS  1
icculus@36
    11
icculus@0
    12
#if PLATFORM_WIN32
icculus@0
    13
#  include <io.h>
icculus@0
    14
#  define PATH_SEP "\\"
icculus@0
    15
#  if (defined _MSC_VER)
icculus@0
    16
#    define inline __inline
icculus@0
    17
#    define snprintf _snprintf
icculus@0
    18
#    define mkdir(x, y) _mkdir(x)
icculus@0
    19
#    define chdir(x) _chdir(x)
icculus@0
    20
#  endif
icculus@0
    21
#  define MAX_PATH 1024
icculus@0
    22
#elif PLATFORM_UNIX
icculus@0
    23
#  include <unistd.h>
icculus@0
    24
#  include <sys/stat.h>
icculus@0
    25
#  include <sys/types.h>
icculus@0
    26
#  include <sys/param.h>
icculus@0
    27
#  include <fcntl.h>
icculus@0
    28
#  define PATH_SEP "/"
icculus@0
    29
#  define MAX_PATH MAXPATHLEN
icculus@0
    30
#else
icculus@0
    31
#  #error please define your platform.
icculus@0
    32
#endif
icculus@0
    33
icculus@0
    34
typedef struct MOJOPATCH_FILELIST
icculus@0
    35
{
icculus@0
    36
    char *fname;
icculus@0
    37
    struct MOJOPATCH_FILELIST *next;
icculus@0
    38
} file_list;
icculus@0
    39
icculus@91
    40
typedef enum
icculus@91
    41
{
icculus@91
    42
    SPAWN_FILENOTFOUND,
icculus@91
    43
    SPAWN_FAILED,
icculus@91
    44
    SPAWN_RETURNGOOD,
icculus@91
    45
    SPAWN_RETURNBAD
icculus@91
    46
} SpawnResult;
icculus@91
    47
icculus@0
    48
/* Your mainline calls this. */
icculus@0
    49
int mojopatch_main(int argc, char **argv);
icculus@0
    50
icculus@0
    51
/* You call this for fatal error messages. */
icculus@0
    52
void _fatal(const char *fmt, ...);
icculus@0
    53
icculus@0
    54
/* Call this for logging (not debug info). */
icculus@0
    55
void _log(const char *fmt, ...);
icculus@0
    56
icculus@0
    57
/* Call this for logging (debug info). */
icculus@0
    58
void _dlog(const char *fmt, ...);
icculus@0
    59
icculus@0
    60
/* platform-specific stuff you implement. */
icculus@0
    61
int file_exists(const char *fname);
icculus@0
    62
int file_is_directory(const char *fname);
icculus@0
    63
int file_is_symlink(const char *fname);
icculus@0
    64
file_list *make_filelist(const char *base);  /* must use malloc(). */
icculus@0
    65
int get_file_size(const char *fname, long *fsize);
icculus@89
    66
char *get_current_dir(char *buf, size_t bufsize);
icculus@0
    67
char *get_realpath(const char *path);
icculus@0
    68
int update_version(const char *ver);
icculus@0
    69
int calc_tmp_filenames(char **tmp1, char **tmp2);
icculus@81
    70
int locate_product_by_identifier(const char *str, char *buf, size_t bufsize);
icculus@83
    71
int get_product_version(const char *ident, char *buf, size_t bufsize);
icculus@91
    72
SpawnResult spawn_xdelta(const char *cmdline);
icculus@91
    73
SpawnResult spawn_script(const char *scriptname, const char *dstdir);
icculus@0
    74
icculus@0
    75
#ifdef __cplusplus
icculus@0
    76
}
icculus@0
    77
#endif
icculus@0
    78
icculus@0
    79
#endif /* include-once blocker. */
icculus@0
    80
icculus@0
    81
/* end of platform.h ... */
icculus@0
    82