| 65 |
cmwslw |
1 |
/* io.c -- io functions
|
|
|
2 |
|
|
|
3 |
This file is part of the UCL data compression library.
|
|
|
4 |
|
|
|
5 |
Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
|
|
6 |
All Rights Reserved.
|
|
|
7 |
|
|
|
8 |
The UCL library is free software; you can redistribute it and/or
|
|
|
9 |
modify it under the terms of the GNU General Public License as
|
|
|
10 |
published by the Free Software Foundation; either version 2 of
|
|
|
11 |
the License, or (at your option) any later version.
|
|
|
12 |
|
|
|
13 |
The UCL library is distributed in the hope that it will be useful,
|
|
|
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
16 |
GNU General Public License for more details.
|
|
|
17 |
|
|
|
18 |
You should have received a copy of the GNU General Public License
|
|
|
19 |
along with the UCL library; see the file COPYING.
|
|
|
20 |
If not, write to the Free Software Foundation, Inc.,
|
|
|
21 |
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
22 |
|
|
|
23 |
Markus F.X.J. Oberhumer
|
|
|
24 |
<markus@oberhumer.com>
|
|
|
25 |
http://www.oberhumer.com/opensource/ucl/
|
|
|
26 |
*/
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
#include "ucl_conf.h"
|
|
|
30 |
|
|
|
31 |
#if !defined(NO_STDIO_H)
|
|
|
32 |
|
|
|
33 |
#include <stdio.h>
|
|
|
34 |
#include <ucl/uclutil.h>
|
|
|
35 |
|
|
|
36 |
#undef ucl_fread
|
|
|
37 |
#undef ucl_fwrite
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
/***********************************************************************
|
|
|
41 |
//
|
|
|
42 |
************************************************************************/
|
|
|
43 |
|
|
|
44 |
UCL_PUBLIC(ucl_uint)
|
|
|
45 |
ucl_fread(FILE *f, ucl_voidp s, ucl_uint len)
|
|
|
46 |
{
|
|
|
47 |
#if 1 && (UCL_UINT_MAX <= SIZE_T_MAX)
|
|
|
48 |
return fread(s,1,len,f);
|
|
|
49 |
#else
|
|
|
50 |
ucl_byte *p = (ucl_byte *) s;
|
|
|
51 |
ucl_uint l = 0;
|
|
|
52 |
size_t k;
|
|
|
53 |
unsigned char *b;
|
|
|
54 |
unsigned char buf[512];
|
|
|
55 |
|
|
|
56 |
while (l < len)
|
|
|
57 |
{
|
|
|
58 |
k = len - l > sizeof(buf) ? sizeof(buf) : (size_t) (len - l);
|
|
|
59 |
k = fread(buf,1,k,f);
|
|
|
60 |
if (k <= 0)
|
|
|
61 |
break;
|
|
|
62 |
l += k;
|
|
|
63 |
b = buf; do *p++ = *b++; while (--k > 0);
|
|
|
64 |
}
|
|
|
65 |
return l;
|
|
|
66 |
#endif
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
/***********************************************************************
|
|
|
71 |
//
|
|
|
72 |
************************************************************************/
|
|
|
73 |
|
|
|
74 |
UCL_PUBLIC(ucl_uint)
|
|
|
75 |
ucl_fwrite(FILE *f, const ucl_voidp s, ucl_uint len)
|
|
|
76 |
{
|
|
|
77 |
#if 1 && (UCL_UINT_MAX <= SIZE_T_MAX)
|
|
|
78 |
return fwrite(s,1,len,f);
|
|
|
79 |
#else
|
|
|
80 |
const ucl_byte *p = (const ucl_byte *) s;
|
|
|
81 |
ucl_uint l = 0;
|
|
|
82 |
size_t k, n;
|
|
|
83 |
unsigned char *b;
|
|
|
84 |
unsigned char buf[512];
|
|
|
85 |
|
|
|
86 |
while (l < len)
|
|
|
87 |
{
|
|
|
88 |
k = len - l > sizeof(buf) ? sizeof(buf) : (size_t) (len - l);
|
|
|
89 |
b = buf; n = k; do *b++ = *p++; while (--n > 0);
|
|
|
90 |
k = fwrite(buf,1,k,f);
|
|
|
91 |
if (k <= 0)
|
|
|
92 |
break;
|
|
|
93 |
l += k;
|
|
|
94 |
}
|
|
|
95 |
return l;
|
|
|
96 |
#endif
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
#endif /* !defined(NO_STDIO_H) */
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
/*
|
|
|
104 |
vi:ts=4:et
|
|
|
105 |
*/
|