mirror of git://sourceware.org/git/glibc.git
2000-03-10 Roland McGrath <roland@baalperazim.frob.com>
* hurd/fopenport.c [! USE_IN_LIBIO] (cookie_io_functions_t): Define as macro for __io_functions. (funcsio): Use cookie_io_functions_t type name. (fopenport): Renamed from __fopenport. Rewrite to call fopencookie.
This commit is contained in:
parent
d10c8b6601
commit
418f095a3e
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 1994, 1995, 1997 Free Software Foundation, Inc.
|
/* Copyright (C) 1994,95,97,2000 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
The GNU C Library is free software; you can redistribute it and/or
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
|
@ -62,11 +62,13 @@ writeio (void *cookie, const char *buf, size_t n)
|
||||||
The current file position is stored in *POS.
|
The current file position is stored in *POS.
|
||||||
Returns zero if successful, nonzero if not. */
|
Returns zero if successful, nonzero if not. */
|
||||||
static int
|
static int
|
||||||
seekio (void *cookie, fpos_t *pos, int whence)
|
seekio (void *cookie, off_t *pos, int whence)
|
||||||
{
|
{
|
||||||
error_t error = __io_seek ((file_t) cookie, *pos, whence, pos);
|
off_t res;
|
||||||
|
error_t error = __io_seek ((file_t) cookie, *pos, whence, &res);
|
||||||
if (error)
|
if (error)
|
||||||
return __hurd_fail (error);
|
return __hurd_fail (error);
|
||||||
|
*pos = res;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,25 +84,40 @@ closeio (void *cookie)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const __io_functions funcsio = { readio, writeio, seekio, closeio };
|
#ifndef USE_IN_LIBIO
|
||||||
|
#define cookie_io_functions_t __io_functions
|
||||||
|
#endif
|
||||||
|
static const cookie_io_functions_t funcsio =
|
||||||
|
{ readio, writeio, seekio, closeio };
|
||||||
|
|
||||||
|
|
||||||
/* Defined in fopen.c. */
|
|
||||||
extern int __getmode (const char *mode, __io_mode *mptr);
|
|
||||||
|
|
||||||
|
|
||||||
/* Open a stream on PORT. MODE is as for fopen. */
|
/* Open a stream on PORT. MODE is as for fopen. */
|
||||||
|
|
||||||
FILE *
|
FILE *
|
||||||
__fopenport (mach_port_t port, const char *mode)
|
fopenport (mach_port_t port, const char *mode)
|
||||||
{
|
{
|
||||||
register FILE *stream;
|
|
||||||
__io_mode m;
|
|
||||||
int pflags;
|
int pflags;
|
||||||
|
int needflags;
|
||||||
error_t err;
|
error_t err;
|
||||||
|
|
||||||
if (!__getmode (mode, &m))
|
const char *m = mode;
|
||||||
return NULL;
|
|
||||||
|
switch (*m++)
|
||||||
|
{
|
||||||
|
case 'r':
|
||||||
|
needflags = O_READ;
|
||||||
|
break;
|
||||||
|
case 'w':
|
||||||
|
needflags = O_WRITE;
|
||||||
|
break;
|
||||||
|
case 'a':
|
||||||
|
needflags = O_WRITE|O_APPEND;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (m[0] == '+' || (m[0] == 'b' && m[1] == '+'))
|
||||||
|
needflags |= O_RDWR;
|
||||||
|
|
||||||
/* Verify the PORT is valid allows the access MODE specifies. */
|
/* Verify the PORT is valid allows the access MODE specifies. */
|
||||||
|
|
||||||
|
|
@ -108,23 +125,11 @@ __fopenport (mach_port_t port, const char *mode)
|
||||||
return __hurd_fail (err), NULL;
|
return __hurd_fail (err), NULL;
|
||||||
|
|
||||||
/* Check the access mode. */
|
/* Check the access mode. */
|
||||||
if ((m.__read && !(pflags & O_READ)) || (m.__write && !(pflags & O_WRITE)))
|
if ((pflags & needflags) != needflags)
|
||||||
{
|
{
|
||||||
errno = EBADF;
|
errno = EBADF;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream = __newstream ();
|
return fopencookie ((void *) port, mode, funcsio);
|
||||||
if (stream == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
stream->__cookie = (void *) port;
|
|
||||||
stream->__mode = m;
|
|
||||||
stream->__io_funcs = funcsio;
|
|
||||||
stream->__room_funcs = __default_room_functions;
|
|
||||||
stream->__seen = 1;
|
|
||||||
|
|
||||||
return stream;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
weak_alias (__fopenport, fopenport)
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue