Subversion Repositories filter_foundry

Rev

Rev 193 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /*
  2.         This file is part of a common library
  3.     Copyright (C) 2002-6 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. /* BigEndian and LittleEndian file I/O for long words, short words, and bytes */
  21.  
  22. #include "file_io.h"
  23.  
  24. OSErr read4B(FILEREF f,long *v){
  25.         unsigned char p[4];
  26.         FILECOUNT count = 4;
  27.         OSErr e = FSRead(f,&count,p);
  28.         if( !e )
  29.                 *v = ((long)p[0]<<24) | ((long)p[1]<<16) | ((long)p[2]<<8) | (long)p[3];
  30.         return e;
  31. }
  32.  
  33. OSErr read2B(FILEREF f,short *v){
  34.         unsigned char p[2];
  35.         FILECOUNT count = 2;
  36.         OSErr e = FSRead(f,&count,p);
  37.         if( !e )
  38.                 *v = (p[0]<<8) | p[1];
  39.         return e;
  40. }
  41.  
  42. OSErr read4L(FILEREF f,long *v){
  43.         unsigned char p[4];
  44.         FILECOUNT count = 4;
  45.         OSErr e = FSRead(f,&count,p);
  46.         if( !e )
  47.                 *v = ((long)p[3]<<24) | ((long)p[2]<<16) | ((long)p[1]<<8) | (long)p[0];
  48.         return e;
  49. }
  50.  
  51. OSErr read2L(FILEREF f,short *v){
  52.         unsigned char p[2];
  53.         FILECOUNT count = 2;
  54.         OSErr e = FSRead(f,&count,p);
  55.         if( !e )
  56.                 *v = (p[1]<<8) | p[0];
  57.         return e;
  58. }
  59.  
  60. OSErr read1(FILEREF f,unsigned char *v){
  61.         FILECOUNT count = 1;
  62.         return FSRead(f,&count,v);
  63. }
  64.  
  65. OSErr write4B(FILEREF f,long v){
  66.         unsigned char p[4];
  67.         FILECOUNT count = 4;
  68.         p[3] = v;
  69.         p[2] = v>>8;
  70.         p[1] = v>>16;
  71.         p[0] = v>>24;
  72.         return FSWrite(f,&count,p);
  73. }
  74.  
  75. OSErr write2B(FILEREF f,short v){
  76.         unsigned char p[2];
  77.         FILECOUNT count = 2;
  78.         p[1] = v;
  79.         p[0] = v>>8;
  80.         return FSWrite(f,&count,p);
  81. }
  82.  
  83. OSErr write4L(FILEREF f,long v){
  84.         unsigned char p[4];
  85.         FILECOUNT count = 4;
  86.         p[0] = v;
  87.         p[1] = v>>8;
  88.         p[2] = v>>16;
  89.         p[3] = v>>24;
  90.         return FSWrite(f,&count,p);
  91. }
  92.  
  93. OSErr write2L(FILEREF f,short v){
  94.         unsigned char p[2];
  95.         FILECOUNT count = 2;
  96.         p[0] = v;
  97.         p[1] = v>>8;
  98.         return FSWrite(f,&count,p);
  99. }
  100.  
  101. OSErr write1(FILEREF f,unsigned char v){
  102.         FILECOUNT count = 1;
  103.         return FSWrite(f,&count,&v);
  104. }
  105.  
  106.