extras/abs-file.h
author Ryan C. Gordon <icculus@icculus.org>
Wed, 03 Oct 2018 22:45:05 -0400
branchstable-1.0
changeset 1648 93b4c3bc6b9d
parent 578 bff1af8455ca
child 654 c0ae01de361d
permissions -rw-r--r--
Fixed Win10's GetUserProfileDirectory() bug in stable-1.0 branch.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
485
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
562
1e307df36810 Minor patches from Adam.
Ryan C. Gordon <icculus@icculus.org>
parents: 512
diff changeset
     2
 * stdio/physfs abstraction layer 2003-04-02
485
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
 *
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
 * Adam D. Moss <adam@gimp.org> <aspirin@icculus.org>
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
 *
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
 * These wrapper macros and functions are designed to allow a program
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
 * to perform file I/O with identical semantics and syntax regardless
512
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
     8
 * of whether PhysicsFS is being used or not.
485
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
 */
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
#ifndef _ABS_FILE_H
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
#define _ABS_FILE_H
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
/*
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
PLEASE NOTE: This license applies to abs-file.h ONLY (to make it clear that
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
you may embed this wrapper code within commercial software); PhysicsFS itself
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
is (at the time of writing) released under a different license with
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
additional restrictions.
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
562
1e307df36810 Minor patches from Adam.
Ryan C. Gordon <icculus@icculus.org>
parents: 512
diff changeset
    18
Copyright (C) 2002-2003 Adam D. Moss (the "Author").  All Rights Reserved.
485
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
Permission is hereby granted, free of charge, to any person obtaining a copy
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
of this software and associated documentation files (the "Software"), to deal
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
in the Software without restriction, including without limitation the rights
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
copies of the Software, and to permit persons to whom the Software is fur-
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
nished to do so, subject to the following conditions:
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
The above copyright notice and this permission notice shall be included in
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
all copies or substantial portions of the Software.
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON-
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
Except as contained in this notice, the name of the Author of the
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
Software shall not be used in advertising or otherwise to promote the sale,
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
use or other dealings in this Software without prior written authorization
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
from the Author.
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
*/
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
#include <stdlib.h>
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
#include <stdio.h>
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
512
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    46
/*
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    47
 * API:
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    48
 *
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    49
 * Macro/function       use like stdio equivalent...
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    50
 * --------------       ----------------------------
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    51
 * MY_FILETYPE          FILE
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    52
 * MY_OPEN_FOR_READ     fopen(..., "rb")
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    53
 * MY_READ              fread(...)
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    54
 * MY_CLOSE             fclose(...)
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    55
 * MY_GETC              fgetc(...)
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    56
 * MY_GETS              fgets(...)
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    57
 * MY_ATEOF             feof(...)
562
1e307df36810 Minor patches from Adam.
Ryan C. Gordon <icculus@icculus.org>
parents: 512
diff changeset
    58
 * MY_TELL              ftell(...)
1e307df36810 Minor patches from Adam.
Ryan C. Gordon <icculus@icculus.org>
parents: 512
diff changeset
    59
 * MY_SEEK              fseek(..., SEEK_SET)
512
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    60
 * MY_REWIND            rewind(...)
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    61
 * MY_SETBUFFER         (not a standard for stdio, does nothing there)
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    62
 */
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    63
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    64
/*
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    65
 * Important DEFINEs:
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    66
 *   It is important to define these consistantly across the various
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    67
 *   compilation modules of your program if you wish to exchange file
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    68
 *   handles between them.
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    69
 *
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    70
 *   USE_PHYSFS: Define USE_PHYSFS if PhysicsFS is being used; note that if
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    71
 *     you do intend to use PhysicsFS then you will still need to initialize
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    72
 *     PhysicsFS yourself and set up its search-paths.
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    73
 *
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    74
 * Optional DEFINEs:
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    75
 *
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    76
 *   PHYSFS_DEFAULT_READ_BUFFER <bytes>: If set then abs-file.h sets the
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    77
 *     PhysicsFS buffer size to this value whenever you open a file.  You
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    78
 *     may over-ride this on a per-filehandle basis by using the
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    79
 *     MY_SETBUFFER() macro (which simply does nothing when not using
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    80
 *     PhysicsFS).  If you have not defined this value explicitly then
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    81
 *     abs-file.h will default to the same default buffer size as used by
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    82
 *     stdio if it can be determined, or 8192 bytes otherwise.
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    83
 */
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    84
#ifndef PHYSFS_DEFAULT_READ_BUFFER
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    85
#ifdef BUFSIZ
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    86
#define PHYSFS_DEFAULT_READ_BUFFER BUFSIZ
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    87
#else
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    88
#define PHYSFS_DEFAULT_READ_BUFFER 8192
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    89
#endif
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    90
#endif
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    91
485
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
#ifdef USE_PHYSFS
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
#include <physfs.h>
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
#define MY_FILETYPE PHYSFS_file
512
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    96
#define MY_SETBUFFER(fp,size) PHYSFS_setBuffer(fp,size)
485
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
#define MY_READ(p,s,n,fp) PHYSFS_read(fp,p,s,n)
512
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    98
#if PHYSFS_DEFAULT_READ_BUFFER
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
    99
