summaryrefslogtreecommitdiffstats
path: root/src/util.h
blob: 963f0f33abbab213f0981be32f5fa213aefc840d (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
64
65
66
67
#ifndef fooutilhfoo
#define fooutilhfoo

/* $Id$ */

/***
  This file is part of syrep.

  syrep is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
  
  syrep is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
  License for more details.
  
  You should have received a copy of the GNU General Public License
  along with syrep; if not, write to the Free Software Foundation,
  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***/

#include <db.h>
#include <inttypes.h>

#ifndef MIN
#define MIN(a,b) ((a)<(b)?(a):(b))
#endif

void statistics(DB *db);
char* normalize_path(char *s);
void rotdash(void);
void rotdash_hide(void);
const char* get_snapshot_filename(const char *path, const char *fn);
const char* get_attached_filename(const char *root, const char *fn);
int isdirectory(const char *path);
int copy_fd(int sfd, int dfd, off_t l);
int copy_file(const char *src, const char *dst, int c);
int move_file(const char *src, const char *dst, int c);
int copy_or_link_file(const char *src, const char *dst, int c);

/* Remove all directories between path and root if they are empty. */
int prune_empty_directories(const char *path, const char *root);

/* Same as /bin/mkdir -p in the shell */
int mkdir_p(const char *path, mode_t m);

/* Create all leading directories in path */
int makeprefixpath(const char *path, mode_t m);

int question(const char *q, const char *resp);

/* Same as /bin/rm -rf in the shell */
int rm_rf(const char *root, int rec);

ssize_t loop_read(int fd, void *d, size_t l);
ssize_t loop_write(int fd, const void *d, size_t l);

int expand_file(int fd, off_t l);
off_t filesize(int fd);
off_t filesize2(const char *p);
char *snprint_off(char *s, size_t l, off_t off);

void set_tmp_dir(const char *s);

#endif