home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
TELECOM
/
rzsz_3_24_src.lzh
/
os9.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-11-04
|
5KB
|
233 lines
#include <stdio.h>
#include <errno.h>
#include <signal.h>
#include <time.h>
#ifdef m6809
#include <sgstat.h>
#include <utime.h>
typedef long time_t;
#endif
#include <direct.h>
#define min(x,y) (x < y ? x : y)
int alarmread(fd,buffer,count,function,timeout)
register int fd;
register char *buffer;
int count;
int (*function)();
register int timeout;
{
register int i;
int n;
int noinput, c;
if((n=_gs_rdy(fd)) > 0)
return( read(fd,buffer,min(count,n)));
errno = 0;
c=timeout << 2;
for( i=0, noinput=1; i < c && noinput; i++)
{
if((n=_gs_rdy(fd)) > 0)
noinput = 0;
else
{
errno = 0;
#ifdef m6809
_ss_ssig(fd,SIGWAKE);
tsleep(15); /* 60 ticks / second */
#else
sigmask(1);
_ss_ssig(fd,SIGWAKE);
tsleep(CLK_TCK / 4);
#endif
_ss_rel(fd);
}
}
if( noinput==0 )
return( read(fd,buffer,min(count,n)));
else
return((*function)());
}
utime (file, timep)
char *file;
long timep[2];
{
struct tm *localtime ();
struct tm *tbuf;
int fd;
struct fildes buf;
if ((fd = open (file, 3)) < 0)
return -1;
if (_gs_gfd (fd, &buf, sizeof (buf)) < 0)
{
close (fd);
return -1;
}
u2otime(buf.fd_dcr,localtime(&(timep[0])));
u2otime(buf.fd_date,localtime(&(timep[1])));
if (_ss_pfd (fd, &buf) < 0)
{
close (fd);
return -1;
}
close (fd);
return 0;
}
long outime( date)
char *date;
{
long o2utime();
char newdate[6];
strncpy(newdate,date,5);
newdate[5]=0;
return(o2utime(newdate));
}
/*
* The two following subroutines convert between UNIX-style and OS-9-style
* file attributes. The UNIX-Style attribute is stored in decimal format,
* NOT in octal format, so if it is printed out in %o format, it will have
* The correct value.
*/
int u2oattr(attr)
int attr;
{
int o_attr=0;
if (attr & 0x001) o_attr |= 0x20; /* Public Execute */
if (attr & 0x002) o_attr |= 0x10; /* Public Write */
if (attr & 0x004) o_attr |= 0x08; /* Public Read */
if (attr & 0x040) o_attr |= 0x04; /* Owner Execute */
if (attr & 0x080) o_attr |= 0x02; /* Owner Write */
if (attr & 0x100) o_attr |= 0x01; /* Owner Read */
return(o_attr);
}
int o2uattr(attr)
int attr;
{
int u_attr=0;
if (attr & 0x20) u_attr |= (0x001 | 0x008); /* Public+Group Execute */
if (attr & 0x10) u_attr |= (0x002 | 0x010); /* Public+Group Write */
if (attr & 0x08) u_attr |= (0x004 | 0x020); /* Public+Group Read */
if (attr & 0x04) u_attr |= (0x040); /* Owner Execute */
if (attr & 0x02) u_attr |= (0x080); /* Owner Write */
if (attr & 0x01) u_attr |= (0x100); /* Owner Read */
return(u_attr);
}
#ifdef m6809
_ss_sbreak(pn)
int pn;
{
struct sgbuf old,new;
short tmp=0;
_gs_opt(pn, &old);
_strass(&new,&old,sizeof(old));
new.sg_baud = 0;
_ss_opt(pn, &new);
write(pn, &tmp, 1);
_ss_opt(pn, &old);
}
#else
/*
* Convert UNIX time to 5-byte OS-9 time
*/
u2otime(otime, tp)
char *otime;
struct tm *tp;
{
otime[5] = tp->tm_sec;
otime[4] = tp->tm_min;
otime[3] = tp->tm_hour;
otime[2] = tp->tm_mday;
otime[1] = tp->tm_mon + 1;
otime[0] = tp->tm_year;
}
/*
* Convert 5-byte OS-9 time to UNIX time
*/
long o2utime(otime)
char *otime;
{
struct tm t;
time_t tt;
t.tm_sec = otime[5];
t.tm_min = otime[4];
t.tm_hour = otime[3];
t.tm_mday = otime[2];
t.tm_mon = otime[1] - 1;
t.tm_year = otime[0];
tt = mktime(&t);
return(mktime(gmtime(&tt)));
}
long c4tol(cp)
char *cp;
{
long n;
n = (cp[0] & 0x7f);
n = (n << 8) + (cp[1] & 0xff);
n = (n << 8) + (cp[2] & 0xff);
n = (n << 8) + (cp[3] & 0xff);
return(n);
}
char *ltoc4(n)
long n;
{
char cp[4];
cp[3] = (char) (n % (256));
n = n >> 8;
cp[2] = (char) (n % (256));
n = n >> 8;
cp[1] = (char) (n % (256));
n = n >> 8;
cp[0] = (char) (n % (256));
return(cp);
}
#asm
I$SetStt equ $008E ; 8f is get
_ss_sbreak:
link a5,#0
movem.l D1/D2/A0,-(A7)
move.l D1,D2
move.w #SS_Break,D1
os9 I$SetStt
bra _sysret
#endasm
#endif /* m6809 */