blob: 83e6212c82d14dee698d208fb8b7f59202bed03f [file] [log] [blame]
Guido van Rossum228d8072001-03-02 05:58:11 +00001/* Fudge unix isatty and fileno for RISCOS */
2
Guido van Rossume877f8b2001-10-24 20:13:15 +00003#include "unixstuff.h"
Guido van Rossum228d8072001-03-02 05:58:11 +00004#include <math.h>
Guido van Rossume877f8b2001-10-24 20:13:15 +00005#include <time.h>
6#include "oslib/osfile.h"
Guido van Rossum228d8072001-03-02 05:58:11 +00007
8int fileno(FILE *f)
9{ return (int)f;
10}
11
12int isatty(int fn)
13{ return (fn==fileno(stdin));
14}
15
16bits unixtime(bits ld,bits ex)
17{ ld&=0xFF;
18 ld-=51;
Guido van Rossume877f8b2001-10-24 20:13:15 +000019 if(ex<1855547904U) ld--;
Guido van Rossum228d8072001-03-02 05:58:11 +000020 ex-=1855548004U;
Guido van Rossume877f8b2001-10-24 20:13:15 +000021 return ex/100+42949673U*ld-ld/25;
Guido van Rossum228d8072001-03-02 05:58:11 +000022}
23
24
Guido van Rossume877f8b2001-10-24 20:13:15 +000025/* from RISC OS infozip, preserves filetype in ld */
26int acorntime(bits *ex, bits *ld, time_t utime)
27{
28 unsigned timlo; /* 3 lower bytes of acorn file-time plus carry byte */
29 unsigned timhi; /* 2 high bytes of acorn file-time */
30
31 timlo = ((unsigned)utime & 0x00ffffffU) * 100 + 0x00996a00U;
32 timhi = ((unsigned)utime >> 24);
33 timhi = timhi * 100 + 0x0000336eU + (timlo >> 24);
34 if (timhi & 0xffff0000U)
35 return 1; /* calculation overflow, do not change time */
36
37 /* insert the five time bytes into loadaddr and execaddr variables */
38 *ex = (timlo & 0x00ffffffU) | ((timhi & 0x000000ffU) << 24);
39 *ld = (*ld & 0xffffff00U) | ((timhi >> 8) & 0x000000ffU);
40
41 return 0; /* subject to future extension to signal overflow */
42}
43
Guido van Rossum228d8072001-03-02 05:58:11 +000044
45int isdir(char *fn)
46{ int ob;
Guido van Rossume877f8b2001-10-24 20:13:15 +000047 if(xosfile_read_stamped_no_path(fn,&ob,0,0,0,0,0)) return 0;
Guido van Rossum228d8072001-03-02 05:58:11 +000048 switch (ob)
Guido van Rossume877f8b2001-10-24 20:13:15 +000049 { case osfile_IS_DIR:return 1;
50 case osfile_IS_IMAGE:return 1;
Guido van Rossum228d8072001-03-02 05:58:11 +000051 }
Guido van Rossume877f8b2001-10-24 20:13:15 +000052 return 0;
Guido van Rossum228d8072001-03-02 05:58:11 +000053}
54
55int isfile(char *fn)
Guido van Rossume877f8b2001-10-24 20:13:15 +000056{ int ob;
57 if(xosfile_read_stamped_no_path(fn,&ob,0,0,0,0,0)) return 0;
Guido van Rossum228d8072001-03-02 05:58:11 +000058 switch (ob)
Guido van Rossume877f8b2001-10-24 20:13:15 +000059 { case osfile_IS_FILE:return 1;
60 case osfile_IS_IMAGE:return 1;
Guido van Rossum228d8072001-03-02 05:58:11 +000061 }
Guido van Rossume877f8b2001-10-24 20:13:15 +000062 return 0;
Guido van Rossum228d8072001-03-02 05:58:11 +000063}
64
Guido van Rossume877f8b2001-10-24 20:13:15 +000065int object_exists(char *fn)
66{ int ob;
67 if(xosfile_read_stamped_no_path(fn,&ob,0,0,0,0,0)) return 0;
Guido van Rossum228d8072001-03-02 05:58:11 +000068 switch (ob)
Guido van Rossume877f8b2001-10-24 20:13:15 +000069 { case osfile_IS_FILE:return 1;
70 case osfile_IS_DIR:return 1;
71 case osfile_IS_IMAGE:return 1;
Guido van Rossum228d8072001-03-02 05:58:11 +000072 }
Guido van Rossume877f8b2001-10-24 20:13:15 +000073 return 0;
Guido van Rossum228d8072001-03-02 05:58:11 +000074}