4 /** \ingroup rpmfileutil rpmio
5 * \file rpmio/rpmfileutil.h
6 * File and path manipulation helper functions.
9 #include <rpm/rpmutil.h>
10 #include <rpm/rpmio.h>
11 #include <rpm/rpmpgp.h>
18 /** \ingroup rpmfileutil
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 COMPRESSED_LZIP = 6, /*!< lzip can handle */
28 COMPRESSED_LRZIP = 7, /*!< lrzip can handle */
29 COMPRESSED_7ZIP = 8 /*!< 7zip can handle */
32 /** \ingroup rpmfileutil
33 * Calculate a file digest and size.
34 * @param algo digest algorithm
36 * @param asAscii return digest as ascii string?
37 * @retval digest address of calculated digest
38 * @retval *fsizep file size pointer (or NULL)
39 * @return 0 on success, 1 on error
41 int rpmDoDigest(int algo, const char * fn,int asAscii,
42 unsigned char * digest, rpm_loff_t * fsizep);
44 /** \ingroup rpmfileutil
45 * Thin wrapper for mkstemp(3).
46 * @param templ template for temporary filename
47 * @return file handle or NULL on error
49 FD_t rpmMkTemp(char *templ);
51 /** \ingroup rpmfileutil
52 * Return file handle for a temporaray file.
53 * A unique temporaray file path will be created in
54 * [prefix/]%{_tmppath} directory.
55 * The file name and the open file handle are returned.
57 * @param prefix leading part of temp file path
58 * @retval fn temp file name (or NULL)
59 * @return fdptr open file handle or NULL on error
61 FD_t rpmMkTempFile(const char * prefix, char **fn);
63 /** \ingroup rpmfileutil
64 * Insure that directories in path exist, creating as needed.
65 * @param path directory path
66 * @param mode directory mode (if created)
67 * @param uid directory uid (if created), or -1 to skip
68 * @param gid directory uid (if created), or -1 to skip
69 * @return 0 on success, errno (or -1) on error
71 int rpmioMkpath(const char * path, mode_t mode, uid_t uid, gid_t gid);
73 /** \ingroup rpmfileutil
74 * Create several directories (including parents if needed) in one go.
75 * Macros in pathstr will be expanded in the process.
76 * @param root leading root directory (or NULL for none)
77 * @param pathstr list of directories separated with :
78 * @return 0 if all directories were successfully created
79 * (or already existed), non-zero otherwise
81 int rpmMkdirs(const char *root, const char *pathstr);
83 /** \ingroup rpmfileutil
84 * Canonicalize file path.
85 * @param path path to canonicalize (in-place)
86 * @return pointer to path
88 char * rpmCleanPath (char * path);
90 /** \ingroup rpmfileutil
91 * Merge 3 args into path, any or all of which may be a url.
92 * The leading part of the first URL encountered is used
93 * for the result, other URL prefixes are discarded, permitting
94 * a primitive form of URL inheiritance.
95 * @param urlroot root URL (often path to chroot, or NULL)
96 * @param urlmdir directory URL (often a directory, or NULL)
97 * @param urlfile file URL (often a file, or NULL)
98 * @return expanded, merged, canonicalized path (malloc'ed)
100 char * rpmGenPath (const char * urlroot,
101 const char * urlmdir,
102 const char * urlfile);
104 /** \ingroup rpmfileutil
105 * Return (malloc'ed) expanded, canonicalized, file path.
106 * @param path macro(s) to expand (NULL terminates list)
107 * @return canonicalized path (malloc'ed)
109 char * rpmGetPath (const char * path, ...) RPM_GNUC_NULL_TERMINATED;
111 /** \ingroup rpmfileutil
112 * Check whether pattern contains any glob metacharacters.
113 * @param pattern glob pattern
114 * @param quote allow backslash quoting of metacharacters?
115 * @return 1 if pattern contains globs, 0 otherwise
117 int rpmIsGlob(const char * pattern, int quote);
119 /** \ingroup rpmfileutil
120 * Return URL path(s) from a (URL prefixed) pattern glob.
121 * @param patterns glob pattern
122 * @retval *argcPtr no. of paths
123 * @retval *argvPtr ARGV_t array of paths
124 * @return 0 on success
126 int rpmGlob(const char * patterns, int * argcPtr, ARGV_t * argvPtr);
128 /** \ingroup rpmfileutil
129 * Escape isspace(3) characters in string.
131 * @return escaped string
133 char * rpmEscapeSpaces(const char * s);
135 /** \ingroup rpmfileutil
136 * Return type of compression used in file.
137 * @param file name of file
138 * @retval compressed address of compression type
139 * @return 0 on success, 1 on I/O error
141 int rpmFileIsCompressed (const char * file, rpmCompressedMagic * compressed);
143 /** \ingroup rpmfileutil
144 * Check if path (string) ends with given suffix
145 * @param path (path) string
146 * @param suffix suffix string to check for
147 * @return 1 if true, 0 otherwise
149 int rpmFileHasSuffix(const char *path, const char *suffix);
151 /** \ingroup rpmfileutil
152 * Like getcwd() but the result is malloced.
153 * @return current working directory (malloc'ed)
155 char * rpmGetCwd(void);
160 #endif /* _RPMFILEUTIL_H */