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 */
29 /** \ingroup rpmfileutil
30 * Calculate a file digest and size.
31 * @param algo digest algorithm
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
38 int rpmDoDigest(int algo, const char * fn,int asAscii,
39 unsigned char * digest, rpm_loff_t * fsizep);
41 /** \ingroup rpmfileutil
42 * Thin wrapper for mkstemp(3).
43 * @param templ template for temporary filename
44 * @return file handle or NULL on error
46 FD_t rpmMkTemp(char *templ);
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.
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
58 FD_t rpmMkTempFile(const char * prefix, char **fn);
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
68 int rpmioMkpath(const char * path, mode_t mode, uid_t uid, gid_t gid);
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
78 int rpmMkdirs(const char *root, const char *pathstr);
80 /** \ingroup rpmfileutil
81 * Canonicalize file path.
82 * @param path path to canonicalize (in-place)
83 * @return pointer to path
85 char * rpmCleanPath (char * path);
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)
97 char * rpmGenPath (const char * urlroot,
99 const char * urlfile);
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)
106 char * rpmGetPath (const char * path, ...) RPM_GNUC_NULL_TERMINATED;
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
115 int rpmGlob(const char * patterns, int * argcPtr, ARGV_t * argvPtr);
117 /** \ingroup rpmfileutil
118 * Escape isspace(3) characters in string.
120 * @return escaped string
122 char * rpmEscapeSpaces(const char * s);
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
130 int rpmFileIsCompressed (const char * file, rpmCompressedMagic * compressed);
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
138 int rpmFileHasSuffix(const char *path, const char *suffix);
140 /** \ingroup rpmfileutil
141 * Like getcwd() but the result is malloced.
142 * @return current working directory (malloc'ed)
144 char * rpmGetCwd(void);
149 #endif /* _RPMFILEUTIL_H */