Subversion Repositories filter_foundry

Rev

Rev 193 | Rev 268 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*
  2.         This file is part of a common library
  3.     Copyright (C) 2002-2010 Toby Thain, toby@telegraphics.com.au
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18. */
  19.  
  20. #ifndef FILE_COMPAT_H
  21. #define FILE_COMPAT_H
  22.  
  23. #ifdef macintosh
  24.  
  25.         #include <files.h>
  26.  
  27.         #ifndef _INT16_T
  28.                 typedef SInt16 int16_t;
  29.         #endif
  30.         #if !defined(_INT16_T) && !defined(_MACHTYPES_H_)
  31.                 typedef SInt32 int32_t;
  32.         #endif
  33.  
  34.         #if defined(WANT_LARGE_FILES) && ! TARGET_CPU_68K
  35.                 // large file support (HFS+)
  36.                 typedef SInt16 FILEREF;
  37.                 typedef SInt64 FILEPOS;
  38.                 typedef ByteCount FILECOUNT;
  39.  
  40.                 #define FSPOPENDF fspopendf_large
  41.                 #define FSCLOSE FSCloseFork
  42.                 #define FSREAD fsread_large
  43.                 #define FSWRITE fswrite_large
  44.                 #define GETFPOS getfpos_large
  45.                 #define SETFPOS setfpos_large
  46.                 #define GETEOF geteof_large
  47.                 #define SETEOF seteof_large
  48.  
  49.                 Boolean host_has_forks(void);
  50.         #else
  51.                 // old-style HFS
  52.                 typedef short FILEREF;
  53.                 typedef long FILEPOS,FILECOUNT;
  54.  
  55.                 #define FSPOPENDF FSpOpenDF
  56.                 #define FSCLOSE FSClose
  57.                 #define FSREAD FSRead
  58.                 #define FSWRITE FSWrite
  59.                 #define GETFPOS GetFPos
  60.                 #define SETFPOS SetFPos
  61.                 #define GETEOF GetEOF
  62.                 #define SETEOF SetEOF
  63.  
  64.                 #define host_has_forks() false
  65.         #endif
  66.  
  67.         extern Boolean has_forks;
  68.  
  69. #else // not macintosh
  70.         /* allow for the situation where _WIN32 is defined BUT we are building a DOS executable
  71.            and wish to use mingw's UNIX compatibility libraries such as stdio;
  72.            check the variable CMDLINE defined for this purpose in such a Makefile. */
  73.  
  74.         #if defined(_WIN32) && ! defined(CMDLINE)
  75.  
  76.                 #include "compat_win.h"
  77.  
  78.                 typedef INT16 int16_t;
  79.                 typedef INT32 int32_t;
  80.  
  81.                 #ifndef INVALID_SET_FILE_POINTER
  82.                         #define INVALID_SET_FILE_POINTER 0xffffffff
  83.                 #endif
  84.  
  85.                 typedef HANDLE FILEREF;
  86.                 typedef LONG FILECOUNT;
  87.  
  88.                 #define FSPOPENDF FSpOpenDF
  89.                 #define FSREAD FSRead
  90.                 #define FSWRITE FSWrite
  91.  
  92.                 #ifdef WANT_LARGE_FILES
  93.                         typedef UINT64 FILEPOS;
  94.                         #define GETFPOS getfpos_large
  95.                         #define SETFPOS setfpos_large
  96.                         #define GETEOF geteof_large
  97.                 #else
  98.                         typedef DWORD FILEPOS;
  99.                         #define GETFPOS GetFPos
  100.                         #define SETFPOS SetFPos
  101.                         #define GETEOF GetEOF
  102.                 #endif
  103.  
  104.                 OSErr FSpOpenDF(const FSSpec *spec, int permission, FILEREF *refNum);
  105.                 OSErr FSpCreate(const FSSpec *spec, OSType creator, OSType fileType, ScriptCode scriptTag);
  106.                 OSErr FSpDelete(const FSSpec *spec);
  107.         #else
  108.                 // UNIX
  109.                 #include <stdio.h>
  110.                 #include <stdint.h>
  111.  
  112.                 typedef FILE *FILEREF;
  113.                 #ifdef WANT_LARGE_FILES
  114.                         typedef fpos_t FILEPOS;
  115.                 #else
  116.                         typedef long FILEPOS;
  117.                 #endif
  118.                 typedef long FILECOUNT;
  119.                 typedef char *FSSpec;/*???*/
  120.                 typedef int OSErr;
  121.  
  122.                 #define noErr 0
  123.                 #define ioErr                           (-36)
  124.  
  125.                 #define FSREAD FSRead
  126.                 #define FSWRITE FSWrite
  127.         #endif
  128.  
  129.                 enum {
  130.                         fsCurPerm                                       = 0,
  131.                         fsRdPerm                                        = 1,
  132.                         fsWrPerm                                        = 2,
  133.                         fsRdWrPerm                                      = 3,
  134.                 };
  135.                 enum {
  136.                   fsAtMark                      = 0,    /* positioning modes in ioPosMode */
  137.                   fsFromStart                   = 1,
  138.                   fsFromLEOF                    = 2,
  139.                   fsFromMark                    = 3
  140.                 };
  141.  
  142.                 OSErr FSClose(FILEREF f);
  143.                 OSErr FSRead(FILEREF f, FILECOUNT *count, void *buffPtr);
  144.                 OSErr FSWrite(FILEREF f, FILECOUNT *count, const void *buffPtr);
  145.                 OSErr GetFPos(FILEREF   refNum,FILEPOS *  filePos);
  146.                 OSErr SetFPos(FILEREF   refNum,short   posMode,long    posOff);
  147.                 OSErr GetEOF(FILEREF   refNum,FILEPOS *  logEOF);
  148.                 OSErr SetEOF(FILEREF   refNum,FILEPOS logEOF);
  149.                 /*
  150.                 HMODULE FSpOpenResFile(const FSSpec *  spec,SignedByte      permission);
  151.                 void CloseResFile(HMODULE hmodule);
  152.                 HGLOBAL GetResource(ResType   theType,short     theID);
  153.                 */
  154.  
  155. #endif
  156.  
  157. OSErr fspopendf_large(const FSSpec *spec, int perm, FILEREF *refNum);
  158. OSErr fsread_large(FILEREF refNum, FILECOUNT *count, void *buffPtr);
  159. OSErr fswrite_large(FILEREF refNum, FILECOUNT *count, void *buffPtr);
  160. OSErr getfpos_large(FILEREF refNum, FILEPOS *filePos);
  161. OSErr setfpos_large(FILEREF refNum, short posMode, FILEPOS posOff);
  162. OSErr geteof_large(FILEREF refNum, FILEPOS *logEOF);
  163. OSErr seteof_large(FILEREF refNum, FILEPOS logEOF);
  164.  
  165. #endif
  166.