cpython/RISCOS/unixstuff.c

75 lines
1.7 KiB
C
Raw Normal View History

2001-03-02 13:58:11 +08:00
/* Fudge unix isatty and fileno for RISCOS */
2001-10-25 04:13:15 +08:00
#include "unixstuff.h"
2001-03-02 13:58:11 +08:00
#include <math.h>
2001-10-25 04:13:15 +08:00
#include <time.h>
#include "oslib/osfile.h"
2001-03-02 13:58:11 +08:00
int fileno(FILE *f)
{ return (int)f;
}
int isatty(int fn)
{ return (fn==fileno(stdin));
}
bits unixtime(bits ld,bits ex)
{ ld&=0xFF;
ld-=51;
2001-10-25 04:13:15 +08:00
if(ex<1855547904U) ld--;
2001-03-02 13:58:11 +08:00
ex-=1855548004U;
2001-10-25 04:13:15 +08:00
return ex/100+42949673U*ld-ld/25;
2001-03-02 13:58:11 +08:00
}
2001-10-25 04:13:15 +08:00
/* from RISC OS infozip, preserves filetype in ld */
int acorntime(bits *ex, bits *ld, time_t utime)
{
unsigned timlo; /* 3 lower bytes of acorn file-time plus carry byte */
unsigned timhi; /* 2 high bytes of acorn file-time */
timlo = ((unsigned)utime & 0x00ffffffU) * 100 + 0x00996a00U;
timhi = ((unsigned)utime >> 24);
timhi = timhi * 100 + 0x0000336eU + (timlo >> 24);
if (timhi & 0xffff0000U)
return 1; /* calculation overflow, do not change time */
/* insert the five time bytes into loadaddr and execaddr variables */
*ex = (timlo & 0x00ffffffU) | ((timhi & 0x000000ffU) << 24);
*ld = (*ld & 0xffffff00U) | ((timhi >> 8) & 0x000000ffU);
return 0; /* subject to future extension to signal overflow */
}
2001-03-02 13:58:11 +08:00
int isdir(char *fn)
{ int ob;
2001-10-25 04:13:15 +08:00
if(xosfile_read_stamped_no_path(fn,&ob,0,0,0,0,0)) return 0;
2001-03-02 13:58:11 +08:00
switch (ob)
2001-10-25 04:13:15 +08:00
{ case osfile_IS_DIR:return 1;
case osfile_IS_IMAGE:return 1;
2001-03-02 13:58:11 +08:00
}
2001-10-25 04:13:15 +08:00
return 0;
2001-03-02 13:58:11 +08:00
}
int isfile(char *fn)
2001-10-25 04:13:15 +08:00
{ int ob;
if(xosfile_read_stamped_no_path(fn,&ob,0,0,0,0,0)) return 0;
2001-03-02 13:58:11 +08:00
switch (ob)
2001-10-25 04:13:15 +08:00
{ case osfile_IS_FILE:return 1;
case osfile_IS_IMAGE:return 1;
2001-03-02 13:58:11 +08:00
}
2001-10-25 04:13:15 +08:00
return 0;
2001-03-02 13:58:11 +08:00
}
2001-10-25 04:13:15 +08:00
int object_exists(char *fn)
{ int ob;
if(xosfile_read_stamped_no_path(fn,&ob,0,0,0,0,0)) return 0;
2001-03-02 13:58:11 +08:00
switch (ob)
2001-10-25 04:13:15 +08:00
{ case osfile_IS_FILE:return 1;
case osfile_IS_DIR:return 1;
case osfile_IS_IMAGE:return 1;
2001-03-02 13:58:11 +08:00
}
2001-10-25 04:13:15 +08:00
return 0;
2001-03-02 13:58:11 +08:00
}