buffer.c (48c779cdecb5f803e5fe5d761987e976ca9609db) | buffer.c (d38c30c092828f4882ce13b08d0bd3fd6dc7afb5) |
---|---|
1/* 2 * Copyright (c) Christos Zoulas 2017. 3 * All Rights Reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27#include "file.h" 28 29#ifndef lint | 1/* 2 * Copyright (c) Christos Zoulas 2017. 3 * All Rights Reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27#include "file.h" 28 29#ifndef lint |
30FILE_RCSID("@(#)$File: buffer.c,v 1.6 2019/05/07 02:27:11 christos Exp $") | 30FILE_RCSID("@(#)$File: buffer.c,v 1.7 2019/06/10 21:35:26 christos Exp $") |
31#endif /* lint */ 32 33#include "magic.h" 34#include <unistd.h> 35#include <string.h> 36#include <stdlib.h> 37#include <sys/stat.h> 38 --- 33 unchanged lines hidden (view full) --- 72 b->elen = CAST(size_t, b->st.st_size) < b->flen ? 73 CAST(size_t, b->st.st_size) : b->flen; 74 if ((b->ebuf = malloc(b->elen)) == NULL) 75 goto out; 76 77 b->eoff = b->st.st_size - b->elen; 78 if (pread(b->fd, b->ebuf, b->elen, b->eoff) == -1) { 79 free(b->ebuf); | 31#endif /* lint */ 32 33#include "magic.h" 34#include <unistd.h> 35#include <string.h> 36#include <stdlib.h> 37#include <sys/stat.h> 38 --- 33 unchanged lines hidden (view full) --- 72 b->elen = CAST(size_t, b->st.st_size) < b->flen ? 73 CAST(size_t, b->st.st_size) : b->flen; 74 if ((b->ebuf = malloc(b->elen)) == NULL) 75 goto out; 76 77 b->eoff = b->st.st_size - b->elen; 78 if (pread(b->fd, b->ebuf, b->elen, b->eoff) == -1) { 79 free(b->ebuf); |
80 b->ebuf = NULL; |
|
80 goto out; 81 } 82 83 return 0; 84out: 85 b->elen = CAST(size_t, ~0); 86 return -1; 87} | 81 goto out; 82 } 83 84 return 0; 85out: 86 b->elen = CAST(size_t, ~0); 87 return -1; 88} |