home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 December
/
VPR9712A.ISO
/
OLS
/
OS2
/
LHA2P205
/
LHA2P205.LZH
/
lha2-2.05pre
/
source.lzh
/
src
/
dosio.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-12-31
|
2KB
|
98 lines
/*
* dosio.c --- MS-DOS and IBM OS/2 dependent I/O
* Copyright (C) 1988-1992, Haruyasu YOSHIZAKI
* Copyright (C) 1991-1995, Satoshi HIRAMATSU (OS/2 HPFS version)
*
* $Log$
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <io.h>
#include <time.h>
#include "port2.h"
#include "typedef.h"
#include "lh.h"
time_t
#ifndef __SUPPORT_CTIME_ATIME__
getfiletime(FILE *f)
{
union stamp stamp;
unsigned date, time;
_dos_getftime(fileno(f), &date, &time);
stamp.t.date = 0xffff & date;
stamp.t.time = 0xffff & time;
return dos2unix(&stamp.s);
}
int
setfiletime(FILE *f, time_t utc)
{
union stamp *stamp;
unsigned date, time;
stamp = (union stamp *)unix2dos(utc);
fflush(f);
return _dos_setftime(fileno(f), stamp->t.date, stamp->t.time);
}
#else
getfiletime(FILE *f)
{
time_t mod, cre, acc;
_os2_getftime(fileno(f), &mod, &cre, &acc);
return mod;
}
int
setfiletime(FILE *f, time_t *mod, time_t *cre, time_t *acc)
{
fflush(f);
return _os2_setftime(fileno(f), mod, cre, acc);
}
#endif
static char
physicaldrive(char *filename)
{
if((isalpha(*filename) != 0) && (*(filename + 1)) == ':')
return tolower((int)*filename) - 'a' + 1;
return 0; /* current drive */
}
long
diskspace(char *filename)
{
struct diskfree_t dtable;
struct find_t srchbuf;
long cluster, freespace;
if(_dos_findfirst(filename, 0x07, &srchbuf))
srchbuf.size = 0;
#ifdef __SUPPORT_EA__
if(srchbuf.ea)
free(srchbuf.ea);
#endif
_dos_getdiskfree(physicaldrive(filename), &dtable);
cluster = (long)dtable.bytes_per_sector*(long)dtable.sectors_per_cluster;
freespace = (long)dtable.avail_clusters*cluster;
freespace += (srchbuf.size + cluster - 1)/cluster*cluster;
return freespace;
}