home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
APPS
/
rzsz_3_36_3_src.lzh
/
os9.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-01-08
|
6KB
|
299 lines
#include <stdio.h>
#include <errno.h>
#include <signal.h>
#include <time.h>
#ifdef m6809
#define localtime localtim
#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)
int fd;
char *buffer;
int count;
int (*function)();
int timeout;
{
register int i = 0;
register int noinput = 1;
register int n, c;
int value;
errno = 0;
if((n=_gs_rdy(fd)) > 0)
return(read(fd,buffer,min(count,n)));
c = timeout << 2;
do
{
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);
}
}
while (noinput && (i++ < c));
if( !noinput )
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 /* !m6809 */
/*
* 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;
{
return (
((cp[0] & 0x7f) << 24)|
((cp[1] & 0xff) << 16) |
((cp[2] & 0xff) << 8) |
(cp[3] & 0xff)
);
}
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
/* The following unix compatable signal routines are from blarslib.l */
/* #include <signal.h> */
typedef int (*pfi)();
#define SIGHANDS 32
static int siginit;
static int nhands;
static struct sighand {int signo; pfi action;} sighands[SIGHANDS];
static int catch();
pfi signal(sig, func)
int sig;
pfi func;
{
register struct sighand *sp;
pfi p = SIG_DFL;
if(!siginit) {
siginit = 1;
intercept(catch);
}
for(sp = &sighands[0]; sp < &sighands[SIGHANDS]; sp++) {
if(sp->signo == sig) {
p = sp->action;
sp->action = func;
return p;
}
}
for(sp = &sighands[0]; sp < &sighands[SIGHANDS]; sp++) {
if(sp->action == SIG_DFL) {
sp->signo = sig;
sp->action = func;
return SIG_DFL;
}
}
return (pfi)-1;
}
static catch(sig)
int sig;
{
register struct sighand *sp;
for(sp = &sighands[0]; sp < &sighands[SIGHANDS]; sp++) {
if(sig == sp->signo) {
/* note the sys V bug of removing the handler is not done */
/* (bsd does not have this bug) */
if((int)sp->action == SIG_IGN) return(0);
if((int)sp->action == SIG_DFL) break;
(*sp->action)();
return(0);
}
}
switch(sig) {
case SIGWAKE:
return(0);
default:
exit(sig);
}
}
#endif /* !m6809 */