Axe the rpmsq debug code which was never getting built anyway
[platform/upstream/rpm.git] / rpmio / rpmfileutil.h
1 #ifndef _RPMFILEUTIL_H
2 #define _RPMFILEUTIL_H
3
4 /** \ingroup rpmfileutil rpmio
5  * \file rpmio/rpmfileutil.h
6  * File and path manipulation helper functions.
7  */
8
9 #include <rpm/rpmutil.h>
10 #include <rpm/rpmio.h>
11 #include <rpm/rpmpgp.h>
12 #include <rpm/argv.h>
13
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17
18 /** \ingroup rpmfileutil
19  */
20 typedef enum rpmCompressedMagic_e {
21     COMPRESSED_NOT              = 0,    /*!< not compressed */
22     COMPRESSED_OTHER            = 1,    /*!< gzip can handle */
23     COMPRESSED_BZIP2            = 2,    /*!< bzip2 can handle */
24     COMPRESSED_ZIP              = 3,    /*!< unzip can handle */
25     COMPRESSED_LZMA             = 4,    /*!< lzma can handle */
26     COMPRESSED_XZ               = 5     /*!< xz can handle */
27 } rpmCompressedMagic;
28
29 /** \ingroup rpmfileutil
30  * Calculate a file digest and size.
31  * @param algo          digest algorithm
32  * @param fn            file name
33  * @param asAscii       return digest as ascii string?
34  * @retval digest       address of calculated digest
35  * @retval *fsizep      file size pointer (or NULL)
36  * @return              0 on success, 1 on error
37  */
38 int rpmDoDigest(int algo, const char * fn,int asAscii,
39                   unsigned char * digest, rpm_loff_t * fsizep);
40
41 /** \ingroup rpmfileutil
42  * Thin wrapper for mkstemp(3). 
43  * @param templ                 template for temporary filename
44  * @return                      file handle or NULL on error
45  */
46 FD_t rpmMkTemp(char *templ);
47
48 /** \ingroup rpmfileutil
49  * Return file handle for a temporaray file.
50  * A unique temporaray file path will be created in
51  * [prefix/]%{_tmppath} directory.
52  * The file name and the open file handle are returned.
53  *
54  * @param prefix        leading part of temp file path
55  * @retval fn           temp file name (or NULL)
56  * @return fdptr        open file handle or NULL on error
57  */
58 FD_t rpmMkTempFile(const char * prefix, char **fn);
59
60 /** \ingroup rpmfileutil
61  * Insure that directories in path exist, creating as needed.
62  * @param path          directory path
63  * @param mode          directory mode (if created)
64  * @param uid           directory uid (if created), or -1 to skip
65  * @param gid           directory uid (if created), or -1 to skip
66  * @return              0 on success, errno (or -1) on error
67  */
68 int rpmioMkpath(const char * path, mode_t mode, uid_t uid, gid_t gid);
69
70 /** \ingroup rpmfileutil
71  * Create several directories (including parents if needed) in one go.
72  * Macros in pathstr will be expanded in the process.
73  * @param root          leading root directory (or NULL for none)
74  * @param pathstr       list of directories separated with :
75  * @return              0 if all directories were successfully created
76  *                      (or already existed), non-zero otherwise
77  */
78 int rpmMkdirs(const char *root, const char *pathstr);
79
80 /** \ingroup rpmfileutil
81  * Canonicalize file path.
82  * @param path          path to canonicalize (in-place)
83  * @return              pointer to path
84  */
85 char * rpmCleanPath     (char * path);
86
87 /** \ingroup rpmfileutil
88  * Merge 3 args into path, any or all of which may be a url.
89  * The leading part of the first URL encountered is used
90  * for the result, other URL prefixes are discarded, permitting
91  * a primitive form of URL inheiritance.
92  * @param urlroot       root URL (often path to chroot, or NULL)
93  * @param urlmdir       directory URL (often a directory, or NULL)
94  * @param urlfile       file URL (often a file, or NULL)
95  * @return              expanded, merged, canonicalized path (malloc'ed)
96  */
97 char * rpmGenPath       (const char * urlroot,
98                         const char * urlmdir,
99                         const char * urlfile);
100
101 /** \ingroup rpmfileutil
102  * Return (malloc'ed) expanded, canonicalized, file path.
103  * @param path          macro(s) to expand (NULL terminates list)
104  * @return              canonicalized path (malloc'ed)
105  */
106 char * rpmGetPath (const char * path, ...) RPM_GNUC_NULL_TERMINATED;
107
108 /** \ingroup rpmfileutil
109  * Return URL path(s) from a (URL prefixed) pattern glob.
110  * @param patterns      glob pattern
111  * @retval *argcPtr     no. of paths
112  * @retval *argvPtr     ARGV_t array of paths
113  * @return              0 on success
114  */
115 int rpmGlob(const char * patterns, int * argcPtr, ARGV_t * argvPtr);
116
117 /** \ingroup rpmfileutil
118  * Escape isspace(3) characters in string.
119  * @param s             string
120  * @return              escaped string
121  */
122 char * rpmEscapeSpaces(const char * s);
123
124 /** \ingroup rpmfileutil
125  * Return type of compression used in file.
126  * @param file          name of file
127  * @retval compressed   address of compression type
128  * @return              0 on success, 1 on I/O error
129  */
130 int rpmFileIsCompressed (const char * file, rpmCompressedMagic * compressed);
131
132 /** \ingroup rpmfileutil
133  * Check if path (string) ends with given suffix
134  * @param path          (path) string
135  * @param suffix        suffix string to check for
136  * @return              1 if true, 0 otherwise
137  */
138 int rpmFileHasSuffix(const char *path, const char *suffix);
139
140 /** \ingroup rpmfileutil
141  * Like getcwd() but the result is malloced.
142  * @return              current working directory (malloc'ed)
143  */
144 char * rpmGetCwd(void);
145
146 #ifdef __cplusplus
147 }
148 #endif
149 #endif /* _RPMFILEUTIL_H */