Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

rpmio/rpmio.h

Go to the documentation of this file.
00001 #ifndef H_RPMIO
00002 #define H_RPMIO
00003 
00009 #include <sys/types.h>
00010 #include <sys/stat.h>
00011 #include <dirent.h>
00012 /*@-noparams@*/
00013 #include <glob.h>
00014 /*@=noparams@*/
00015 #include <stdio.h>
00016 #include <stdlib.h>
00017 #include <unistd.h>
00018 
00021 typedef /*@abstract@*/ struct pgpDig_s * pgpDig;
00022 
00025 typedef /*@abstract@*/ struct pgpDigParams_s * pgpDigParams;
00026 
00034 #if !defined(__LCLINT__) && defined(__GLIBC__) && \
00035         (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2))
00036 #define USE_COOKIE_SEEK_POINTER 1
00037 typedef _IO_off64_t     _libio_off_t;
00038 typedef _libio_off_t *  _libio_pos_t;
00039 #else
00040 typedef off_t           _libio_off_t;
00041 typedef off_t           _libio_pos_t;
00042 #endif
00043 
00047 typedef /*@abstract@*/ /*@refcounted@*/ struct _FD_s * FD_t;
00048 
00051 typedef /*@observer@*/ struct FDIO_s * FDIO_t;
00052 
00053 #ifdef __cplusplus
00054 extern "C" {
00055 #endif
00056 
00061 
00064 typedef ssize_t (*fdio_read_function_t) (void *cookie, char *buf, size_t nbytes)
00065         /*@globals errno, fileSystem @*/
00066         /*@modifies *cookie, errno, fileSystem @*/
00067         /*@requires maxSet(buf) >= (nbytes - 1) @*/
00068         /*@ensures maxRead(buf) == result @*/ ;
00069 
00072 typedef ssize_t (*fdio_write_function_t) (void *cookie, const char *buf, size_t nbytes)
00073         /*@globals errno, fileSystem @*/
00074         /*@modifies *cookie, errno, fileSystem @*/;
00075 
00078 typedef int (*fdio_seek_function_t) (void *cookie, _libio_pos_t pos, int whence)
00079         /*@globals errno, fileSystem @*/
00080         /*@modifies *cookie, errno, fileSystem @*/;
00081 
00084 typedef int (*fdio_close_function_t) (void *cookie)
00085         /*@globals errno, fileSystem, systemState @*/
00086         /*@modifies *cookie, errno, fileSystem, systemState @*/;
00087 
00088 
00091 typedef /*@only@*/ /*@null@*/ FD_t (*fdio_ref_function_t) ( /*@only@*/ void * cookie,
00092                 const char * msg, const char * file, unsigned line)
00093         /*@globals fileSystem @*/
00094         /*@modifies fileSystem @*/;
00095 
00098 typedef /*@only@*/ /*@null@*/ FD_t (*fdio_deref_function_t) ( /*@only@*/ FD_t fd,
00099                 const char * msg, const char * file, unsigned line)
00100         /*@globals fileSystem @*/
00101         /*@modifies fd, fileSystem @*/;
00102 
00103 
00106 typedef /*@only@*/ /*@null@*/ FD_t (*fdio_new_function_t) (const char * msg,
00107                 const char * file, unsigned line)
00108         /*@globals fileSystem @*/
00109         /*@modifies fileSystem @*/;
00110 
00111 
00114 typedef int (*fdio_fileno_function_t) (void * cookie)
00115         /*@globals fileSystem @*/
00116         /*@modifies *cookie, fileSystem @*/;
00117 
00118 
00121 typedef FD_t (*fdio_open_function_t) (const char * path, int flags, mode_t mode)
00122         /*@globals errno, fileSystem @*/
00123         /*@modifies errno, fileSystem @*/;
00124 
00127 typedef FD_t (*fdio_fopen_function_t) (const char * path, const char * fmode)
00128         /*@globals fileSystem @*/
00129         /*@modifies fileSystem @*/;
00130 
00133 typedef void * (*fdio_ffileno_function_t) (FD_t fd)
00134         /*@globals fileSystem @*/
00135         /*@modifies fileSystem @*/;
00136 
00139 typedef int (*fdio_fflush_function_t) (FD_t fd)
00140         /*@globals fileSystem @*/
00141         /*@modifies fileSystem @*/;
00149 
00152 typedef int (*fdio_mkdir_function_t) (const char * path, mode_t mode)
00153         /*@globals errno, fileSystem @*/
00154         /*@modifies errno, fileSystem @*/;
00155 
00158 typedef int (*fdio_chdir_function_t) (const char * path)
00159         /*@globals errno, fileSystem @*/
00160         /*@modifies errno, fileSystem @*/;
00161 
00164 typedef int (*fdio_rmdir_function_t) (const char * path)
00165         /*@globals errno, fileSystem @*/
00166         /*@modifies errno, fileSystem @*/;
00167 
00170 typedef int (*fdio_rename_function_t) (const char * oldpath, const char * newpath)
00171         /*@globals errno, fileSystem @*/
00172         /*@modifies errno, fileSystem @*/;
00173 
00176 typedef int (*fdio_unlink_function_t) (const char * path)
00177         /*@globals errno, fileSystem @*/
00178         /*@modifies errno, fileSystem @*/;
00179 /*@-typeuse@*/
00180 
00183 typedef int (*fdio_stat_function_t) (const char * path, /*@out@*/ struct stat * st)
00184         /*@globals errno, fileSystem @*/
00185         /*@modifies *st, errno, fileSystem @*/;
00186 
00189 typedef int (*fdio_lstat_function_t) (const char * path, /*@out@*/ struct stat * st)
00190         /*@globals errno, fileSystem @*/
00191         /*@modifies *st, errno, fileSystem @*/;
00192 
00195 typedef int (*fdio_access_function_t) (const char * path, int amode)
00196         /*@globals errno, fileSystem @*/
00197         /*@modifies errno, fileSystem @*/;
00198 /*@=typeuse@*/
00204 struct FDIO_s {
00205   fdio_read_function_t          read;
00206   fdio_write_function_t         write;
00207   fdio_seek_function_t          seek;
00208   fdio_close_function_t         close;
00209 
00210   fdio_ref_function_t           _fdref;
00211   fdio_deref_function_t         _fdderef;
00212   fdio_new_function_t           _fdnew;
00213   fdio_fileno_function_t        _fileno;
00214 
00215   fdio_open_function_t          _open;
00216   fdio_fopen_function_t         _fopen;
00217   fdio_ffileno_function_t       _ffileno;
00218   fdio_fflush_function_t        _fflush;
00219 
00220   fdio_mkdir_function_t         _mkdir;
00221   fdio_chdir_function_t         _chdir;
00222   fdio_rmdir_function_t         _rmdir;
00223   fdio_rename_function_t        _rename;
00224   fdio_unlink_function_t        _unlink;
00225 };
00226 
00227 
00232 
00236 /*@observer@*/ const char * Fstrerror(/*@null@*/ FD_t fd)
00237         /*@*/;
00238 
00242 /*@-incondefs@*/
00243 size_t Fread(/*@out@*/ void * buf, size_t size, size_t nmemb, FD_t fd)
00244         /*@globals fileSystem @*/
00245         /*@modifies fd, *buf, fileSystem @*/
00246         /*@requires maxSet(buf) >= (nmemb - 1) @*/
00247         /*@ensures maxRead(buf) == result @*/;
00248 /*@=incondefs@*/
00249 
00253 /*@-incondefs@*/
00254 size_t Fwrite(const void * buf, size_t size, size_t nmemb, FD_t fd)
00255         /*@globals fileSystem @*/
00256         /*@modifies fd, fileSystem @*/
00257         /*@requires maxRead(buf) >= nmemb @*/;
00258 /*@=incondefs@*/
00259 
00263 int Fseek(FD_t fd, _libio_off_t offset, int whence)
00264         /*@globals fileSystem @*/
00265         /*@modifies fileSystem @*/;
00266 
00270 int Fclose( /*@killref@*/ FD_t fd)
00271         /*@globals fileSystem, internalState @*/
00272         /*@modifies fd, fileSystem, internalState @*/;
00273 
00276 /*@null@*/ FD_t Fdopen(FD_t ofd, const char * fmode)
00277         /*@globals fileSystem @*/
00278         /*@modifies ofd, fileSystem @*/;
00279 
00283 /*@null@*/ FD_t Fopen(/*@null@*/ const char * path,
00284                         /*@null@*/ const char * fmode)
00285         /*@globals fileSystem, internalState @*/
00286         /*@modifies fileSystem, internalState @*/;
00287 
00288 
00292 int Fflush(/*@null@*/ FD_t fd)
00293         /*@globals fileSystem @*/
00294         /*@modifies fd, fileSystem @*/;
00295 
00299 int Ferror(/*@null@*/ FD_t fd)
00300         /*@*/;
00301 
00305 int Fileno(FD_t fd)
00306         /*@globals fileSystem @*/
00307         /*@modifies fileSystem@*/;
00308 
00312 /*@unused@*/
00313 int Fcntl(FD_t fd, int op, void *lip)
00314         /*@globals errno, fileSystem @*/
00315         /*@modifies fd, *lip, errno, fileSystem @*/;
00316 
00323 
00327 int Mkdir(const char * path, mode_t mode)
00328         /*@globals errno, fileSystem, internalState @*/
00329         /*@modifies errno, fileSystem, internalState @*/;
00330 
00334 int Chdir(const char * path)
00335         /*@globals errno, fileSystem, internalState @*/
00336         /*@modifies errno, fileSystem, internalState @*/;
00337 
00341 int Rmdir(const char * path)
00342         /*@globals errno, fileSystem, internalState @*/
00343         /*@modifies errno, fileSystem, internalState @*/;
00344 
00348 int Rename(const char * oldpath, const char * newpath)
00349         /*@globals errno, fileSystem, internalState @*/
00350         /*@modifies errno, fileSystem, internalState @*/;
00351 
00355 int Link(const char * oldpath, const char * newpath)
00356         /*@globals errno, fileSystem, internalState @*/
00357         /*@modifies errno, fileSystem, internalState @*/;
00358 
00362 int Unlink(const char * path)
00363         /*@globals errno, fileSystem, internalState @*/
00364         /*@modifies errno, fileSystem, internalState @*/;
00365 
00369 /*@-incondefs@*/
00370 int Readlink(const char * path, /*@out@*/ char * buf, size_t bufsiz)
00371         /*@globals errno, fileSystem, internalState @*/
00372         /*@modifies *buf, errno, fileSystem, internalState @*/
00373         /*@requires maxSet(buf) >= (bufsiz - 1) @*/
00374         /*@ensures maxRead(buf) <= bufsiz @*/;
00375 /*@=incondefs@*/
00376 
00380 int Stat(const char * path, /*@out@*/ struct stat * st)
00381         /*@globals errno, fileSystem, internalState @*/
00382         /*@modifies *st, errno, fileSystem, internalState @*/;
00383 
00387 int Lstat(const char * path, /*@out@*/ struct stat * st)
00388         /*@globals errno, fileSystem, internalState @*/
00389         /*@modifies *st, errno, fileSystem, internalState @*/;
00390 
00394 int Access(const char * path, int amode)
00395         /*@globals errno, fileSystem @*/
00396         /*@modifies errno, fileSystem @*/;
00397 
00398 
00402 int Glob(const char * pattern, int flags,
00403                 int errfunc(const char * epath, int eerrno),
00404                 /*@out@*/ glob_t * pglob)
00405         /*@globals fileSystem @*/
00406         /*@modifies *pglob, fileSystem @*/;
00407 
00411 void Globfree( /*@only@*/ glob_t * pglob)
00412         /*@globals fileSystem @*/
00413         /*@modifies *pglob, fileSystem @*/;
00414 
00415 
00419 /*@null@*/
00420 DIR * Opendir(const char * path)
00421         /*@globals errno, fileSystem, internalState @*/
00422         /*@modifies errno, fileSystem, internalState @*/;
00423 
00427 /*@dependent@*/ /*@null@*/
00428 struct dirent * Readdir(DIR * dir)
00429         /*@globals errno, fileSystem @*/
00430         /*@modifies *dir, errno, fileSystem @*/;
00431 
00435 int Closedir(/*@only@*/ DIR * dir)
00436         /*@globals errno, fileSystem @*/
00437         /*@modifies *dir, errno, fileSystem @*/;
00438 
00446 
00449 off_t   fdSize(FD_t fd)
00450         /*@globals fileSystem @*/
00451         /*@modifies fd, fileSystem@*/;
00452 
00455 /*@null@*/ FD_t fdDup(int fdno)
00456         /*@globals fileSystem, internalState @*/
00457         /*@modifies fileSystem, internalState @*/;
00458 
00459 #ifdef UNUSED
00460 /*@null@*/ FILE *fdFdopen( /*@only@*/ void * cookie, const char * mode);
00461 #endif
00462 
00463 /* XXX Legacy interfaces needed by gnorpm, rpmfind et al */
00464 
00465 /*@-exportlocal@*/
00468 #ifndef H_RPMIO_INTERNAL        /* XXX avoid gcc warning */
00469 /*@unused@*/ int fdFileno(void * cookie)
00470         /*@*/;
00471 #define fdFileno(_fd)           fdio->_fileno(_fd)
00472 #endif
00473 
00476 /*@null@*/ FD_t fdOpen(const char *path, int flags, mode_t mode)
00477         /*@globals errno, fileSystem, internalState @*/
00478         /*@modifies errno, fileSystem, internalState @*/;
00479 #define fdOpen(_path, _flags, _mode)    fdio->_open((_path), (_flags), (_mode))
00480 
00483 /*@-incondefs@*/
00484 ssize_t fdRead(void * cookie, /*@out@*/ char * buf, size_t count)
00485         /*@globals errno, fileSystem @*/
00486         /*@modifies *cookie, *buf, errno, fileSystem @*/
00487         /*@requires maxSet(buf) >= (count - 1) @*/
00488         /*@ensures maxRead(buf) == result @*/ ;
00489 #define fdRead(_fd, _buf, _count)       fdio->read((_fd), (_buf), (_count))
00490 /*@=incondefs@*/
00491 
00494 ssize_t fdWrite(void * cookie, const char * buf, size_t count)
00495         /*@globals errno, fileSystem @*/
00496         /*@modifies *cookie, errno, fileSystem @*/;
00497 #define fdWrite(_fd, _buf, _count)      fdio->write((_fd), (_buf), (_count))
00498 
00501 int fdClose( /*@only@*/ void * cookie)
00502         /*@globals errno, fileSystem, systemState, internalState @*/
00503         /*@modifies *cookie, errno, fileSystem, systemState, internalState @*/;
00504 #define fdClose(_fd)            fdio->close(_fd)
00505 
00508 /*@unused@*/
00509 /*@only@*/ /*@null@*/
00510 FD_t fdLink (/*@only@*/ void * cookie, const char * msg)
00511         /*@globals fileSystem @*/
00512         /*@modifies *cookie, fileSystem @*/;
00513 #define fdLink(_fd, _msg)       fdio->_fdref(_fd, _msg, __FILE__, __LINE__)
00514 
00517 /*@unused@*/
00518 /*@only@*/ /*@null@*/
00519 FD_t fdFree(/*@only@*/ FD_t fd, const char * msg)
00520         /*@globals fileSystem @*/
00521         /*@modifies fd, fileSystem @*/;
00522 #define fdFree(_fd, _msg)       fdio->_fdderef(_fd, _msg, __FILE__, __LINE__)
00523 
00526 /*@unused@*/
00527 /*@only@*/ /*@null@*/
00528 FD_t fdNew (const char * msg)
00529         /*@globals fileSystem @*/
00530         /*@modifies fileSystem @*/;
00531 #define fdNew(_msg)             fdio->_fdnew(_msg, __FILE__, __LINE__)
00532 
00535 int fdWritable(FD_t fd, int secs)
00536         /*@globals errno, fileSystem @*/
00537         /*@modifies fd, errno, fileSystem @*/;
00538 
00541 int fdReadable(FD_t fd, int secs)
00542         /*@globals errno @*/
00543         /*@modifies fd, errno @*/;
00544 /*@=exportlocal@*/
00545 
00554 int rpmioMkpath(const char * path, mode_t mode, uid_t uid, gid_t gid)
00555         /*@globals fileSystem, internalState @*/
00556         /*@modifies fileSystem, internalState @*/;
00557 
00561 /*@-typeuse@*/
00562 typedef enum ftperrCode_e {
00563     FTPERR_BAD_SERVER_RESPONSE  = -1,   
00564     FTPERR_SERVER_IO_ERROR      = -2,   
00565     FTPERR_SERVER_TIMEOUT       = -3,   
00566     FTPERR_BAD_HOST_ADDR        = -4,   
00567     FTPERR_BAD_HOSTNAME         = -5,   
00568     FTPERR_FAILED_CONNECT       = -6,   
00569     FTPERR_FILE_IO_ERROR        = -7,   
00570     FTPERR_PASSIVE_ERROR        = -8,   
00571     FTPERR_FAILED_DATA_CONNECT  = -9,   
00572     FTPERR_FILE_NOT_FOUND       = -10,  
00573     FTPERR_NIC_ABORT_IN_PROGRESS= -11,  
00574     FTPERR_UNKNOWN              = -100  
00575 } ftperrCode;
00576 /*@=typeuse@*/
00577 
00580 /*@-redecl@*/
00581 /*@observer@*/ const char *const ftpStrerror(int errorNumber)
00582         /*@*/;
00583 /*@=redecl@*/
00584 
00587 /*@unused@*/
00588 /*@dependent@*/ /*@null@*/ void * ufdGetUrlinfo(FD_t fd)
00589         /*@modifies fd @*/;
00590 
00593 /*@-redecl@*/
00594 /*@unused@*/
00595 /*@observer@*/ const char * urlStrerror(const char * url)
00596         /*@globals internalState @*/
00597         /*@modifies internalState @*/;
00598 /*@=redecl@*/
00599 
00602 /*@-exportlocal@*/
00603 int ufdCopy(FD_t sfd, FD_t tfd)
00604         /*@globals fileSystem @*/
00605         /*@modifies sfd, tfd, fileSystem @*/;
00606 /*@=exportlocal@*/
00607 
00610 int ufdGetFile( /*@killref@*/ FD_t sfd, FD_t tfd)
00611         /*@globals fileSystem, internalState @*/
00612         /*@modifies sfd, tfd, fileSystem, internalState @*/;
00613 
00616 /*@unused@*/ int timedRead(FD_t fd, /*@out@*/ void * bufptr, int length)
00617         /*@globals fileSystem @*/
00618         /*@modifies fd, *bufptr, fileSystem @*/;
00619 #define timedRead       ufdio->read
00620 
00621 /*@-exportlocal@*/
00624 /*@observer@*/ /*@unchecked@*/ extern FDIO_t fdio;
00625 
00628 /*@observer@*/ /*@unchecked@*/ extern FDIO_t fpio;
00629 
00632 /*@observer@*/ /*@unchecked@*/ extern FDIO_t ufdio;
00633 
00636 /*@observer@*/ /*@unchecked@*/ extern FDIO_t gzdio;
00637 
00640 /*@observer@*/ /*@unchecked@*/ extern FDIO_t bzdio;
00641 
00644 /*@observer@*/ /*@unchecked@*/ extern FDIO_t fadio;
00645 /*@=exportlocal@*/
00648 /*@unused@*/ static inline int xislower(int c) /*@*/ {
00649     return (c >= 'a' && c <= 'z');
00650 }
00651 /*@unused@*/ static inline int xisupper(int c) /*@*/ {
00652     return (c >= 'A' && c <= 'Z');
00653 }
00654 /*@unused@*/ static inline int xisalpha(int c) /*@*/ {
00655     return (xislower(c) || xisupper(c));
00656 }
00657 /*@unused@*/ static inline int xisdigit(int c) /*@*/ {
00658     return (c >= '0' && c <= '9');
00659 }
00660 /*@unused@*/ static inline int xisalnum(int c) /*@*/ {
00661     return (xisalpha(c) || xisdigit(c));
00662 }
00663 /*@unused@*/ static inline int xisblank(int c) /*@*/ {
00664     return (c == ' ' || c == '\t');
00665 }
00666 /*@unused@*/ static inline int xisspace(int c) /*@*/ {
00667     return (xisblank(c) || c == '\n' || c == '\r' || c == '\f' || c == '\v');
00668 }
00669 
00670 /*@unused@*/ static inline int xtolower(int c) /*@*/ {
00671     return ((xisupper(c)) ? (c | ('a' - 'A')) : c);
00672 }
00673 /*@unused@*/ static inline int xtoupper(int c) /*@*/ {
00674     return ((xislower(c)) ? (c & ~('a' - 'A')) : c);
00675 }
00676 
00680 int xstrcasecmp(const char * s1, const char * s2)               /*@*/;
00681 
00685 int xstrncasecmp(const char *s1, const char * s2, size_t n)     /*@*/;
00686 
00687 #ifdef __cplusplus
00688 }
00689 #endif
00690 
00691 #endif  /* H_RPMIO */

Generated on Sun Oct 26 13:02:03 2003 for rpm by doxygen1.2.18