misc.c

Tue, 17 Oct 2006 00:32:05 +0200

author
Tuomo Valkonen <tuomov@iki.fi>
date
Tue, 17 Oct 2006 00:32:05 +0200
changeset 103
76174c5f04b5
parent 80
c60bc05a6d38
permissions
-rw-r--r--

Path fix

0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
1 /*
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
2 * libtu/misc.c
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
3 *
36
63cd573ffbcf trunk: changeset 39
tuomov
parents: 32
diff changeset
4 * Copyright (c) Tuomo Valkonen 1999-2002.
53
f8f9366b359c trunk: changeset 57
tuomov
parents: 42
diff changeset
5 *
f8f9366b359c trunk: changeset 57
tuomov
parents: 42
diff changeset
6 * You may distribute and modify this library under the terms of either
f8f9366b359c trunk: changeset 57
tuomov
parents: 42
diff changeset
7 * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
8 */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
9
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
10 #include <stdlib.h>
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
11 #include <stdio.h>
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
12 #include <string.h>
64
f20d97d852ce trunk: changeset 1362
tuomov
parents: 63
diff changeset
13 #include <ctype.h>
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
14
70
e866dc825481 trunk: changeset 1408
tuomov
parents: 64
diff changeset
15 #include "misc.h"
80
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 70
diff changeset
16 #include "output.h"
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
17
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
18
1
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
19 void *malloczero(size_t size)
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
20 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
21 void *p=malloc(size);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
22
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
23 if(p!=NULL)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
24 memset(p, 0, size);
80
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 70
diff changeset
25 else
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 70
diff changeset
26 warn_err();
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
27
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
28 return p;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
29 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
30
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
31
1
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
32 void *remalloczero(void *ptr, size_t oldsize, size_t newsize)
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
33 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
34 void *p=NULL;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
35
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
36 if(newsize!=0){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
37 p=realloc(ptr, newsize);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
38
80
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 70
diff changeset
39 if(p==NULL){
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 70
diff changeset
40 warn_err();
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
41 return NULL;
80
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 70
diff changeset
42 }
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
43
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
44 if(newsize>oldsize)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
45 memset((char*)p+oldsize, 0, newsize-oldsize);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
46 }
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
47
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
48 return p;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
49 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
50
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
51
63
5b732dd506d3 trunk: changeset 1360
tuomov
parents: 62
diff changeset
52 char *scopyn(const char *p, size_t l)
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
53 {
80
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 70
diff changeset
54 char *pn=ALLOC_N(char, l+1);
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
55
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
56 if(pn==NULL)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
57 return NULL;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
58
64
f20d97d852ce trunk: changeset 1362
tuomov
parents: 63
diff changeset
59 memcpy(pn, p, l);
f20d97d852ce trunk: changeset 1362
tuomov
parents: 63
diff changeset
60 pn[l]='\0';
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
61
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
62 return pn;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
63 }
63
5b732dd506d3 trunk: changeset 1360
tuomov
parents: 62
diff changeset
64
5b732dd506d3 trunk: changeset 1360
tuomov
parents: 62
diff changeset
65
5b732dd506d3 trunk: changeset 1360
tuomov
parents: 62
diff changeset
66 char *scopy(const char *p)
5b732dd506d3 trunk: changeset 1360
tuomov
parents: 62
diff changeset
67 {
5b732dd506d3 trunk: changeset 1360
tuomov
parents: 62
diff changeset
68 size_t l=strlen(p);
5b732dd506d3 trunk: changeset 1360
tuomov
parents: 62
diff changeset
69 return scopyn(p, l);
5b732dd506d3 trunk: changeset 1360
tuomov
parents: 62
diff changeset
70 }
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
71
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
72
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
73 char *scat(const char *p1, const char *p2)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
74 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
75 size_t l1, l2;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
76 char*pn;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
77
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
78 l1=strlen(p1);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
79 l2=strlen(p2);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
80
80
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 70
diff changeset
81 pn=ALLOC_N(char, l1+l2+1);
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
82
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
83 if(pn==NULL)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
84 return NULL;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
85
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
86 memcpy(pn, p1, l1);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
87 memcpy(pn+l1, p2, l2+1);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
88
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
89 return pn;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
90 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
91
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
92
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
93 char *scat3(const char *p1, const char *p2, const char *p3)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
94 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
95 size_t l1, l2, l3;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
96 char *pn;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
97
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
98 l1=strlen(p1);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
99 l2=strlen(p2);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
100 l3=strlen(p3);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
101
80
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 70
diff changeset
102 pn=ALLOC_N(char, l1+l2+l3+1);
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
103
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
104 if(pn==NULL)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
105 return NULL;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
106
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
107 memcpy(pn, p1, l1);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
108 memcpy(pn+l1, p2, l2);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
109 memcpy(pn+l1+l2, p3, l3+1);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
110
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
111 return pn;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
112 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
113
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
114
1
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
115 char *scatn(const char *s1, ssize_t l1, const char *s2, ssize_t l2)
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
116 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
117 size_t tlen=1;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
118 char *s;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
119
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
120 if(l1<0)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
121 l1=strlen(s1);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
122
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
123 if(l2<0)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
124 l2=strlen(s2);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
125
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
126 tlen+=l1+l2;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
127
80
c60bc05a6d38 trunk: changeset 1692
tuomov
parents: 70
diff changeset
128 s=ALLOC_N(char, tlen);
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
129
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
130 if(s==NULL)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
131 return NULL;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
132
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
133 memcpy(s, s1, l1);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
134 memcpy(s+l1, s2, l2);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
135 s[l1+l2]='\0';
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
136
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
137 return s;
1
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
138 }
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
139
6e704fc09528 trunk: changeset 4
tuomov
parents: 0
diff changeset
140
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
141 /* */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
142
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
143
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
144 const char *simple_basename(const char *name)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
145 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
146 const char *p;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
147
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
148 p=name+strlen(name)-1;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
149
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
150 /* Skip any trailing slashes */
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
151 while(*p=='/'){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
152 /* root? */
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
153 if(p==name)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
154 return name;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
155 p--;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
156 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
157
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
158 while(p!=name){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
159 if(*p=='/')
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
160 return p+1;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
161 p--;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
162 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
163
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
164 return name;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
165 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
166
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
167
32
7e74a8d61b76 trunk: changeset 35
tuomov
parents: 9
diff changeset
168 void stripws(char *p)
7e74a8d61b76 trunk: changeset 35
tuomov
parents: 9
diff changeset
169 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
170 int l;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
171
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
172 l=strspn(p, " ");
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
173 if(l!=0)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
174 strcpy(p, p+l);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
175 l=strlen(p);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
176
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
177 while(--l>=0){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
178 if(*(p+l)!=' ')
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
179 break;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
180 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
181 *(p+l+1)='\0';
32
7e74a8d61b76 trunk: changeset 35
tuomov
parents: 9
diff changeset
182 }
7e74a8d61b76 trunk: changeset 35
tuomov
parents: 9
diff changeset
183
7e74a8d61b76 trunk: changeset 35
tuomov
parents: 9
diff changeset
184
64
f20d97d852ce trunk: changeset 1362
tuomov
parents: 63
diff changeset
185 const char *libtu_strcasestr(const char *str, const char *ptn)
f20d97d852ce trunk: changeset 1362
tuomov
parents: 63
diff changeset
186 {
f20d97d852ce trunk: changeset 1362
tuomov
parents: 63
diff changeset
187 const char *s2, *p2;
f20d97d852ce trunk: changeset 1362
tuomov
parents: 63
diff changeset
188 for(; *str; str++) {
f20d97d852ce trunk: changeset 1362
tuomov
parents: 63
diff changeset
189 for(s2=str, p2=ptn; ; s2++, p2++) {
f20d97d852ce trunk: changeset 1362
tuomov
parents: 63
diff changeset
190 if(!*p2)
f20d97d852ce trunk: changeset 1362
tuomov
parents: 63
diff changeset
191 return str;
f20d97d852ce trunk: changeset 1362
tuomov
parents: 63
diff changeset
192 if(toupper(*s2)!=toupper(*p2))
f20d97d852ce trunk: changeset 1362
tuomov
parents: 63
diff changeset
193 break;
f20d97d852ce trunk: changeset 1362
tuomov
parents: 63
diff changeset
194 }
f20d97d852ce trunk: changeset 1362
tuomov
parents: 63
diff changeset
195 }
f20d97d852ce trunk: changeset 1362
tuomov
parents: 63
diff changeset
196 return NULL;
f20d97d852ce trunk: changeset 1362
tuomov
parents: 63
diff changeset
197 }
f20d97d852ce trunk: changeset 1362
tuomov
parents: 63
diff changeset
198
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
199 /* */
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
200
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
201
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
202 bool readf(FILE *f, void *buf, size_t n)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
203 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
204 return fread(buf, 1, n, f)!=1;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
205 }
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
206
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
207
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
208 bool writef(FILE *f, const void *buf, size_t n)
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
209 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 53
diff changeset
210 return fwrite(buf, 1, n, f)!=1;
0
86b7f6f9c5c0 Tailorization of trunk
tailor@f281.ttorni.ton.tut.fi
parents:
diff changeset
211 }

mercurial