dpkg 1.21.11
file.h
Go to the documentation of this file.
1/*
2 * libdpkg - Debian packaging suite library routines
3 * file.h - file handling routines
4 *
5 * Copyright © 2008-2010 Guillem Jover <guillem@debian.org>
6 *
7 * This is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef LIBDPKG_FILE_H
22#define LIBDPKG_FILE_H
23
24#include <sys/types.h>
25
26#include <stdbool.h>
27
28#include <dpkg/macros.h>
29#include <dpkg/error.h>
30#include <dpkg/varbuf.h>
31
33
40struct file_stat {
41 uid_t uid;
42 gid_t gid;
43 mode_t mode;
44
45 /* Used by dpkg-statoverride when parsing the database to preserve the
46 * user and group names in case the system does not know about them. */
47 char *uname;
48 char *gname;
49};
50
51bool file_is_exec(const char *filename);
52
53void file_copy_perms(const char *src, const char *dst);
54
55int
56file_slurp(const char *filename, struct varbuf *vb, struct dpkg_error *err);
57
61};
62
63bool file_is_locked(int lockfd, const char *filename);
64void file_lock(int *lockfd, enum file_lock_flags flags, const char *filename,
65 const char *filedesc);
66void file_unlock(int fd, const char *filename, const char *filedesc);
67void file_show(const char *filename);
68
72
73#endif /* LIBDPKG_FILE_H */
void file_unlock(int fd, const char *filename, const char *filedesc)
Unlock a previously locked file.
Definition: file.c:140
bool file_is_exec(const char *filename)
Check whether a filename is executable.
Definition: file.c:45
void file_lock(int *lockfd, enum file_lock_flags flags, const char *filename, const char *filedesc)
Lock a file.
Definition: file.c:195
file_lock_flags
Definition: file.h:58
void file_copy_perms(const char *src, const char *dst)
Copy file ownership and permissions from one file to another.
Definition: file.c:65
void file_show(const char *filename)
Definition: file.c:234
bool file_is_locked(int lockfd, const char *filename)
Check if a file has a lock acquired.
Definition: file.c:170
int file_slurp(const char *filename, struct varbuf *vb, struct dpkg_error *err)
Definition: file.c:108
@ FILE_LOCK_WAIT
Definition: file.h:60
@ FILE_LOCK_NOWAIT
Definition: file.h:59
#define DPKG_BEGIN_DECLS
Definition: macros.h:86
#define DPKG_END_DECLS
Definition: macros.h:87
Definition: error.h:42
Definition: file.h:40
char * uname
Definition: file.h:47
gid_t gid
Definition: file.h:42
uid_t uid
Definition: file.h:41
char * gname
Definition: file.h:48
mode_t mode
Definition: file.h:43
varbuf_init must be called exactly once before the use of each varbuf (including before any call to v...
Definition: varbuf.h:55