Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sol-cfuncs.c « rs6000 « libgloss - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 982716746faa27d34726fafe20b52bc25d9ad550 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/*
 * solaris-cfuncs.S -- C functions for Solaris.
 *
 * Copyright (c) 1996 Cygnus Support
 *
 * The authors hereby grant permission to use, copy, modify, distribute,
 * and license this software and its documentation for any purpose, provided
 * that existing copyright notices are retained in all copies and that this
 * notice is included verbatim in any distributions. No written agreement,
 * license, or royalty fee is required for any of the authorized uses.
 * Modifications to this software may be copyrighted by their authors
 * and need not follow the licensing terms described here, provided that
 * the new terms are clearly indicated on the first page of each file where
 * they apply.
 */

#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/unistd.h>

#ifndef __STDC__
#define const
#endif

/* Solaris stat packet */
typedef	long		solaris_off_t;
typedef	long		solaris_uid_t;
typedef	long		solaris_gid_t;
typedef	long unsigned	solaris_mode_t;
typedef	long unsigned	solaris_nlink_t;
typedef long unsigned	solaris_dev_t;
typedef long unsigned	solaris_ino_t;
typedef long		solaris_time_t;

typedef struct {
  solaris_time_t	tv_sec;
  long			tv_nsec;
} solaris_timestruc_t;

#define	_ST_FSTYPSZ 16

struct solaris_stat {
  solaris_dev_t		st_dev;
  long			st_pad1[3];
  solaris_ino_t		st_ino;
  solaris_mode_t	st_mode;
  solaris_nlink_t	st_nlink;
  solaris_uid_t 	st_uid;
  solaris_gid_t 	st_gid;
  solaris_dev_t		st_rdev;
  long			st_pad2[2];
  solaris_off_t		st_size;
  long			st_pad3;
  solaris_timestruc_t	st_atim;
  solaris_timestruc_t	st_mtim;
  solaris_timestruc_t	st_ctim;
  long			st_blksize;
  long			st_blocks;
  char			st_fstype[_ST_FSTYPSZ];
  long			st_pad4[8];
};

/* Solaris termios packet */
#define	SOLARIS_NCCS	19
typedef unsigned long solaris_tcflag_t;
typedef unsigned char solaris_cc_t;
typedef unsigned long solaris_speed_t;

struct solaris_termios {
  solaris_tcflag_t	c_iflag;
  solaris_tcflag_t	c_oflag;
  solaris_tcflag_t	c_cflag;
  solaris_tcflag_t	c_lflag;
  solaris_cc_t		c_cc[SOLARIS_NCCS];
};

#define	SOLARIS_TIOC	('T'<<8)
#define	SOLARIS_TCGETS	(SOLARIS_TIOC|13)



/* Debug support */
#ifdef DEBUG
#define TRACE(msg) trace (msg)
#define TRACE1(msg,num) trace1 (msg,(unsigned)num)

static void
trace (msg)
     const char *msg;
{
  const char *p;

  for (p = msg; *p != '\0'; p++)
    ;

  (void) write (2, msg, p-msg);
}

static void
trace1 (msg, num)
     const char *msg;
     unsigned int num;
{
  char buffer[16];
  char *p = &buffer[ sizeof(buffer) ];

  trace (msg);
  *--p = '\0';
  *--p = '\n';
  do {
    *--p = '0' + (num % 10);
    num /= 10;
  } while (num != 0); 
  trace (p);  
}

#else
#define TRACE(msg)
#define TRACE1(msg,num)
#endif


/* Errno support */

int errno;

int *
__errno ()
{
  return &errno;
}

/* syscall handler branches here to set errno.  Error codes
   that are common between newlib and Solaris are the same.  */

int
_cerror (e)
     int e;
{
  TRACE1("got to _cerror ",e);
  errno = e;
  return -1;
}


/* Sbrk support */

extern char _end[];
static char *curbrk = _end;

void *
sbrk (incr)
     size_t incr;
{
  char *oldbrk = curbrk;
  TRACE("got to sbrk\n");
  curbrk += incr;
  if (brk (curbrk) == -1)
    return (char *) -1;

  return (void *)oldbrk;
}


/* Isatty support */

int
isatty (fd)
     int fd;
{
  struct solaris_termios t;
  int ret;

  ret = (ioctl (fd, SOLARIS_TCGETS, &t) == 0);

  TRACE1("got to isatty, returned ", ret);
  return ret;
}


/* Convert Solaris {,f}stat to newlib.
   Fortunately, the st_mode bits are the same.  */

static void
solaris_to_newlib_stat (solaris, newlib)
     struct solaris_stat *solaris;
     struct stat *newlib;
{
  static struct stat zero_stat;

  *newlib = zero_stat;
  newlib->st_dev     = solaris->st_dev;
  newlib->st_ino     = solaris->st_ino;
  newlib->st_mode    = solaris->st_mode;
  newlib->st_nlink   = solaris->st_nlink;
  newlib->st_uid     = solaris->st_uid;
  newlib->st_gid     = solaris->st_gid;
  newlib->st_rdev    = solaris->st_rdev;
  newlib->st_size    = solaris->st_size;
  newlib->st_blksize = solaris->st_blksize;
  newlib->st_blocks  = solaris->st_blocks;
  newlib->st_atime   = solaris->st_atim.tv_sec;
  newlib->st_mtime   = solaris->st_mtim.tv_sec;
  newlib->st_ctime   = solaris->st_ctim.tv_sec;
}

int
stat (file, newlib_stat)
     const char *file;
     struct stat *newlib_stat;
{
  int ret;
  struct solaris_stat st;

  TRACE("got to stat\n");
  ret = _stat (file, &st);
  if (ret >= 0)
    solaris_to_newlib_stat (&st, newlib_stat);

  return ret;
}

int
lstat (file, newlib_stat)
     const char *file;
     struct stat *newlib_stat;
{
  int ret;
  struct solaris_stat st;

  TRACE("got to lstat\n");
  ret = _lstat (file, &st);
  if (ret >= 0)
    solaris_to_newlib_stat (&st, newlib_stat);

  return ret;
}

int
fstat (fd, newlib_stat)
     int fd;
     struct stat *newlib_stat;
{
  int ret;
  struct solaris_stat st;

  TRACE("got to fstat\n");
  ret = _fstat (fd, &st);
  if (ret >= 0)
    solaris_to_newlib_stat (&st, newlib_stat);

  return ret;
}


/* Nops */

int
getrusage ()
{
  _cerror (EINVAL);
  return -1;
}

char *
getcwd(buf, size)
     char *buf;
     size_t size;
{
  if (!buf || size < 2)
    return ".";

  buf[0] = '.';
  buf[1] = '\0';
  return buf;
}