OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [native/] [jni/] [java-net/] [local.c] - Blame information for rev 774

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 774 jeremybenn
/* local.c -- implementation of unix-domain sockets.
2
   Copyright (C) 2006  Free Software Foundation, Inc.
3
 
4
This file is a part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or (at
9
your option) any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
19
USA
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version.  */
37
 
38
 
39
#include "config.h"
40
 
41
#ifdef ENABLE_LOCAL_SOCKETS
42
 
43
#include <stddef.h>
44
#include <stdlib.h>
45
#include <unistd.h>
46
#include <string.h>
47
#include <errno.h>
48
#include <sys/types.h>
49
#include <sys/socket.h>
50
#include <sys/un.h>
51
 
52
#include <stdio.h>
53
 
54
#if defined(HAVE_SYS_IOCTL_H)
55
#define BSD_COMP /* Get FIONREAD on Solaris2 */
56
#include <sys/ioctl.h>
57
#endif
58
#if defined(HAVE_SYS_FILIO_H) /* Get FIONREAD on Solaris 2.5 */
59
#include <sys/filio.h>
60
#endif
61
 
62
#include "local.h"
63
 
64
const char *
65
local_error (void)
66
{
67
  return strerror (errno);
68
}
69
 
70
int
71
local_create (int stream)
72
{
73
  return socket (PF_UNIX, stream ? SOCK_STREAM : SOCK_DGRAM, 0);
74
}
75
 
76
int
77
local_bind (int fd, const char *addr)
78
{
79
  struct sockaddr_un saddr;
80
 
81
  if (strlen (addr) >= sizeof (saddr.sun_path))
82
    {
83
      errno = ENAMETOOLONG;
84
      return -1;
85
    }
86
 
87
  strcpy (saddr.sun_path, addr);
88
  saddr.sun_family = AF_LOCAL;
89
 
90
  return bind (fd, (struct sockaddr *) &saddr, SUN_LEN (&saddr));
91
}
92
 
93
int
94
local_listen (int fd, int backlog)
95
{
96
  return listen (fd, backlog);
97
}
98
 
99
int
100
local_accept (int fd, char *path)
101
{
102
  int newfd;
103
  struct sockaddr_un addr;
104
  socklen_t sz = SUN_LEN(&addr);
105
 
106
  newfd = accept (fd, (struct sockaddr *) &addr, &sz);
107
  if (newfd >= 0)
108
    {
109
      /** sun_path is some crazy statically-sized buffer, and it's
110
          size is different on different OSes. */
111
      int n = sizeof (addr.sun_path);
112
      strncpy (path, addr.sun_path, n);
113
      path[n] = '\0';
114
    }
115
  return newfd;
116
}
117
 
118
int
119
local_available (int fd)
120
{
121
  int val;
122
  if (ioctl (fd, FIONREAD, &val))
123
    {
124
      return -1;
125
    }
126
  return val;
127
}
128
 
129
int
130
local_close (int fd)
131
{
132
  return close (fd);
133
}
134
 
135
int
136
local_unlink (char *path)
137
{
138
  return unlink (path);
139
}
140
 
141
int
142
local_shutdown_input (int fd)
143
{
144
  return shutdown (fd, 0);
145
}
146
 
147
int
148
local_shutdown_output (int fd)
149
{
150
  return shutdown (fd, 1);
151
}
152
 
153
int
154
local_connect (int fd, char *path)
155
{
156
  struct sockaddr_un saddr;
157
 
158
  strncpy (saddr.sun_path, path, sizeof (saddr.sun_path));
159
  saddr.sun_path[sizeof (saddr.sun_path) - 1] = '\0';
160
  saddr.sun_family = AF_UNIX;
161
 
162
  return connect (fd, (struct sockaddr *) &saddr, SUN_LEN(&saddr));
163
}
164
 
165
int
166
local_read (int fd, void *buf, int len)
167
{
168
  int count = -1;
169
  do
170
    {
171
      count = read (fd, buf, len);
172
    }
173
  while (count == -1 && errno == EINTR);
174
  return count;
175
}
176
 
177
int
178
local_write (int fd, void *buf, int len)
179
{
180
  int count = -1;
181
  do
182
    {
183
      count = write (fd, buf, len);
184
    }
185
  while (count == -1 && errno == EINTR);
186
  return count;
187
}
188
 
189
#endif /* ENABLE_LOCAL_SOCKETS */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.