source: git/src/useful.c @ 1b71c05

RELEASE/1.0
Last change on this file since 1b71c05 was 1b71c05, checked in by Olly Betts <olly@…>, 14 years ago

src/: Update FSF address in (C) notices in source files.

git-svn-id: file:///home/survex-svn/survex/branches/1.0@3463 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/* useful.c
2 * Copyright (C) 1993-2001,2003 Olly Betts
3 *
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.
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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18
19#ifdef HAVE_CONFIG_H
20# include <config.h>
21#endif
22
23#include "useful.h"
24#include "osdepend.h"
25
26#ifndef WORDS_BIGENDIAN
27
28/* used by macro versions of useful_get<nn> functions */
29INT16_T useful_w16;
30INT32_T useful_w32;
31
32#if 0 /* these functions aren't needed - macros do the job */
33/* the numbers in the file are little endian, so use fread/fwrite */
34extern void Far
35useful_put16(INT16_T w, FILE *fh)
36{
37   fwrite(&w, 2, 1, fh);
38}
39
40#undef useful_put32
41extern void Far
42useful_put32(INT32_T w, FILE *fh)
43{
44   fwrite(&w, 4, 1, fh);
45}
46
47#undef useful_get16
48extern INT16_T Far
49useful_get16(FILE *fh)
50{
51   INT16_T w;
52   fread(&w, 2, 1, fh);
53   return w;
54}
55
56#undef useful_put32
57extern INT32_T Far
58useful_get32(FILE *fh)
59{
60   INT32_T w;
61   fread(&w, 4, 1, fh);
62   return w;
63}
64#endif
65
66#else
67
68extern void Far
69useful_put16(INT16_T w, FILE *fh)
70{
71   putc((char)(w), fh);
72   putc((char)(w >> 8l), fh);
73}
74
75extern void Far
76useful_put32(INT32_T w, FILE *fh)
77{
78   putc((char)(w), fh);
79   putc((char)(w >> 8l), fh);
80   putc((char)(w >> 16l), fh);
81   putc((char)(w >> 24l), fh);
82}
83
84extern INT16_T Far
85useful_get16(FILE *fh)
86{
87   INT16_T w;
88   w = getc(fh);
89   w |= (INT16_T)(getc(fh) << 8l);
90   return w;
91}
92
93extern INT32_T Far
94useful_get32(FILE *fh)
95{
96   INT32_T w;
97   w = getc(fh);
98   w |= (INT32_T)(getc(fh) << 8l);
99   w |= (INT32_T)(getc(fh) << 16l);
100   w |= (INT32_T)(getc(fh) << 24l);
101   return w;
102}
103#endif
Note: See TracBrowser for help on using the repository browser.