diff options
author | Ulrich Drepper <drepper@redhat.com> | 2004-12-22 20:10:10 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2004-12-22 20:10:10 +0000 |
commit | a334319f6530564d22e775935d9c91663623a1b4 (patch) | |
tree | b5877475619e4c938e98757d518bb1e9cbead751 /libio/fmemopen.c | |
parent | 0ecb606cb6cf65de1d9fc8a919bceb4be476c602 (diff) | |
download | glibc-a334319f6530564d22e775935d9c91663623a1b4.tar.gz glibc-a334319f6530564d22e775935d9c91663623a1b4.tar.xz glibc-a334319f6530564d22e775935d9c91663623a1b4.zip |
(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
Diffstat (limited to 'libio/fmemopen.c')
-rw-r--r-- | libio/fmemopen.c | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/libio/fmemopen.c b/libio/fmemopen.c index f3b280092c..ab6ffdd678 100644 --- a/libio/fmemopen.c +++ b/libio/fmemopen.c @@ -1,5 +1,5 @@ /* Fmemopen implementation. - Copyright (C) 2000, 2002, 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 2000, 2002 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Hanno Mueller, kontakt@hanno.de, 2000. @@ -27,6 +27,8 @@ * but couldn't find it in libio. The following snippet of code is an * attempt to implement what glibc's documentation describes. * + * No, it isn't really tested yet. :-) + * * * * I already see some potential problems: @@ -71,7 +73,6 @@ #include <libio.h> #include <stdio.h> #include <stdlib.h> -#include <stdint.h> #include <string.h> #include <sys/types.h> #include "libioP.h" @@ -127,7 +128,7 @@ fmemopen_write (void *cookie, const char *b, size_t s) if ((size_t) (c->pos + addnullc) == c->size) { __set_errno (ENOSPC); - return 0; + return -1; } s = c->size - c->pos - addnullc; } @@ -165,7 +166,7 @@ fmemopen_seek (void *cookie, _IO_off64_t *p, int w) break; case SEEK_END: - np = c->maxpos - *p; + np = c->size - *p; break; default: @@ -175,9 +176,9 @@ fmemopen_seek (void *cookie, _IO_off64_t *p, int w) if (np < 0 || (size_t) np > c->size) return -1; - *p = c->pos = np; + c->pos = np; - return 0; + return np; } @@ -202,13 +203,6 @@ fmemopen (void *buf, size_t len, const char *mode) cookie_io_functions_t iof; fmemopen_cookie_t *c; - if (__builtin_expect (len == 0, 0)) - { - einval: - __set_errno (EINVAL); - return NULL; - } - c = (fmemopen_cookie_t *) malloc (sizeof (fmemopen_cookie_t)); if (c == NULL) return NULL; @@ -226,15 +220,7 @@ fmemopen (void *buf, size_t len, const char *mode) c->buffer[0] = '\0'; } else - { - if (__builtin_expect ((uintptr_t) len > -(uintptr_t) buf, 0)) - { - free (c); - goto einval; - } - - c->buffer = buf; - } + c->buffer = buf; c->size = len; |