- Fix more style(9)-related issues (copyright header, spaces after function
names, unnecessary casts) - Change type of boolean variable from char to bool Suggested by: jhb, zont, jmallett Reviewed by: cognet Approved by: cognet
This commit is contained in:
parent
2d7d16429c
commit
71796d333c
lib/libc/stdio
@ -1,32 +1,33 @@
|
||||
/*-
|
||||
Copyright (C) 2013 Pietro Cerutti <gahr@FreeBSD.org>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
* Copyright (C) 2013 Pietro Cerutti <gahr@FreeBSD.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -36,7 +37,7 @@ __FBSDID("$FreeBSD$");
|
||||
struct fmemopen_cookie
|
||||
{
|
||||
char *buf; /* pointer to the memory region */
|
||||
char own; /* did we allocate the buffer ourselves? */
|
||||
bool own; /* did we allocate the buffer ourselves? */
|
||||
char bin; /* is this a binary buffer? */
|
||||
size_t size; /* buffer length in bytes */
|
||||
size_t len; /* data length in bytes */
|
||||
@ -58,7 +59,7 @@ fmemopen (void * __restrict buf, size_t size, const char * __restrict mode)
|
||||
/*
|
||||
* Retrieve the flags as used by open(2) from the mode argument, and
|
||||
* validate them.
|
||||
* */
|
||||
*/
|
||||
rc = __sflags(mode, &flags);
|
||||
if (rc == 0) {
|
||||
errno = EINVAL;
|
||||
@ -74,7 +75,6 @@ fmemopen (void * __restrict buf, size_t size, const char * __restrict mode)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* Allocate a cookie. */
|
||||
ck = malloc(sizeof(struct fmemopen_cookie));
|
||||
if (ck == NULL) {
|
||||
return (NULL);
|
||||
@ -121,8 +121,8 @@ fmemopen (void * __restrict buf, size_t size, const char * __restrict mode)
|
||||
case 'a':
|
||||
if (ck->bin) {
|
||||
/*
|
||||
* This isn't useful, since the buffer isn't
|
||||
* allowed to grow.
|
||||
* This isn't useful, since the buffer isn't allowed
|
||||
* to grow.
|
||||
*/
|
||||
ck->off = ck->len = size;
|
||||
} else
|
||||
@ -136,8 +136,7 @@ fmemopen (void * __restrict buf, size_t size, const char * __restrict mode)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Actuall wrapper. */
|
||||
f = funopen ((void *)ck,
|
||||
f = funopen(ck,
|
||||
flags & O_WRONLY ? NULL : fmemopen_read,
|
||||
flags & O_RDONLY ? NULL : fmemopen_write,
|
||||
fmemopen_seek, fmemopen_close);
|
||||
@ -153,7 +152,7 @@ fmemopen (void * __restrict buf, size_t size, const char * __restrict mode)
|
||||
* Turn off buffering, so a write past the end of the buffer
|
||||
* correctly returns a short object count.
|
||||
*/
|
||||
setvbuf (f, (char *) NULL, _IONBF, 0);
|
||||
setvbuf(f, NULL, _IONBF, 0);
|
||||
|
||||
return (f);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user