/src/libwebp/imageio/metadata.c
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2012 Google Inc. All Rights Reserved. |
2 | | // |
3 | | // Use of this source code is governed by a BSD-style license |
4 | | // that can be found in the COPYING file in the root of the source |
5 | | // tree. An additional intellectual property rights grant can be found |
6 | | // in the file PATENTS. All contributing project authors may |
7 | | // be found in the AUTHORS file in the root of the source tree. |
8 | | // ----------------------------------------------------------------------------- |
9 | | // |
10 | | // Metadata types and functions. |
11 | | // |
12 | | |
13 | | #include "./metadata.h" |
14 | | |
15 | | #include <stdlib.h> |
16 | | #include <string.h> |
17 | | |
18 | | #include "webp/types.h" |
19 | | |
20 | 6.14k | void MetadataInit(Metadata* const metadata) { |
21 | 6.14k | if (metadata == NULL) return; |
22 | 6.14k | memset(metadata, 0, sizeof(*metadata)); |
23 | 6.14k | } |
24 | | |
25 | 19.1k | void MetadataPayloadDelete(MetadataPayload* const payload) { |
26 | 19.1k | if (payload == NULL) return; |
27 | 19.1k | free(payload->bytes); |
28 | 19.1k | payload->bytes = NULL; |
29 | 19.1k | payload->size = 0; |
30 | 19.1k | } |
31 | | |
32 | 6.39k | void MetadataFree(Metadata* const metadata) { |
33 | 6.39k | if (metadata == NULL) return; |
34 | 6.37k | MetadataPayloadDelete(&metadata->exif); |
35 | 6.37k | MetadataPayloadDelete(&metadata->iccp); |
36 | 6.37k | MetadataPayloadDelete(&metadata->xmp); |
37 | 6.37k | } |
38 | | |
39 | | int MetadataCopy(const char* metadata, size_t metadata_len, |
40 | 0 | MetadataPayload* const payload) { |
41 | 0 | if (metadata == NULL || metadata_len == 0 || payload == NULL) return 0; |
42 | 0 | payload->bytes = (uint8_t*)malloc(metadata_len); |
43 | 0 | if (payload->bytes == NULL) return 0; |
44 | 0 | payload->size = metadata_len; |
45 | 0 | memcpy(payload->bytes, metadata, metadata_len); |
46 | 0 | return 1; |
47 | 0 | } |
48 | | |
49 | | // ----------------------------------------------------------------------------- |