aboutsummaryrefslogtreecommitdiff
path: root/include/common.h
blob: 13d79baf4daaa1af8fe40824be1abd5ff7f764e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* SPDX-License-Identifier: GPL-3.0-or-later */
/*
 * common.h
 *
 * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
 */
#ifndef COMMON_H
#define COMMON_H

#include "config.h"

#include "sqfs/xattr_reader.h"
#include "sqfs/inode.h"
#include "sqfs/table.h"
#include "sqfs/data_reader.h"
#include "sqfs/dir_reader.h"
#include "sqfs/block.h"
#include "sqfs/xattr.h"
#include "sqfs/dir.h"
#include "sqfs/io.h"

#include "simple_writer.h"
#include "compress_cli.h"
#include "dir_tree.h"
#include "compat.h"
#include "fstree.h"

#include <stddef.h>

void sqfs_perror(const char *file, const char *action, int error_code);

/* A common implementation of the '--version' command line flag. */
void print_version(const char *progname);

/*
  Parse a number optionally followed by a KMG suffix (case insensitive). Prints
  an error message to stderr and returns -1 on failure, 0 on success.

  The "what" string is used to prefix error messages (perror style).

  If reference is non-zero, the suffix '%' can be used to compute the result as
  a multiple of the reference value.
 */
int parse_size(const char *what, size_t *out, const char *str,
	       size_t reference);

void print_size(sqfs_u64 size, char *buffer, bool round_to_int);

/*
  Parse a comma separated list (e.g. "uid=...,gid=..." of defaults for
  fstree nodes. Used for command line parsing. Returns 0 on success,
  -1 on failure. Prints an error message to stderr on failure.
 */
int parse_fstree_defaults(fstree_defaults_t *out, char *str);

int istream_open_stdin(sqfs_istream_t **out);

int ostream_open_stdout(sqfs_ostream_t **out);

sqfs_istream_t *istream_memory_create(const char *name, size_t bufsz,
				      const void *data, size_t size);

#endif /* COMMON_H */