comparison compat.c @ 101:a5da1ac53b34

Use long double instead of long long for drivesize and drivefree.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 06 Aug 2002 07:54:13 +0000
parents bb2b01c3122f
children 0fc45e386376
comparison
equal deleted inserted replaced
100:bb2b01c3122f 101:a5da1ac53b34
206 if(pipes[0] < 0 || pipes[1] < 0) 206 if(pipes[0] < 0 || pipes[1] < 0)
207 return -1; 207 return -1;
208 return 0; 208 return 0;
209 } 209 }
210 210
211 /* Return in K to avoid big problems exceeding an 211 long double drivefree(int drive)
212 unsigned long when no 64bit integers are available */
213 #if (defined(__IBMC__) && __IBMC__ < 360) || (defined(__WIN32__) && !defined(__CYGWIN32__))
214 unsigned long drivefree(int drive)
215 #else
216 unsigned long long drivefree(int drive)
217 #endif
218 { 212 {
219 #if defined(__EMX__) || defined(__OS2__) 213 #if defined(__EMX__) || defined(__OS2__)
220 ULONG aulFSInfoBuf[40] = {0}; 214 ULONG aulFSInfoBuf[40] = {0};
221 APIRET rc = NO_ERROR; 215 APIRET rc = NO_ERROR;
222 ULONG kbytes;
223 216
224 DosError(FERR_DISABLEHARDERR); 217 DosError(FERR_DISABLEHARDERR);
225 rc = DosQueryFSInfo(drive, 218 rc = DosQueryFSInfo(drive,
226 FSIL_ALLOC, 219 FSIL_ALLOC,
227 (PVOID)aulFSInfoBuf, 220 (PVOID)aulFSInfoBuf,
229 222
230 DosError(FERR_ENABLEHARDERR); 223 DosError(FERR_ENABLEHARDERR);
231 if (rc != NO_ERROR) 224 if (rc != NO_ERROR)
232 return 0; 225 return 0;
233 226
234 kbytes = aulFSInfoBuf[3]/1024; 227 return (long double)((double)aulFSInfoBuf[3] * (double)aulFSInfoBuf[1] * (double)aulFSInfoBuf[4]);
235
236 return (kbytes * aulFSInfoBuf[1] * aulFSInfoBuf[4]);
237 #elif defined(__WIN32__) || defined(WINNT) 228 #elif defined(__WIN32__) || defined(WINNT)
238 char buffer[10] = "C:\\"; 229 char buffer[10] = "C:\\";
239 DWORD spc, bps, fc, tc; 230 DWORD spc, bps, fc, tc;
240 ULONG kbytes;
241 231
242 buffer[0] = drive + 'A' - 1; 232 buffer[0] = drive + 'A' - 1;
243 233
244 if(GetDiskFreeSpace(buffer, &spc, &bps, &fc, &tc) == 0) 234 if(GetDiskFreeSpace(buffer, &spc, &bps, &fc, &tc) == 0)
245 return 0; 235 return 0;
246 236
247 kbytes = fc/1024; 237 return (long double)((double)spc*(double)bps*(double)fc);
248
249 return (spc*bps*kbytes);
250 #elif defined(__FreeBSD__) 238 #elif defined(__FreeBSD__)
251 struct statfs *fsp; 239 struct statfs *fsp;
252 int entries, index = 1; 240 int entries, index = 1;
253 241
254 entries = getmntinfo (&fsp, MNT_NOWAIT); 242 entries = getmntinfo (&fsp, MNT_NOWAIT);
255 243
256 for (; entries-- > 0; fsp++) 244 for (; entries-- > 0; fsp++)
257 { 245 {
258 if(index == drive) 246 if(index == drive)
259 return fsp->f_bsize * (fsp->f_bavail / 1024); 247 return (long double)((double)fsp->f_bsize * (double)fsp->f_bavail);
260 index++; 248 index++;
261 } 249 }
262 return 0; 250 return 0;
263 #elif defined(__sun__) 251 #elif defined(__sun__)
264 FILE *fp = fopen("/etc/mnttab", "r"); 252 FILE *fp = fopen("/etc/mnttab", "r");
270 { 258 {
271 while((getmntent(fp, &mnt) == 0)) 259 while((getmntent(fp, &mnt) == 0))
272 { 260 {
273 if(index == drive) 261 if(index == drive)
274 { 262 {
275 long long size = 0; 263 long double size = 0;
276 264
277 if(mnt.mnt_mountp) 265 if(mnt.mnt_mountp)
278 { 266 {
279 statfs(mnt.mnt_mountp, &sfs, sizeof(struct statfs), 0); 267 statfs(mnt.mnt_mountp, &sfs, sizeof(struct statfs), 0);
280 size = sfs.f_bsize * (sfs.f_bfree / 1024); 268 size = (long double)((double)sfs.f_bsize * (double)sfs.f_bfree);
281 } 269 }
282 fclose(fp); 270 fclose(fp);
283 return size; 271 return size;
284 } 272 }
285 index++; 273 index++;
297 { 285 {
298 while((mnt = getmntent(fp))) 286 while((mnt = getmntent(fp)))
299 { 287 {
300 if(index == drive) 288 if(index == drive)
301 { 289 {
302 long long size = 0; 290 long double size = 0;
303 291
304 if(mnt->mnt_dir) 292 if(mnt->mnt_dir)
305 { 293 {
306 statfs(mnt->mnt_dir, &sfs); 294 statfs(mnt->mnt_dir, &sfs);
307 size = sfs.f_bsize * (sfs.f_bavail / 1024); 295 size = (long double)((double)sfs.f_bsize * (double)sfs.f_bavail);
308 } 296 }
309 endmntent(fp); 297 endmntent(fp);
310 return size; 298 return size;
311 } 299 }
312 index++; 300 index++;
315 } 303 }
316 return 0; 304 return 0;
317 #endif 305 #endif
318 } 306 }
319 307
320 /* Return in K to avoid big problems exceeding an 308 long double drivesize(int drive)
321 unsigned long when no 64bit integers are available */
322 #if (defined(__IBMC__) && __IBMC__ < 360) || (defined(__WIN32__) && !defined(__CYGWIN32__))
323 unsigned long drivesize(int drive)
324 #else
325 unsigned long long drivesize(int drive)
326 #endif
327 { 309 {
328 #if defined(__EMX__) || defined(__OS2__) 310 #if defined(__EMX__) || defined(__OS2__)
329 ULONG aulFSInfoBuf[40] = {0}; 311 ULONG aulFSInfoBuf[40] = {0};
330 APIRET rc = NO_ERROR; 312 APIRET rc = NO_ERROR;
331 ULONG kbytes;
332 313
333 DosError(FERR_DISABLEHARDERR); 314 DosError(FERR_DISABLEHARDERR);
334 rc = DosQueryFSInfo(drive, 315 rc = DosQueryFSInfo(drive,
335 FSIL_ALLOC, 316 FSIL_ALLOC,
336 (PVOID)aulFSInfoBuf, 317 (PVOID)aulFSInfoBuf,
338 319
339 DosError(FERR_ENABLEHARDERR); 320 DosError(FERR_ENABLEHARDERR);
340 if (rc != NO_ERROR) 321 if (rc != NO_ERROR)
341 return 0; 322 return 0;
342 323
343 kbytes = aulFSInfoBuf[2]/1024; 324 return (long double)((double)aulFSInfoBuf[2] * (double)aulFSInfoBuf[1] * (double)aulFSInfoBuf[4]);
344
345 return (kbytes * aulFSInfoBuf[1] * aulFSInfoBuf[4]);
346 #elif defined(__WIN32__) || defined(WINNT) 325 #elif defined(__WIN32__) || defined(WINNT)
347 char buffer[10] = "C:\\"; 326 char buffer[10] = "C:\\";
348 DWORD spc, bps, fc, tc; 327 DWORD spc, bps, fc, tc;
349 ULONG kbytes;
350 328
351 buffer[0] = drive + 'A' - 1; 329 buffer[0] = drive + 'A' - 1;
352 330
353 if(GetDiskFreeSpace(buffer, &spc, &bps, &fc, &tc) == 0) 331 if(GetDiskFreeSpace(buffer, &spc, &bps, &fc, &tc) == 0)
354 return 0; 332 return 0;
355 333
356 kbytes = tc/1024; 334 return (long double)((double)spc*(double)bps*(double)tc);
357
358 return (spc*bps*kbytes);
359 #elif defined(__FreeBSD__) 335 #elif defined(__FreeBSD__)
360 struct statfs *fsp; 336 struct statfs *fsp;
361 int entries, index = 1; 337 int entries, index = 1;
362 338
363 entries = getmntinfo (&fsp, MNT_NOWAIT); 339 entries = getmntinfo (&fsp, MNT_NOWAIT);
364 340
365 for (; entries-- > 0; fsp++) 341 for (; entries-- > 0; fsp++)
366 { 342 {
367 if(index == drive) 343 if(index == drive)
368 return fsp->f_bsize * (fsp->f_blocks / 1024); 344 return (long double)((double)fsp->f_bsize * (double)fsp->f_blocks);
369 index++; 345 index++;
370 } 346 }
371 return 0; 347 return 0;
372 #elif defined(__sun__) 348 #elif defined(__sun__)
373 FILE *fp = fopen("/etc/mnttab", "r"); 349 FILE *fp = fopen("/etc/mnttab", "r");
379 { 355 {
380 while(getmntent(fp, &mnt) == 0) 356 while(getmntent(fp, &mnt) == 0)
381 { 357 {
382 if(index == drive) 358 if(index == drive)
383 { 359 {
384 long long size = 0; 360 long double size = 0;
385 361
386 if(mnt.mnt_mountp) 362 if(mnt.mnt_mountp)
387 { 363 {
388 statfs(mnt.mnt_mountp, &sfs, sizeof(struct statfs), 0); 364 statfs(mnt.mnt_mountp, &sfs, sizeof(struct statfs), 0);
389 size = sfs.f_bsize * (sfs.f_blocks / 1024); 365 size = (long double)((double)sfs.f_bsize * (double)sfs.f_blocks);
390 } 366 }
391 fclose(fp); 367 fclose(fp);
392 return size; 368 return size;
393 } 369 }
394 index++; 370 index++;
406 { 382 {
407 while((mnt = getmntent(fp))) 383 while((mnt = getmntent(fp)))
408 { 384 {
409 if(index == drive) 385 if(index == drive)
410 { 386 {
411 long long size = 0; 387 long double size = 0;
412 388
413 if(mnt->mnt_dir) 389 if(mnt->mnt_dir)
414 { 390 {
415 statfs(mnt->mnt_dir, &sfs); 391 statfs(mnt->mnt_dir, &sfs);
416 size = sfs.f_bsize * (sfs.f_blocks / 1024); 392 size = (long double)((double)sfs.f_bsize * (double)sfs.f_blocks);
417 } 393 }
418 endmntent(fp); 394 endmntent(fp);
419 return size; 395 return size;
420 } 396 }
421 index++; 397 index++;