project_files/hwc/rtl/fileio.c
author Wuzzy <almikes@aol.com>
Wed, 11 Oct 2017 23:41:25 +0200
changeset 12700 28210d2a9a36
parent 11687 2c21bc80c95d
child 14428 a32b967f1341
permissions -rw-r--r--
Rope: Keep rope selected if sliding on ground and secondary weapon selected For consistency w/ previous rope commit
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     1
/*
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     2
 * XXX: assume all files are text files
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     3
 */
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     4
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     5
#include "misc.h"
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     6
#include "fileio.h"
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     7
#include <string.h>
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     8
#include <stdlib.h>
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
     9
#include <assert.h>
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    10
#include <sys/stat.h>
11687
2c21bc80c95d Implement GetCurrentDir in the c rtl
koda
parents: 10575
diff changeset
    11
#include <unistd.h>
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    12
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    13
io_result_t IOResult;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    14
int FileMode;
11687
2c21bc80c95d Implement GetCurrentDir in the c rtl
koda
parents: 10575
diff changeset
    15
char cwd[1024];
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    16
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    17
static void init(File f) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    18
    f->fp = NULL;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    19
    f->eof = 0;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    20
    f->mode = NULL;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    21
    f->record_len = 0;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    22
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    23
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    24
void fpcrtl_assign__vars(File *f, string255 name) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    25
    FIX_STRING(name);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    26
    *f = (File) malloc(sizeof(file_wrapper_t));
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    27
    strcpy((*f)->file_name, name.str);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    28
    init(*f);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    29
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    30
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    31
void fpcrtl_reset1(File f) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    32
    f->fp = fopen(f->file_name, "r");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    33
    if (!f->fp) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    34
        IOResult = IO_ERROR_DUMMY;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    35
        printf("Failed to open %s\n", f->file_name);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    36
        return;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    37
    } else {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    38
#ifdef FPCRTL_DEBUG
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    39
        printf("Opened %s\n", f->file_name);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    40
#endif
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    41
    }
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    42
    IOResult = IO_NO_ERROR;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    43
    f->mode = "r";
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    44
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    45
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    46
void fpcrtl_reset2(File f, int l) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    47
    f->eof = 0;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    48
    f->fp = fopen(f->file_name, "rb");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    49
    if (!f->fp) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    50
        IOResult = IO_ERROR_DUMMY;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    51
        printf("Failed to open %s\n", f->file_name);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    52
        return;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    53
    }
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    54
    IOResult = IO_NO_ERROR;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    55
    f->mode = "rb";
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    56
    f->record_len = l;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    57
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    58
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    59
void __attribute__((overloadable)) fpcrtl_rewrite(File f) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    60
    f->fp = fopen(f->file_name, "w+");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    61
    if (!f->fp) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    62
        IOResult = IO_ERROR_DUMMY;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    63
        return;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    64
    }
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    65
    IOResult = IO_NO_ERROR;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    66
    f->mode = "w+";
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    67
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    68
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    69
void __attribute__((overloadable)) fpcrtl_rewrite(File f, Integer l) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    70
    IOResult = IO_NO_ERROR;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    71
    fpcrtl_rewrite(f);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    72
    if (f->fp) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    73
        f->record_len = l;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    74
    }
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    75
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    76
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    77
void fpcrtl_close(File f) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    78
    IOResult = IO_NO_ERROR;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    79
    fclose(f->fp);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    80
    free(f);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    81
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    82
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    83
boolean fpcrtl_eof(File f) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    84
    IOResult = IO_NO_ERROR;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    85
    if (f->eof || f->fp == NULL || feof(f->fp)) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    86
        return true;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    87
    } else {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    88
        return false;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    89
    }
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    90
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    91
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    92
void __attribute__((overloadable)) fpcrtl_readLn(File f) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    93
    IOResult = IO_NO_ERROR;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    94
    char line[256];
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    95
    if (fgets(line, sizeof(line), f->fp) == NULL) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    96
        f->eof = 1;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    97
    }
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    98
    if (feof(f->fp)) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
    99
        f->eof = 1;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   100
    }
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   101
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   102
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   103
void __attribute__((overloadable)) fpcrtl_readLn__vars(File f, Integer *i) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   104
    string255 s;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   105
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   106
    if (feof(f->fp)) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   107
        f->eof = 1;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   108
        return;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   109
    }
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   110
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   111
    fpcrtl_readLn__vars(f, &s);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   112
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   113
    *i = atoi(s.str);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   114
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   115
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   116
void __attribute__((overloadable)) fpcrtl_readLn__vars(File f, LongWord *i) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   117
    string255 s;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   118
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   119
    if (feof(f->fp)) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   120
        f->eof = 1;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   121
        return;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   122
    }
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   123
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   124
    fpcrtl_readLn__vars(f, &s);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   125
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   126
    *i = atoi(s.str);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   127
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   128
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   129
void __attribute__((overloadable)) fpcrtl_readLn__vars(File f, string255 *s) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   130
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   131
    if (fgets(s->str, 255, f->fp) == NULL) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   132
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   133
        s->len = 0;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   134
        s->str[0] = 0;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   135
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   136
        f->eof = 1;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   137
        return;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   138
    }
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   139
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   140
    if (feof(f->fp)) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   141
        s->len = 0;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   142
        f->eof = 1;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   143
        return;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   144
    }
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   145
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   146
    IOResult = IO_NO_ERROR;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   147
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   148
    s->len = strlen(s->str);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   149
    if ((s->len > 0) && (s->str[s->len - 1] == '\n')) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   150
        s->str[s->len - 1] = 0;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   151
        s->len--;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   152
    }
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   153
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   154
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   155
void __attribute__((overloadable)) fpcrtl_write(File f, string255 s) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   156
    FIX_STRING(s);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   157
    fprintf(f->fp, "%s", s.str);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   158
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   159
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   160
void __attribute__((overloadable)) fpcrtl_write(FILE *f, string255 s) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   161
    FIX_STRING(s);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   162
    fprintf(f, "%s", s.str);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   163
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   164
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   165
void __attribute__((overloadable)) fpcrtl_writeLn(File f, string255 s) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   166
    FIX_STRING(s);
