| [421b7d2] | 1 | /* useful.c | 
|---|
| [64d37a3] | 2 |  * Copyright (C) 1993-2001,2003 Olly Betts | 
|---|
| [846746e] | 3 |  * | 
|---|
| [89231c4] | 4 |  * This program is free software; you can redistribute it and/or modify | 
|---|
 | 5 |  * it under the terms of the GNU General Public License as published by | 
|---|
 | 6 |  * the Free Software Foundation; either version 2 of the License, or | 
|---|
 | 7 |  * (at your option) any later version. | 
|---|
| [846746e] | 8 |  * | 
|---|
 | 9 |  * This program is distributed in the hope that it will be useful, | 
|---|
 | 10 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| [89231c4] | 11 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
 | 12 |  * GNU General Public License for more details. | 
|---|
| [846746e] | 13 |  * | 
|---|
| [89231c4] | 14 |  * You should have received a copy of the GNU General Public License | 
|---|
 | 15 |  * along with this program; if not, write to the Free Software | 
|---|
 | 16 |  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA | 
|---|
| [d1b1380] | 17 |  */ | 
|---|
 | 18 |  | 
|---|
| [a420b49] | 19 | #ifdef HAVE_CONFIG_H | 
|---|
 | 20 | # include <config.h> | 
|---|
 | 21 | #endif | 
|---|
| [d1b1380] | 22 |  | 
|---|
 | 23 | #include "useful.h" | 
|---|
 | 24 | #include "osdepend.h" | 
|---|
 | 25 |  | 
|---|
| [f149799] | 26 | #ifndef WORDS_BIGENDIAN | 
|---|
| [d1b1380] | 27 |  | 
|---|
 | 28 | /* used by macro versions of useful_get<nn> functions */ | 
|---|
| [647407d] | 29 | INT16_T useful_w16; | 
|---|
 | 30 | INT32_T useful_w32; | 
|---|
| [d1b1380] | 31 |  | 
|---|
| [a420b49] | 32 | #if 0 /* these functions aren't needed - macros do the job */ | 
|---|
| [d1b1380] | 33 | /* the numbers in the file are little endian, so use fread/fwrite */ | 
|---|
| [64d37a3] | 34 | extern void Far | 
|---|
| [647407d] | 35 | useful_put16(INT16_T w, FILE *fh) | 
|---|
| [a420b49] | 36 | { | 
|---|
 | 37 |    fwrite(&w, 2, 1, fh); | 
|---|
| [d1b1380] | 38 | } | 
|---|
 | 39 |  | 
|---|
| [a420b49] | 40 | #undef useful_put32 | 
|---|
| [64d37a3] | 41 | extern void Far | 
|---|
| [647407d] | 42 | useful_put32(INT32_T w, FILE *fh) | 
|---|
| [a420b49] | 43 | { | 
|---|
 | 44 |    fwrite(&w, 4, 1, fh); | 
|---|
| [d1b1380] | 45 | } | 
|---|
 | 46 |  | 
|---|
| [a420b49] | 47 | #undef useful_get16 | 
|---|
| [64d37a3] | 48 | extern INT16_T Far | 
|---|
| [a420b49] | 49 | useful_get16(FILE *fh) | 
|---|
 | 50 | { | 
|---|
| [647407d] | 51 |    INT16_T w; | 
|---|
| [a420b49] | 52 |    fread(&w, 2, 1, fh); | 
|---|
| [d1b1380] | 53 |    return w; | 
|---|
 | 54 | } | 
|---|
 | 55 |  | 
|---|
| [a420b49] | 56 | #undef useful_put32 | 
|---|
| [64d37a3] | 57 | extern INT32_T Far | 
|---|
| [a420b49] | 58 | useful_get32(FILE *fh) | 
|---|
 | 59 | { | 
|---|
| [4beccdbc] | 60 |    INT32_T w; | 
|---|
| [a420b49] | 61 |    fread(&w, 4, 1, fh); | 
|---|
| [d1b1380] | 62 |    return w; | 
|---|
 | 63 | } | 
|---|
| [a420b49] | 64 | #endif | 
|---|
| [d1b1380] | 65 |  | 
|---|
 | 66 | #else | 
|---|
 | 67 |  | 
|---|
| [64d37a3] | 68 | extern void Far | 
|---|
| [647407d] | 69 | useful_put16(INT16_T w, FILE *fh) | 
|---|
| [a420b49] | 70 | { | 
|---|
 | 71 |    putc((char)(w), fh); | 
|---|
 | 72 |    putc((char)(w >> 8l), fh); | 
|---|
| [d1b1380] | 73 | } | 
|---|
 | 74 |  | 
|---|
| [64d37a3] | 75 | extern void Far | 
|---|
| [647407d] | 76 | useful_put32(INT32_T w, FILE *fh) | 
|---|
| [a420b49] | 77 | { | 
|---|
 | 78 |    putc((char)(w), fh); | 
|---|
 | 79 |    putc((char)(w >> 8l), fh); | 
|---|
 | 80 |    putc((char)(w >> 16l), fh); | 
|---|
 | 81 |    putc((char)(w >> 24l), fh); | 
|---|
| [d1b1380] | 82 | } | 
|---|
 | 83 |  | 
|---|
| [64d37a3] | 84 | extern INT16_T Far | 
|---|
| [a420b49] | 85 | useful_get16(FILE *fh) | 
|---|
 | 86 | { | 
|---|
| [647407d] | 87 |    INT16_T w; | 
|---|
| [a420b49] | 88 |    w = getc(fh); | 
|---|
| [647407d] | 89 |    w |= (INT16_T)(getc(fh) << 8l); | 
|---|
| [d1b1380] | 90 |    return w; | 
|---|
 | 91 | } | 
|---|
 | 92 |  | 
|---|
| [64d37a3] | 93 | extern INT32_T Far | 
|---|
| [a420b49] | 94 | useful_get32(FILE *fh) | 
|---|
 | 95 | { | 
|---|
| [647407d] | 96 |    INT32_T w; | 
|---|
| [a420b49] | 97 |    w = getc(fh); | 
|---|
| [4beccdbc] | 98 |    w |= (INT32_T)(getc(fh) << 8l); | 
|---|
 | 99 |    w |= (INT32_T)(getc(fh) << 16l); | 
|---|
 | 100 |    w |= (INT32_T)(getc(fh) << 24l); | 
|---|
| [d1b1380] | 101 |    return w; | 
|---|
 | 102 | } | 
|---|
 | 103 | #endif | 
|---|