version 1.3.14
[gzip.git] / primos / primos.c
blob18e228b69be8c5eaad809f5dce407073af73e046
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 */
9 #ifdef __50SERIES
11 #include <config.h>
12 #include <stdio.h>
13 #include <fcntl.h>
14 #include <sys/stat.h>
17 uid_t primos_uid = 42;
18 gid_t primos_gid = 42;
19 mode_t primos_mode = 600;
21 /* Dummy do-nothing routine for chmod() */
22 int chmod(path, mode)
23 char *path;
24 int mode;
26 return 0;
29 char *getenv(var)
30 char *var;
32 char buf[256];
33 extern char *gvget();
35 buf[0] = '.';
36 strcpy(buf+1, var);
38 return gvget(buf);
42 unlink(path)
43 char *path;
45 return delete(path);
48 int lstat(path, buf)
49 char *path;
50 struct stat *buf;
52 return stat(path, buf);
55 int stat(path, buf)
56 char *path;
57 struct stat *buf;
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;
67 buf->st_rwlock = frwlock(path);
68 switch (buf->st_type = ftype(path))
70 case 0:
71 case 1:
72 /* Regular file (SAM or DAM) */
73 buf->st_size = fsize(path);
74 buf->st_mtime = fdtm(path);
76 buf->st_mode = S_IFREG|primos_mode;
77 break;
79 case 4:
80 buf->st_size = 0;
81 buf->st_mtime = fdtm(path);
83 buf->st_mode = S_IFDIR|primos_mode;
84 break;
86 case -1:
87 return -1;
89 default:
90 buf->st_mode = primos_mode;
91 buf->st_size = fsize(path);
92 buf->st_mtime = fdtm(path);
95 buf->st_blocks = (buf->st_size-1) / buf->st_blksize + 1;
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..
101 buf->st_atime = buf->st_mtime;
102 buf->st_ctime = buf->st_mtime;
104 return 0;
107 int fstat(fd, buf)
108 int fd;
109 struct stat *buf;
111 char path[1025];
113 return stat(getname(fd, path), buf);
116 int ascii2pascii(c)
117 int c;
119 return (c ? (c | 0x80) : '\0');
123 #endif /* __50SERIES */