blob: b191bd2a3aac37bbc319e2e6868926bedc63b51a [file] [log] [blame]
James Zern061263a2012-05-11 16:00:57 -07001// Copyright 2012 Google Inc. All Rights Reserved.
2//
James Zernd6406142013-06-06 23:05:58 -07003// 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.
James Zern061263a2012-05-11 16:00:57 -07008// -----------------------------------------------------------------------------
9//
10// Utility functions used by the example programs.
11//
12
13#ifndef WEBP_EXAMPLES_EXAMPLE_UTIL_H_
14#define WEBP_EXAMPLES_EXAMPLE_UTIL_H_
15
16#include "webp/types.h"
17
James Zern605a7122013-11-25 14:43:12 -080018#ifdef __cplusplus
James Zern061263a2012-05-11 16:00:57 -070019extern "C" {
20#endif
21
22// Allocates storage for entire file 'file_name' and returns contents and size
23// in 'data' and 'data_size'. Returns 1 on success, 0 otherwise. '*data' should
24// be deleted using free().
skal2bcad892014-03-12 19:32:16 +010025// If 'file_name' is NULL or equal to "-", input is read from stdin by calling
26// the function ExUtilReadFromStdin().
James Zern061263a2012-05-11 16:00:57 -070027int ExUtilReadFile(const char* const file_name,
28 const uint8_t** data, size_t* data_size);
29
skal2bcad892014-03-12 19:32:16 +010030// Same as ExUtilReadFile(), but reads until EOF from stdin instead.
31int ExUtilReadFromStdin(const uint8_t** data, size_t* data_size);
32
Urvang Joshie9a15a32012-11-07 14:41:15 -080033// Write a data segment into a file named 'file_name'. Returns true if ok.
skal2bcad892014-03-12 19:32:16 +010034// If 'file_name' is NULL or equal to "-", output is written to stdout.
Urvang Joshie9a15a32012-11-07 14:41:15 -080035int ExUtilWriteFile(const char* const file_name,
36 const uint8_t* data, size_t data_size);
37
James Zern605a7122013-11-25 14:43:12 -080038#ifdef __cplusplus
James Zern061263a2012-05-11 16:00:57 -070039} // extern "C"
40#endif
41
42#endif // WEBP_EXAMPLES_EXAMPLE_UTIL_H_