Imported Upstream version 1.3.14
[debian/gzip] / primos / primos.c
1 /*
2 ** primos.c
3 **
4 ** This file contains emulation routines for some common Unix functions
5 **
6 ** Author: Peter Eriksson <pen@lysator.liu.se>
7 */
8
9 #ifdef __50SERIES
10
11 #include <config.h>
12 #include <stdio.h>
13 #include <fcntl.h>
14 #include <sys/stat.h>
15
16
17 uid_t  primos_uid = 42;
18 gid_t  primos_gid = 42;
19 mode_t primos_mode = 600;
20
21 /* Dummy do-nothing routine for chmod() */
22 int chmod(path, mode)
23   char *path;
24   int mode;
25 {
26    return 0;
27 }
28
29 char *getenv(var)
30   char *var;
31 {
32   char buf[256];
33   extern char *gvget();
34
35   buf[0] = '.';
36   strcpy(buf+1, var);
37
38   return gvget(buf);
39 }
40
41
42 unlink(path)
43   char *path;
44 {
45   return delete(path);
46 }
47
48 int lstat(path, buf)
49   char *path;
50   struct stat *buf;
51 {
52   return stat(path, buf);
53 }
54
55 int stat(path, buf)
56   char *path;
57   struct stat *buf;
58 {
59   buf->st_dev     = 1;
60   buf->st_ino     = 1;
61   buf->st_nlink   = 1;
62   buf->st_uid     = primos_uid;
63   buf->st_gid     = primos_gid;
64   buf->st_rdev    = 1;
65   buf->st_blksize = 2048;
66
67   buf->st_rwlock = frwlock(path);
68   switch (buf->st_type = ftype(path))
69   {
70     case 0:
71     case 1:
72       /* Regular file (SAM or DAM) */
73       buf->st_size   = fsize(path);
74       buf->st_mtime  = fdtm(path);
75
76       buf->st_mode = S_IFREG|primos_mode;
77       break;
78
79     case 4:
80       buf->st_size = 0;
81       buf->st_mtime = fdtm(path);
82
83       buf->st_mode = S_IFDIR|primos_mode;
84       break;
85
86     case -1:
87       return -1;
88
89     default:
90       buf->st_mode = primos_mode;
91       buf->st_size = fsize(path);
92       buf->st_mtime = fdtm(path);
93   }
94
95   buf->st_blocks = (buf->st_size-1) / buf->st_blksize + 1;
96
97   /* Should be fixed to really fetch these values, but that
98    * would require calling some PRIMOS subroutines and I don't have
99    * a copy of the Primos Subroutine reference manuals here..
100    */
101   buf->st_atime = buf->st_mtime;
102   buf->st_ctime = buf->st_mtime;
103
104   return 0;
105 }
106
107 int fstat(fd, buf)
108   int fd;
109   struct stat *buf;
110 {
111   char path[1025];
112
113   return stat(getname(fd, path), buf);
114 }
115
116 int ascii2pascii(c)
117   int c;
118 {
119   return (c ? (c | 0x80) : '\0');
120 }
121
122
123 #endif /* __50SERIES */