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 */
31 /** \ingroup rpmfileutil
32 * Calculate a file digest and size.
33 * @param algo digest algorithm
35 * @param asAscii return digest as ascii string?
36 * @retval digest address of calculated digest
37 * @retval *fsizep file size pointer (or NULL)
38 * @return 0 on success, 1 on error
40 int rpmDoDigest(int algo, const char * fn,int asAscii,
41 unsigned char * digest, rpm_loff_t * fsizep);
43 /** \ingroup rpmfileutil
44 * Thin wrapper for mkstemp(3).
45 * @param templ template for temporary filename
46 * @return file handle or NULL on error
48 FD_t rpmMkTemp(char *templ);
50 /** \ingroup rpmfileutil
51 * Return file handle for a temporaray file.
52 * A unique temporaray file path will be created in
53 * [prefix/]%{_tmppath} directory.
54 * The file name and the open file handle are returned.
56 * @param prefix leading part of temp file path
57 * @retval fn temp file name (or NULL)
58 * @return fdptr open file handle or NULL on error
60 FD_t rpmMkTempFile(const char * prefix, char **fn);
62 /** \ingroup rpmfileutil
63 * Insure that directories in path exist, creating as needed.
64 * @param path directory path
65 * @param mode directory mode (if created)
66 * @param uid directory uid (if created), or -1 to skip
67 * @param gid directory uid (if created), or -1 to skip
68 * @return 0 on success, errno (or -1) on error
70 int rpmioMkpath(const char * path, mode_t mode, uid_t uid, gid_t gid);
72 /** \ingroup rpmfileutil
73 * Create several directories (including parents if needed) in one go.
74 * Macros in pathstr will be expanded in the process.
75 * @param root leading root directory (or NULL for none)
76 * @param pathstr list of directories separated with :
77 * @return 0 if all directories were successfully created
78 * (or already existed), non-zero otherwise
80 int rpmMkdirs(const char *root, const char *pathstr);
82 /** \ingroup rpmfileutil
83 * Canonicalize file path.
84 * @param path path to canonicalize (in-place)
85 * @return pointer to path
87 char * rpmCleanPath (char * path);
89 /** \ingroup rpmfileutil
90 * Merge 3 args into path, any or all of which may be a url.
91 * The leading part of the first URL encountered is used
92 * for the result, other URL prefixes are discarded, permitting
93 * a primitive form of URL inheiritance.
94 * @param urlroot root URL (often path to chroot, or NULL)
95 * @param urlmdir directory URL (often a directory, or NULL)
96 * @param urlfile file URL (often a file, or NULL)
97 * @return expanded, merged, canonicalized path (malloc'ed)
99 char * rpmGenPath (const char * urlroot,
100 const char * urlmdir,
101 const char * urlfile);
103 /** \ingroup rpmfileutil
104 * Return (malloc'ed) expanded, canonicalized, file path.
105 * @param path macro(s) to expand (NULL terminates list)
106 * @return canonicalized path (malloc'ed)
108 char * rpmGetPath (const char * path, ...) RPM_GNUC_NULL_TERMINATED;
110 /** \ingroup rpmfileutil
111 * Return URL path(s) from a (URL prefixed) pattern glob.
112 * @param patterns glob pattern
113 * @retval *argcPtr no. of paths
114 * @retval *argvPtr ARGV_t array of paths
115 * @return 0 on success
117 int rpmGlob(const char * patterns, int * argcPtr, ARGV_t * argvPtr);
119 /** \ingroup rpmfileutil
120 * Escape isspace(3) characters in string.
122 * @return escaped string
124 char * rpmEscapeSpaces(const char * s);
126 /** \ingroup rpmfileutil
127 * Return type of compression used in file.
128 * @param file name of file
129 * @retval compressed address of compression type
130 * @return 0 on success, 1 on I/O error
132 int rpmFileIsCompressed (const char * file, rpmCompressedMagic * compressed);
134 /** \ingroup rpmfileutil
135 * Check if path (string) ends with given suffix
136 * @param path (path) string
137 * @param suffix suffix string to check for
138 * @return 1 if true, 0 otherwise
140 int rpmFileHasSuffix(const char *path, const char *suffix);
142 /** \ingroup rpmfileutil
143 * Like getcwd() but the result is malloced.
144 * @return current working directory (malloc'ed)
146 char * rpmGetCwd(void);
151 #endif /* _RPMFILEUTIL_H */