10575
13b1e9008f4b super-filthy hack to allow pas2c to fallback to writing to stderr.
sheepluva
parents: 9966
diff changeset
   167
    // filthy hack to write to stderr
13b1e9008f4b super-filthy hack to allow pas2c to fallback to writing to stderr.
sheepluva
parents: 9966
diff changeset
   168
    if (!f->fp)
13b1e9008f4b super-filthy hack to allow pas2c to fallback to writing to stderr.
sheepluva
parents: 9966
diff changeset
   169
        fprintf(stderr, "%s\n", s.str);
13b1e9008f4b super-filthy hack to allow pas2c to fallback to writing to stderr.
sheepluva
parents: 9966
diff changeset
   170
    else
13b1e9008f4b super-filthy hack to allow pas2c to fallback to writing to stderr.
sheepluva
parents: 9966
diff changeset
   171
        fprintf(f->fp, "%s\n", s.str);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   172
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   173
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   174
void __attribute__((overloadable)) fpcrtl_writeLn(FILE *f, string255 s) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   175
    FIX_STRING(s);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   176
    fprintf(f, "%s\n", s.str);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   177
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   178
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   179
void fpcrtl_blockRead__vars(File f, void *buf, Integer count, Integer *result) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   180
    assert(f->record_len > 0);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   181
    *result = fread(buf, f->record_len, count, f->fp);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   182
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   183
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   184
/*
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   185
 * XXX: dummy blockWrite
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   186
 */
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   187
void fpcrtl_blockWrite__vars(File f, const void *buf, Integer count,
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   188
        Integer *result) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   189
    assert(0);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   190
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   191
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   192
bool fpcrtl_directoryExists(string255 dir) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   193
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   194
    struct stat st;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   195
    FIX_STRING(dir);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   196
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   197
    IOResult = IO_NO_ERROR;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   198
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   199
#ifdef FPCRTL_DEBUG
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   200
    printf("Warning: directoryExists is called. This may not work when compiled to js.\n");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   201
#endif
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   202
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   203
    if (stat(dir.str, &st) == 0) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   204
        return true;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   205
    }
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   206
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   207
    return false;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   208
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   209
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   210
bool fpcrtl_fileExists(string255 filename) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   211
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   212
    FIX_STRING(filename);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   213
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   214
    IOResult = IO_NO_ERROR;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   215
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   216
    FILE *fp = fopen(filename.str, "r");
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   217
    if (fp) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   218
        fclose(fp);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   219
        return true;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   220
    }
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   221
    return false;
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   222
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   223
11687
2c21bc80c95d Implement GetCurrentDir in the c rtl
koda
parents: 10575
diff changeset
   224
char * fpcrtl_getCurrentDir(void) {
2c21bc80c95d Implement GetCurrentDir in the c rtl
koda
parents: 10575
diff changeset
   225
2c21bc80c95d Implement GetCurrentDir in the c rtl
koda
parents: 10575
diff changeset
   226
    IOResult = IO_NO_ERROR;
2c21bc80c95d Implement GetCurrentDir in the c rtl
koda
parents: 10575
diff changeset
   227
2c21bc80c95d Implement GetCurrentDir in the c rtl
koda
parents: 10575
diff changeset
   228
    if (getcwd(cwd, sizeof(cwd)) != NULL)
2c21bc80c95d Implement GetCurrentDir in the c rtl
koda
parents: 10575
diff changeset
   229
        return cwd;
2c21bc80c95d Implement GetCurrentDir in the c rtl
koda
parents: 10575
diff changeset
   230
2c21bc80c95d Implement GetCurrentDir in the c rtl
koda
parents: 10575
diff changeset
   231
    IOResult = IO_ERROR_DUMMY;
2c21bc80c95d Implement GetCurrentDir in the c rtl
koda
parents: 10575
diff changeset
   232
    return "";
2c21bc80c95d Implement GetCurrentDir in the c rtl
koda
parents: 10575
diff changeset
   233
}
2c21bc80c95d Implement GetCurrentDir in the c rtl
koda
parents: 10575
diff changeset
   234
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   235
void __attribute__((overloadable)) fpcrtl_flush(Text f) {
9966
01e198990211 pas2c engine now writes debug log
unc0rr
parents: 7983
diff changeset
   236
    fflush(f->fp);
7983
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   237
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   238
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   239
void __attribute__((overloadable)) fpcrtl_flush(FILE *f) {
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   240
    fflush(f);
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   241
}
02f36c3e7f6c add xymeng's rtl port
koda
parents:
diff changeset
   242