2 * solaris-cfuncs.S -- C functions for Solaris.
4 * Copyright (c) 1996 Cygnus Support
6 * The authors hereby grant permission to use, copy, modify, distribute,
7 * and license this software and its documentation for any purpose, provided
8 * that existing copyright notices are retained in all copies and that this
9 * notice is included verbatim in any distributions. No written agreement,
10 * license, or royalty fee is required for any of the authorized uses.
11 * Modifications to this software may be copyrighted by their authors
12 * and need not follow the licensing terms described here, provided that
13 * the new terms are clearly indicated on the first page of each file where
18 #include <sys/types.h>
20 #include <sys/unistd.h>
26 /* Solaris stat packet */
27 typedef long solaris_off_t
;
28 typedef long solaris_uid_t
;
29 typedef long solaris_gid_t
;
30 typedef long unsigned solaris_mode_t
;
31 typedef long unsigned solaris_nlink_t
;
32 typedef long unsigned solaris_dev_t
;
33 typedef long unsigned solaris_ino_t
;
34 typedef long solaris_time_t
;
37 solaris_time_t tv_sec
;
39 } solaris_timestruc_t
;
41 #define _ST_FSTYPSZ 16
47 solaris_mode_t st_mode
;
48 solaris_nlink_t st_nlink
;
51 solaris_dev_t st_rdev
;
53 solaris_off_t st_size
;
55 solaris_timestruc_t st_atim
;
56 solaris_timestruc_t st_mtim
;
57 solaris_timestruc_t st_ctim
;
60 char st_fstype
[_ST_FSTYPSZ
];
64 /* Solaris termios packet */
65 #define SOLARIS_NCCS 19
66 typedef unsigned long solaris_tcflag_t
;
67 typedef unsigned char solaris_cc_t
;
68 typedef unsigned long solaris_speed_t
;
70 struct solaris_termios
{
71 solaris_tcflag_t c_iflag
;
72 solaris_tcflag_t c_oflag
;
73 solaris_tcflag_t c_cflag
;
74 solaris_tcflag_t c_lflag
;
75 solaris_cc_t c_cc
[SOLARIS_NCCS
];
78 #define SOLARIS_TIOC ('T'<<8)
79 #define SOLARIS_TCGETS (SOLARIS_TIOC|13)
85 #define TRACE(msg) trace (msg)
86 #define TRACE1(msg,num) trace1 (msg,(unsigned)num)
94 for (p
= msg
; *p
!= '\0'; p
++)
97 (void) write (2, msg
, p
-msg
);
106 char *p
= &buffer
[ sizeof(buffer
) ];
112 *--p
= '0' + (num
% 10);
120 #define TRACE1(msg,num)
134 /* syscall handler branches here to set errno. Error codes
135 that are common between newlib and Solaris are the same. */
141 TRACE1("got to _cerror ",e
);
150 static char *curbrk
= _end
;
156 char *oldbrk
= curbrk
;
157 TRACE("got to sbrk\n");
159 if (brk (curbrk
) == -1)
162 return (void *)oldbrk
;
172 struct solaris_termios t
;
175 ret
= (ioctl (fd
, SOLARIS_TCGETS
, &t
) == 0);
177 TRACE1("got to isatty, returned ", ret
);
182 /* Convert Solaris {,f}stat to newlib.
183 Fortunately, the st_mode bits are the same. */
186 solaris_to_newlib_stat (solaris
, newlib
)
187 struct solaris_stat
*solaris
;
190 static struct stat zero_stat
;
193 newlib
->st_dev
= solaris
->st_dev
;
194 newlib
->st_ino
= solaris
->st_ino
;
195 newlib
->st_mode
= solaris
->st_mode
;
196 newlib
->st_nlink
= solaris
->st_nlink
;
197 newlib
->st_uid
= solaris
->st_uid
;
198 newlib
->st_gid
= solaris
->st_gid
;
199 newlib
->st_rdev
= solaris
->st_rdev
;
200 newlib
->st_size
= solaris
->st_size
;
201 newlib
->st_blksize
= solaris
->st_blksize
;
202 newlib
->st_blocks
= solaris
->st_blocks
;
203 newlib
->st_atime
= solaris
->st_atim
.tv_sec
;
204 newlib
->st_mtime
= solaris
->st_mtim
.tv_sec
;
205 newlib
->st_ctime
= solaris
->st_ctim
.tv_sec
;
209 stat (file
, newlib_stat
)
211 struct stat
*newlib_stat
;
214 struct solaris_stat st
;
216 TRACE("got to stat\n");
217 ret
= _stat (file
, &st
);
219 solaris_to_newlib_stat (&st
, newlib_stat
);
225 lstat (file
, newlib_stat
)
227 struct stat
*newlib_stat
;
230 struct solaris_stat st
;
232 TRACE("got to lstat\n");
233 ret
= _lstat (file
, &st
);
235 solaris_to_newlib_stat (&st
, newlib_stat
);
241 fstat (fd
, newlib_stat
)
243 struct stat
*newlib_stat
;
246 struct solaris_stat st
;
248 TRACE("got to fstat\n");
249 ret
= _fstat (fd
, &st
);
251 solaris_to_newlib_stat (&st
, newlib_stat
);
271 if (!buf
|| size
< 2)