rpmio.h
Go to the documentation of this file.
#ifndef H_RPMIO
#define H_RPMIO
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <rpmiotypes.h>
#include <rpmzlog.h>
#if !defined(__LCLINT__) && !defined(__UCLIBC__) && defined(__GLIBC__) && \
(__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2))
#define USE_COOKIE_SEEK_POINTER 1
typedef _IO_off64_t _libio_off_t;
typedef _libio_off_t * _libio_pos_t;
#else
typedef off_t _libio_off_t;
typedef off_t _libio_pos_t;
#endif
typedef /*@abstract@*/ /*@refcounted@*/ struct _FD_s * FD_t;
typedef /*@observer@*/ struct FDIO_s * FDIO_t;
#ifdef __cplusplus
extern "C" {
#endif
typedef ssize_t (*fdio_read_function_t) (void *cookie, char *buf, size_t nbytes)
/*@globals errno, fileSystem @*/
/*@modifies *cookie, errno, fileSystem @*/
/*@requires maxSet(buf) >= (nbytes - 1) @*/
/*@ensures maxRead(buf) == result @*/ ;
typedef ssize_t (*fdio_write_function_t) (void *cookie, const char *buf, size_t nbytes)
/*@globals errno, fileSystem @*/
/*@modifies *cookie, errno, fileSystem @*/;
typedef int (*fdio_seek_function_t) (void *cookie, _libio_pos_t pos, int whence)
/*@globals errno, fileSystem @*/
/*@modifies *cookie, errno, fileSystem @*/;
typedef int (*fdio_close_function_t) (void *cookie)
/*@globals errno, fileSystem, systemState @*/
/*@modifies *cookie, errno, fileSystem, systemState @*/;
typedef FD_t (*fdio_fopen_function_t) (const char * path, const char * fmode)
/*@globals errno, fileSystem @*/
/*@modifies errno, fileSystem @*/;
typedef FD_t (*fdio_fdopen_function_t) (void * cookie, const char * fmode)
/*@globals errno, fileSystem @*/
/*@modifies errno, fileSystem @*/;
typedef int (*fdio_flush_function_t) (void * cookie)
/*@globals errno, fileSystem @*/
/*@modifies errno, fileSystem @*/;
struct FDIO_s {
fdio_read_function_t read;
fdio_write_function_t write;
fdio_seek_function_t seek;
fdio_close_function_t close;
/*@null@*/
fdio_fopen_function_t _fopen;
/*@null@*/
fdio_fdopen_function_t _fdopen;
/*@null@*/
fdio_flush_function_t _flush;
};
/*@observer@*/ const char * Fstrerror(/*@null@*/ FD_t fd)
/*@*/;
/*@-incondefs@*/
size_t Fread(/*@out@*/ void * buf, size_t size, size_t nmemb, FD_t fd)
/*@globals fileSystem @*/
/*@modifies fd, *buf, fileSystem @*/
/*@requires maxSet(buf) >= (nmemb - 1) @*/;
/*@=incondefs@*/
/*@-incondefs@*/
size_t Fwrite(const void * buf, size_t size, size_t nmemb, FD_t fd)
/*@globals fileSystem @*/
/*@modifies fd, fileSystem @*/
/*@requires maxRead(buf) >= nmemb @*/;
/*@=incondefs@*/
int Fseek(FD_t fd, _libio_off_t offset, int whence)
/*@globals fileSystem @*/
/*@modifies fileSystem @*/;
int Fclose( /*@killref@*/ FD_t fd)
/*@globals fileSystem, internalState @*/
/*@modifies fd, fileSystem, internalState @*/;
/*@null@*/ FD_t Fdopen(FD_t ofd, const char * fmode)
/*@globals fileSystem, internalState @*/
/*@modifies ofd, fileSystem, internalState @*/;
/*@null@*/ FD_t Fopen(/*@null@*/ const char * path,
/*@null@*/ const char * fmode)
/*@globals h_errno, fileSystem, internalState @*/
/*@modifies fileSystem, internalState @*/;
int Fflush(/*@null@*/ FD_t fd)
/*@globals fileSystem @*/
/*@modifies fd, fileSystem @*/;
int Ferror(/*@null@*/ FD_t fd)
/*@*/;
int Fileno(FD_t fd)
/*@globals fileSystem @*/
/*@modifies fileSystem@*/;
/*@unused@*/
int Fcntl(FD_t fd, int op, void *lip)
/*@globals errno, fileSystem @*/
/*@modifies fd, *lip, errno, fileSystem @*/;
int Mkdir(const char * path, mode_t mode)
/*@globals errno, h_errno, fileSystem, internalState @*/
/*@modifies errno, fileSystem, internalState @*/;
int Chdir(const char * path)
/*@globals errno, h_errno, fileSystem, internalState @*/
/*@modifies errno, fileSystem, internalState @*/;
int Rmdir(const char * path)
/*@globals errno, h_errno, fileSystem, internalState @*/
/*@modifies errno, fileSystem, internalState @*/;
/*@unchecked@*/ /*@observer@*/ /*@null@*/
extern const char * _chroot_prefix;
int Chroot(const char * path)
/*@globals _chroot_prefix, errno, fileSystem, internalState @*/
/*@modifies _chroot_prefix, errno, fileSystem, internalState @*/;
int Open(const char * path, int flags, mode_t mode)
/*@globals errno, fileSystem, internalState @*/
/*@modifies errno, fileSystem, internalState @*/;
int Rename(const char * oldpath, const char * newpath)
/*@globals errno, h_errno, fileSystem, internalState @*/
/*@modifies errno, fileSystem, internalState @*/;
int Link(const char * oldpath, const char * newpath)
/*@globals errno, fileSystem, internalState @*/
/*@modifies errno, fileSystem, internalState @*/;
int Unlink(const char * path)
/*@globals errno, h_errno, fileSystem, internalState @*/
/*@modifies errno, fileSystem, internalState @*/;
int Stat(const char * path, /*@out@*/ struct stat * st)
/*@globals errno, h_errno, fileSystem, internalState @*/
/*@modifies *st, errno, fileSystem, internalState @*/;
int Lstat(const char * path, /*@out@*/ struct stat * st)
/*@globals errno, h_errno, fileSystem, internalState @*/
/*@modifies *st, errno, fileSystem, internalState @*/;
int Fstat(FD_t fd, /*@out@*/ struct stat * st)
/*@globals errno, fileSystem, internalState @*/
/*@modifies *st, errno, fileSystem, internalState @*/;
int Chown(const char * path, uid_t owner, gid_t group)
/*@globals errno, fileSystem, internalState @*/
/*@modifies errno, fileSystem, internalState @*/;
int Fchown(FD_t fd, uid_t owner, gid_t group)
/*@globals errno, fileSystem, internalState @*/
/*@modifies errno, fileSystem, internalState @*/;
int Lchown(const char * path, uid_t owner, gid_t group)
/*@globals errno, fileSystem, internalState @*/
/*@modifies errno, fileSystem, internalState @*/;
int Chmod(const char * path, mode_t mode)
/*@globals errno, fileSystem, internalState @*/
/*@modifies errno, fileSystem, internalState @*/;
int Fchmod(FD_t fd, mode_t mode)
/*@globals errno, fileSystem, internalState @*/
/*@modifies errno, fileSystem, internalState @*/;
int Mkfifo(const char * path, mode_t mode)
/*@globals errno, fileSystem, internalState @*/
/*@modifies errno, fileSystem, internalState @*/;
int Mknod(const char * path, mode_t mode, dev_t dev)
/*@globals errno, fileSystem, internalState @*/
/*@modifies errno, fileSystem, internalState @*/;
struct utimbuf;
int Utime(const char * path, const struct utimbuf * buf)
/*@globals errno, fileSystem, internalState @*/
/*@modifies errno, fileSystem, internalState @*/;
int Utimes(const char * path, const struct timeval * times)
/*@globals errno, fileSystem, internalState @*/
/*@modifies errno, fileSystem, internalState @*/;
int Symlink(const char * oldpath, const char * newpath)
/*@globals errno, fileSystem, internalState @*/
/*@modifies errno, fileSystem, internalState @*/;
/*@-incondefs@*/
int Readlink(const char * path, /*@out@*/ char * buf, size_t bufsiz)
/*@globals errno, h_errno, fileSystem, internalState @*/
/*@modifies *buf, errno, fileSystem, internalState @*/;
/*@=incondefs@*/
int Access(const char * path, int amode)
/*@globals errno, fileSystem @*/
/*@modifies errno, fileSystem @*/;
#if defined(__linux__)
int Mount(const char *source, const char *target,
const char *filesystemtype, unsigned long mountflags,
const void *data)
/*@globals errno, fileSystem @*/
/*@modifies errno, fileSystem @*/;
int Umount(const char *target)
/*@globals errno, fileSystem @*/
/*@modifies errno, fileSystem @*/;
int Umount2(const char *target, int flags)
/*@globals errno, fileSystem @*/
/*@modifies errno, fileSystem @*/;
#endif
int Glob_pattern_p (const char *pattern, int quote)
/*@*/;
int Glob_error(const char * epath, int eerrno)
/*@*/;
int Glob(const char * pattern, int flags,
int errfunc(const char * epath, int eerrno),
/*@out@*/ void * _pglob)
/*@globals fileSystem @*/
/*@modifies *_pglob, fileSystem @*/;
void Globfree( /*@only@*/ void * _pglob)
/*@globals fileSystem @*/
/*@modifies *_pglob, fileSystem @*/;
/*@null@*/
DIR * Opendir(const char * path)
/*@globals errno, h_errno, fileSystem, internalState @*/
/*@modifies errno, fileSystem, internalState @*/;
/*@dependent@*/ /*@null@*/
struct dirent * Readdir(DIR * dir)
/*@globals errno, fileSystem @*/
/*@modifies *dir, errno, fileSystem @*/;
int Closedir(/*@only@*/ DIR * dir)
/*@globals errno, fileSystem @*/
/*@modifies *dir, errno, fileSystem @*/;
/*@-globuse@*/
/*@null@*/
char * Realpath(const char * path, /*@out@*/ /*@null@*/ char * resolved_path)
/*@globals errno, fileSystem, internalState @*/
/*@modifies resolved_path, errno, fileSystem, internalState @*/;
/*@=globuse@*/
off_t Lseek(int fdno, off_t offset, int whence)
/*@globals errno, fileSystem @*/
/*@modifies errno, fileSystem @*/;
/*@null@*/ FD_t fdDup(int fdno)
/*@globals fileSystem, internalState @*/
/*@modifies fileSystem, internalState @*/;
/*@-exportlocal@*/
ssize_t fdRead(void * cookie, /*@out@*/ char * buf, size_t count)
/*@globals errno, fileSystem, internalState @*/
/*@modifies *cookie, *buf, errno, fileSystem, internalState @*/;
#define fdRead(_fd, _buf, _count) fdio->read((_fd), (_buf), (_count))
ssize_t fdWrite(void * cookie, const char * buf, size_t count)
/*@globals errno, fileSystem, internalState @*/
/*@modifies *cookie, errno, fileSystem, internalState @*/;
#define fdWrite(_fd, _buf, _count) fdio->write((_fd), (_buf), (_count))
int fdClose( /*@only@*/ void * cookie)
/*@globals errno, fileSystem, systemState, internalState @*/
/*@modifies *cookie, errno, fileSystem, systemState, internalState @*/;
#define fdClose(_fd) fdio->close(_fd)
/*@null@*/ FD_t fdOpen(const char *path, int flags, mode_t mode)
/*@globals errno, fileSystem, internalState @*/
/*@modifies errno, fileSystem, internalState @*/;
#define fdOpen(_path, _flags, _mode) fdio->_open((_path), (_flags), (_mode))
/*@unused@*/
/*@newref@*/ /*@null@*/
FD_t fdLink (void * cookie, const char * msg)
/*@globals fileSystem @*/
/*@modifies *cookie, fileSystem @*/;
#define fdLink(_fd, _msg) \
((FD_t)rpmioLinkPoolItem((rpmioItem)(_fd), _msg, __FILE__, __LINE__))
/*@unused@*/ /*@null@*/
FD_t fdFree(/*@killref@*/ FD_t fd, const char * msg)
/*@globals fileSystem @*/
/*@modifies fd, fileSystem @*/;
#define fdFree(_fd, _msg) \
((FD_t)rpmioFreePoolItem((rpmioItem)(_fd), _msg, __FILE__, __LINE__))
/*@unused@*/
/*@newref@*/ /*@null@*/
FD_t fdNew (const char * msg)
/*@globals fileSystem @*/
/*@modifies fileSystem @*/;
/*@newref@*/ /*@null@*/
FD_t XfdNew (const char * msg, const char * fn, unsigned ln)
/*@globals fileSystem @*/
/*@modifies fileSystem @*/;
#define fdNew(_msg) XfdNew(_msg, __FILE__, __LINE__)
int fdWritable(FD_t fd, int secs)
/*@globals errno, fileSystem @*/
/*@modifies fd, errno, fileSystem @*/;
int fdReadable(FD_t fd, int secs)
/*@globals errno @*/
/*@modifies fd, errno @*/;
/*@=exportlocal@*/
int rpmioMkpath(const char * path, mode_t mode, uid_t uid, gid_t gid)
/*@globals h_errno, fileSystem, internalState @*/
/*@modifies fileSystem, internalState @*/;
int rpmioAccess(const char *FN, /*@null@*/ const char * path, int mode)
/*@globals fileSystem, internalState @*/
/*@modifies fileSystem, internalState @*/;
extern char * (*Getpass) (const char * prompt)
/*@*/;
char * _GetPass (const char * prompt)
/*@*/;
char * _RequestPass (const char * prompt)
/*@*/;
/*@-typeuse@*/
typedef enum ftperrCode_e {
FTPERR_NE_ERROR = -1,
FTPERR_NE_LOOKUP = -2,
FTPERR_NE_AUTH = -3,
FTPERR_NE_PROXYAUTH = -4,
FTPERR_NE_CONNECT = -5,
FTPERR_NE_TIMEOUT = -6,
FTPERR_NE_FAILED = -7,
FTPERR_NE_RETRY = -8,
FTPERR_NE_REDIRECT = -9,
FTPERR_BAD_SERVER_RESPONSE = -81,
FTPERR_SERVER_IO_ERROR = -82,
FTPERR_SERVER_TIMEOUT = -83,
FTPERR_BAD_HOST_ADDR = -84,
FTPERR_BAD_HOSTNAME = -85,
FTPERR_FAILED_CONNECT = -86,
FTPERR_FILE_IO_ERROR = -87,
FTPERR_PASSIVE_ERROR = -88,
FTPERR_FAILED_DATA_CONNECT = -89,
FTPERR_FILE_NOT_FOUND = -90,
FTPERR_NIC_ABORT_IN_PROGRESS= -91,
FTPERR_UNKNOWN = -100
} ftperrCode;
/*@=typeuse@*/
/*@-redecl@*/
/*@observer@*/
const char * ftpStrerror(int errorNumber)
/*@*/;
/*@=redecl@*/
/*@unused@*/
/*@dependent@*/ /*@null@*/
void * ufdGetUrlinfo(FD_t fd)
/*@globals fileSystem @*/
/*@modifies fd, fileSystem @*/;
/*@-redecl@*/
/*@unused@*/
/*@observer@*/
const char * urlStrerror(const char * url)
/*@globals h_errno, internalState @*/
/*@modifies internalState @*/;
/*@=redecl@*/
/*@-exportlocal@*/
int ufdCopy(FD_t sfd, FD_t tfd)
/*@globals fileSystem @*/
/*@modifies sfd, tfd, fileSystem @*/;
/*@=exportlocal@*/
int ufdGetFile( /*@killref@*/ FD_t sfd, FD_t tfd)
/*@globals fileSystem, internalState @*/
/*@modifies sfd, tfd, fileSystem, internalState @*/;
/*@-exportlocal@*/
/*@observer@*/ /*@unchecked@*/ extern FDIO_t fdio;
/*@observer@*/ /*@unchecked@*/ extern FDIO_t fpio;
/*@observer@*/ /*@unchecked@*/ extern FDIO_t ufdio;
/*@observer@*/ /*@unchecked@*/ extern FDIO_t gzdio;
/*@observer@*/ /*@unchecked@*/ extern FDIO_t bzdio;
/*@observer@*/ /*@unchecked@*/ extern FDIO_t lzdio;
/*@observer@*/ /*@unchecked@*/ extern FDIO_t xzdio;
/*@=exportlocal@*/
/*@unchecked@*/ /*@only@*/ /*@null@*/
extern rpmioPool _fdPool;
void rpmioClean(void)
/*@globals _fdPool, fileSystem, internalState @*/
/*@modifies _fdPool, fileSystem, internalState @*/;
/*@null@*/
rpmioPool rpmioFreePool(/*@only@*//*@null@*/ rpmioPool pool)
/*@globals fileSystem, internalState @*/
/*@modifies pool, fileSystem, internalState @*/;
rpmioPool rpmioNewPool(/*@observer@*/ const char * name,
size_t size, int limit, int flags,
/*@null@*/ const char * (*dbg) (void *item),
/*@null@*/ void (*init) (void *item),
/*@null@*/ void (*fini) (void *item))
/*@globals fileSystem @*/
/*@modifies fileSystem @*/;
/*@null@*/
rpmioItem rpmioUnlinkPoolItem(/*@killref@*/ /*@null@*/ rpmioItem item,
const char * msg, const char * fn, unsigned ln)
/*@globals fileSystem @*/
/*@modifies item, fileSystem @*/;
/*@newref@*/ /*@null@*/
rpmioItem rpmioLinkPoolItem(/*@returned@*/ /*@null@*/ rpmioItem item,
const char * msg, const char * fn, unsigned ln)
/*@globals fileSystem @*/
/*@modifies item, fileSystem @*/;
/*@null@*/
void * rpmioFreePoolItem(/*@killref@*/ /*@null@*/ rpmioItem item,
const char * msg, const char * fn, unsigned ln)
/*@globals fileSystem @*/
/*@modifies item, fileSystem @*/;
rpmioItem rpmioGetPool(/*@kept@*/ /*@null@*/ rpmioPool pool, size_t size)
/*@globals fileSystem @*/
/*@modifies pool, fileSystem @*/;
/*@null@*/
rpmioItem rpmioPutPool(rpmioItem item)
/*@globals fileSystem @*/
/*@modifies item, fileSystem @*/;
#ifdef __cplusplus
}
#endif
#endif /* H_RPMIO */