static MY_FILETYPE* MY_OPEN_FOR_READ(const char *const filename)
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
   100
{
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
   101
  MY_FILETYPE *const file = PHYSFS_openRead(filename);
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
   102
  if (file) {
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
   103
    MY_SETBUFFER(file, PHYSFS_DEFAULT_READ_BUFFER);
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
   104
  }
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
   105
  return file;
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
   106
}
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
   107
#else
485
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
#define MY_OPEN_FOR_READ(fn) PHYSFS_openRead(fn)
512
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
   109
#endif
5ed9ffa3ad8f Updates from Adam Moss for new buffering API.
Ryan C. Gordon <icculus@icculus.org>
parents: 485
diff changeset
   110
static int MY_GETC(MY_FILETYPE *const fp) {
485
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
  unsigned char c;
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
  /*if (PHYSFS_eof(fp)) {
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
    return EOF;
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
  }
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
  MY_READ(&c, 1, 1, fp);*/
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
  if (MY_READ(&c, 1, 1, fp) != 1) {
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
    return EOF;
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
  }
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
  return c;
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
}
578
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
   121
static char * MY_GETS(char * const str, const int size, 
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
   122
                      MY_FILETYPE *const fp) {
485
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
  int i = 0;
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
  int c;
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
  do {
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
    if (i == size-1) {
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
      break;
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
    }
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
    c = MY_GETC(fp);
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
    if (c == EOF) {
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
      break;
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
    }
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
    str[i++] = c;
578
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
   134
  } while (c != '\0' && 
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
   135
      c != -1 && 
bff1af8455ca Tabs-to-spaces patch by James Turk.
Ryan C. Gordon <icculus@icculus.org>
parents: 562
diff changeset
   136
      c != '\n');
485
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
  str[i] = '\0';
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
  if (i == 0) {
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
    return NULL;
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
  }
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
  return str;
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
}
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
#define MY_CLOSE(fp) PHYSFS_close(fp)
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
#define MY_ATEOF(fp) PHYSFS_eof(fp)
562
1e307df36810 Minor patches from Adam.
Ryan C. Gordon <icculus@icculus.org>
parents: 512
diff changeset
   145
#define MY_TELL(fp) PHYSFS_tell(fp)
1e307df36810 Minor patches from Adam.
Ryan C. Gordon <icculus@icculus.org>
parents: 512
diff changeset
   146
#define MY_SEEK(fp,o) PHYSFS_seek(fp,o)
1e307df36810 Minor patches from Adam.
Ryan C. Gordon <icculus@icculus.org>
parents: 512
diff changeset
   147
#define MY_REWIND(fp) MY_SEEK(fp,0)
485
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
#else
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
#define MY_FILETYPE FILE
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
#define MY_READ(p,s,n,fp) fread(p,s,n,fp)
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
#define MY_OPEN_FOR_READ(n) fopen(n, "rb")
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
#define MY_GETC(fp) fgetc(fp)
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
#define MY_GETS(str,size,fp) fgets(str,size,fp)
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
#define MY_CLOSE(fp) fclose(fp)
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
#define MY_ATEOF(fp) feof(fp)
562
1e307df36810 Minor patches from Adam.
Ryan C. Gordon <icculus@icculus.org>
parents: 512
diff changeset
   158
#define MY_TELL(fp) ftell(fp)
1e307df36810 Minor patches from Adam.
Ryan C. Gordon <icculus@icculus.org>
parents: 512
diff changeset
   159
#define MY_SEEK(fp,o) fseek(fp,o, SEEK_SET)
485
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
#define MY_REWIND(fp) rewind(fp)
562
1e307df36810 Minor patches from Adam.
Ryan C. Gordon <icculus@icculus.org>
parents: 512
diff changeset
   161
/*static void MY_SETBUFFER(const MY_FILETYPE *const file, const int num) { }*/
1e307df36810 Minor patches from Adam.
Ryan C. Gordon <icculus@icculus.org>
parents: 512
diff changeset
   162
#define MY_SETBUFFER(fp,size)
485
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
#endif
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
53355a5a6096 Initial add.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
#endif