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 
00030 #if !defined(__LCLINT__) && defined(__GLIBC__) && \
00031         (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2))
00032 #define USE_COOKIE_SEEK_POINTER 1
00033 typedef _IO_off64_t     _libio_off_t;
00034 typedef _libio_off_t *  _libio_pos_t;
00035 #else
00036 typedef off_t           _libio_off_t;
00037 typedef off_t           _libio_pos_t;
00038 #endif
00039 
00043 typedef /*@abstract@*/ /*@refcounted@*/ struct _FD_s * FD_t;
00044 
00047 typedef /*@observer@*/ struct FDIO_s * FDIO_t;
00048 
00049 #ifdef __cplusplus
00050 extern "C" {
00051 #endif
00052 
00057 
00060 typedef ssize_t (*fdio_read_function_t) (void *cookie, char *buf, size_t nbytes)
00061         /*@globals errno, fileSystem @*/
00062         /*@modifies *cookie, errno, fileSystem @*/
00063         /*@requires maxSet(buf) >= (nbytes - 1) @*/
00064         /*@ensures maxRead(buf) >= nbytes @*/ ;
00065 
00068 typedef ssize_t (*fdio_write_function_t) (void *cookie, const char *buf, size_t nbytes)
00069         /*@globals errno, fileSystem @*/
00070         /*@modifies *cookie, errno, fileSystem @*/;
00071 
00074 typedef int (*fdio_seek_function_t) (void *cookie, _libio_pos_t pos, int whence)
00075         /*@globals errno, fileSystem @*/
00076         /*@modifies *cookie, errno, fileSystem @*/;
00077 
00080 typedef int (*fdio_close_function_t) (void *cookie)
00081         /*@globals errno, fileSystem, systemState @*/
00082         /*@modifies *cookie, errno, fileSystem, systemState @*/;
00083 
00084 
00087 typedef /*@only@*/ /*@null@*/ FD_t (*fdio_ref_function_t) ( /*@only@*/ void * cookie,
00088                 const char * msg, const char * file, unsigned line)
00089         /*@globals fileSystem @*/
00090         /*@modifies fileSystem @*/;
00091 
00094 typedef /*@only@*/ /*@null@*/ FD_t (*fdio_deref_function_t) ( /*@only@*/ FD_t fd,
00095                 const char * msg, const char * file, unsigned line)
00096         /*@globals fileSystem @*/
00097         /*@modifies fd, fileSystem @*/;
00098 
00099 
00102 typedef /*@only@*/ /*@null@*/ FD_t (*fdio_new_function_t) (const char * msg,
00103                 const char * file, unsigned line)
00104         /*@globals fileSystem @*/
00105         /*@modifies fileSystem @*/;
00106 
00107 
00110 typedef int (*fdio_fileno_function_t) (void * cookie)
00111         /*@globals fileSystem @*/
00112         /*@modifies *cookie, fileSystem @*/;
00113 
00114 
00117 typedef FD_t (*fdio_open_function_t) (const char * path, int flags, mode_t mode)
00118         /*@globals errno, fileSystem @*/
00119         /*@modifies errno, fileSystem @*/;
00120 
00123 typedef FD_t (*fdio_fopen_function_t) (const char * path, const char * fmode)
00124         /*@globals fileSystem @*/
00125         /*@modifies fileSystem @*/;
00126 
00129 typedef void * (*fdio_ffileno_function_t) (FD_t fd)
00130         /*@globals fileSystem @*/
00131         /*@modifies fileSystem @*/;
00132 
00135 typedef int (*fdio_fflush_function_t) (FD_t fd)
00136         /*@globals fileSystem @*/
00137         /*@modifies fileSystem @*/;
00145 
00148 typedef int (*fdio_mkdir_function_t) (const char * path, mode_t mode)
00149         /*@globals errno, fileSystem @*/
00150         /*@modifies errno, fileSystem @*/;
00151 
00154 typedef int (*fdio_chdir_function_t) (const char * path)
00155         /*@globals errno, fileSystem @*/
00156         /*@modifies errno, fileSystem @*/;
00157 
00160 typedef int (*fdio_rmdir_function_t) (const char * path)
00161         /*@globals errno, fileSystem @*/
00162         /*@modifies errno, fileSystem @*/;
00163 
00166 typedef int (*fdio_rename_function_t) (const char * oldpath, const char * newpath)
00167         /*@globals errno, fileSystem @*/
00168         /*@modifies errno, fileSystem @*/;
00169 
00172 typedef int (*fdio_unlink_function_t) (const char * path)
00173         /*@globals errno, fileSystem @*/
00174         /*@modifies errno, fileSystem @*/;
00175 /*@-typeuse@*/
00176 
00179 typedef int (*fdio_stat_function_t) (const char * path, /*@out@*/ struct stat * st)
00180         /*@globals errno, fileSystem @*/
00181         /*@modifies *st, errno, fileSystem @*/;
00182 
00185 typedef int (*fdio_lstat_function_t) (const char * path, /*@out@*/ struct stat * st)
00186         /*@globals errno, fileSystem @*/
00187         /*@modifies *st, errno, fileSystem @*/;
00188 
00191 typedef int (*fdio_access_function_t) (const char * path, int amode)
00192         /*@globals errno, fileSystem @*/
00193         /*@modifies errno, fileSystem @*/;
00194 /*@=typeuse@*/
00200 struct FDIO_s {
00201   fdio_read_function_t          read;
00202   fdio_write_function_t         write;
00203   fdio_seek_function_t          seek;
00204   fdio_close_function_t         close;
00205 
00206   fdio_ref_function_t           _fdref;
00207   fdio_deref_function_t         _fdderef;
00208   fdio_new_function_t           _fdnew;
00209   fdio_fileno_function_t        _fileno;
00210 
00211   fdio_open_function_t          _open;
00212   fdio_fopen_function_t         _fopen;
00213   fdio_ffileno_function_t       _ffileno;
00214   fdio_fflush_function_t        _fflush;
00215 
00216   fdio_mkdir_function_t         _mkdir;
00217   fdio_chdir_function_t         _chdir;
00218   fdio_rmdir_function_t         _rmdir;
00219   fdio_rename_function_t        _rename;
00220   fdio_unlink_function_t        _unlink;
00221 };
00222 
00223 
00228 
00232 /*@-redecl@*/
00233 /*@observer@*/ const char * Fstrerror(/*@null@*/ FD_t fd)
00234         /*@*/;
00235 /*@=redecl@*/
00236 
00240 size_t Fread(/*@out@*/ void * buf, size_t size, size_t nmemb, FD_t fd)
00241         /*@globals fileSystem @*/
00242         /*@modifies fd, *buf, fileSystem @*/;
00243 
00247 size_t Fwrite(const void * buf, size_t size, size_t nmemb, FD_t fd)
00248         /*@globals fileSystem @*/
00249         /*@modifies fd, fileSystem @*/;
00250 
00254 int Fseek(FD_t fd, _libio_off_t offset, int whence)
00255         /*@globals fileSystem @*/
00256         /*@modifies fileSystem @*/;
00257 
00261 int Fclose( /*@killref@*/ FD_t fd)
00262         /*@globals fileSystem @*/
00263         /*@modifies fd, fileSystem @*/;
00264 
00267 /*@null@*/ FD_t Fdopen(FD_t ofd, const char * fmode)
00268         /*@globals fileSystem @*/
00269         /*@modifies ofd, fileSystem @*/;
00270 
00274 /*@null@*/ FD_t Fopen(/*@null@*/ const char * path,
00275                         /*@null@*/ const char * fmode)
00276         /*@globals fileSystem @*/
00277         /*@modifies fileSystem @*/;
00278 
00279 
00283 int Fflush(/*@null@*/ FD_t fd)
00284         /*@globals fileSystem @*/
00285         /*@modifies fd, fileSystem @*/;
00286 
00290 int Ferror(/*@null@*/ FD_t fd)
00291         /*@*/;
00292 
00296 int Fileno(FD_t fd)
00297         /*@globals fileSystem @*/
00298         /*@modifies fileSystem@*/;
00299 
00303 /*@unused@*/
00304 int Fcntl(FD_t fd, int op, void *lip)
00305         /*@globals errno, fileSystem @*/
00306         /*@modifies fd, *lip, errno, fileSystem @*/;
00307 
00314 
00318 int Mkdir(const char * path, mode_t mode)
00319         /*@globals errno, fileSystem @*/
00320         /*@modifies errno, fileSystem @*/;
00321 
00325 int MkdirP(const char * path, mode_t mode)
00326         /*@globals errno, fileSystem @*/
00327         /*@modifies errno, fileSystem @*/;
00328 
00332 int Chdir(const char * path)
00333         /*@globals errno, fileSystem @*/
00334         /*@modifies errno, fileSystem @*/;
00335 
00339 int Rmdir(const char * path)
00340         /*@globals errno, fileSystem @*/
00341         /*@modifies errno, fileSystem @*/;
00342 
00346 int Rename(const char * oldpath, const char * newpath)
00347         /*@globals errno, fileSystem @*/
00348         /*@modifies errno, fileSystem @*/;
00349 
00353 int Link(const char * oldpath, const char * newpath)
00354         /*@globals errno, fileSystem @*/
00355         /*@modifies errno, fileSystem @*/;
00356 
00360 int Unlink(const char * path)
00361         /*@globals errno, fileSystem @*/
00362         /*@modifies errno, fileSystem @*/;
00363 
00367 int Readlink(const char * path, /*@out@*/ char * buf, size_t bufsiz)
00368         /*@globals errno, fileSystem @*/
00369         /*@modifies *buf, errno, fileSystem @*/
00370         /*@requires maxSet(buf) >= (bufsiz - 1) @*/
00371         /*@ensures result <= bufsiz @*/;
00372 
00376 int Stat(const char * path, /*@out@*/ struct stat * st)
00377         /*@globals errno, fileSystem @*/
00378         /*@modifies *st, errno, fileSystem @*/;
00379 
00383 int Lstat(const char * path, /*@out@*/ struct stat * st)
00384         /*@globals errno, fileSystem @*/
00385         /*@modifies *st, errno, fileSystem @*/;
00386 
00390 int Access(const char * path, int amode)
00391         /*@globals errno, fileSystem @*/
00392         /*@modifies errno, fileSystem @*/;
00393 
00394 
00398 int Glob(const char * pattern, int flags,
00399                 int errfunc(const char * epath, int eerrno),
00400                 /*@out@*/ glob_t * pglob)
00401         /*@globals fileSystem @*/
00402         /*@modifies *pglob, fileSystem @*/;
00403 
00407 void Globfree( /*@only@*/ glob_t * pglob)
00408         /*@globals fileSystem @*/
00409         /*@modifies *pglob, fileSystem @*/;
00410 
00411 
00415 /*@null@*/
00416 DIR * Opendir(const char * path)
00417         /*@globals errno, fileSystem @*/
00418         /*@modifies errno, fileSystem @*/;
00419 
00423 /*@null@*/
00424 struct dirent * Readdir(DIR * dir)
00425         /*@globals errno, fileSystem @*/
00426         /*@modifies *dir, errno, fileSystem @*/;
00427 
00431 int Closedir(/*@only@*/ DIR * dir)
00432         /*@globals errno, fileSystem @*/
00433         /*@modifies *dir, errno, fileSystem @*/;
00434 
00442 
00445 off_t   fdSize(FD_t fd)
00446         /*@globals fileSystem @*/
00447         /*@modifies fd, fileSystem@*/;
00448 
00451 /*@null@*/ FD_t fdDup(int fdno)
00452         /*@globals fileSystem @*/
00453         /*@modifies fileSystem@*/;
00454 
00455 #ifdef UNUSED
00456 /*@null@*/ FILE *fdFdopen( /*@only@*/ void * cookie, const char * mode);
00457 #endif
00458 
00459 /* XXX Legacy interfaces needed by gnorpm, rpmfind et al */
00460 
00461 /*@-exportlocal@*/
00464 #ifndef H_RPMIO_INTERNAL        /* XXX avoid gcc warning */
00465 /*@unused@*/ int fdFileno(void * cookie)
00466         /*@*/;
00467 #define fdFileno(_fd)           fdio->_fileno(_fd)
00468 #endif
00469 
00472 /*@null@*/ FD_t fdOpen(const char *path, int flags, mode_t mode)
00473         /*@globals errno, fileSystem @*/
00474         /*@modifies errno, fileSystem @*/;
00475 #define fdOpen(_path, _flags, _mode)    fdio->_open((_path), (_flags), (_mode))
00476 
00479 ssize_t fdRead(void * cookie, /*@out@*/ char * buf, size_t count)
00480         /*@globals errno, fileSystem @*/
00481         /*@modifies *cookie, *buf, errno, fileSystem @*/
00482         /*@requires maxSet(buf) >= (count - 1) @*/
00483         /*@ensures maxRead(buf) >= count @*/ ;
00484 #define fdRead(_fd, _buf, _count)       fdio->read((_fd), (_buf), (_count))
00485 
00488 ssize_t fdWrite(void * cookie, const char * buf, size_t count)
00489         /*@globals errno, fileSystem @*/
00490         /*@modifies *cookie, errno, fileSystem @*/;
00491 #define fdWrite(_fd, _buf, _count)      fdio->write((_fd), (_buf), (_count))
00492 
00495 int fdClose( /*@only@*/ void * cookie)
00496         /*@globals errno, fileSystem, systemState @*/
00497         /*@modifies *cookie, errno, fileSystem, systemState @*/;
00498 #define fdCLose(_fd)            fdio->close(_fd)
00499 
00502 /*@unused@*/
00503 /*@only@*/ /*@null@*/
00504 FD_t fdLink (/*@only@*/ void * cookie, const char * msg)
00505         /*@globals fileSystem @*/
00506         /*@modifies *cookie, fileSystem @*/;
00507 #define fdLink(_fd, _msg)       fdio->_fdref(_fd, _msg, __FILE__, __LINE__)
00508 
00511 /*@unused@*/
00512 /*@only@*/ /*@null@*/
00513 FD_t fdFree(/*@only@*/ FD_t fd, const char * msg)
00514         /*@globals fileSystem @*/
00515         /*@modifies fd, fileSystem @*/;
00516 #define fdFree(_fd, _msg)       fdio->_fdderef(_fd, _msg, __FILE__, __LINE__)
00517 
00520 /*@unused@*/
00521 /*@only@*/ /*@null@*/
00522 FD_t fdNew (const char * msg)
00523         /*@globals fileSystem @*/
00524         /*@modifies fileSystem @*/;
00525 #define fdNew(_msg)             fdio->_fdnew(_msg, __FILE__, __LINE__)
00526 
00529 int fdWritable(FD_t fd, int secs)
00530         /*@globals errno, fileSystem @*/
00531         /*@modifies fd, errno, fileSystem @*/;
00532 
00535 int fdReadable(FD_t fd, int secs)
00536         /*@globals errno @*/
00537         /*@modifies fd, errno @*/;
00538 /*@=exportlocal@*/
00539 
00543 /*@-typeuse@*/
00544 typedef enum ftperrCode_e {
00545     FTPERR_BAD_SERVER_RESPONSE  = -1,   
00546     FTPERR_SERVER_IO_ERROR      = -2,   
00547     FTPERR_SERVER_TIMEOUT       = -3,   
00548     FTPERR_BAD_HOST_ADDR        = -4,   
00549     FTPERR_BAD_HOSTNAME         = -5,   
00550     FTPERR_FAILED_CONNECT       = -6,   
00551     FTPERR_FILE_IO_ERROR        = -7,   
00552     FTPERR_PASSIVE_ERROR        = -8,   
00553     FTPERR_FAILED_DATA_CONNECT  = -9,   
00554     FTPERR_FILE_NOT_FOUND       = -10,  
00555     FTPERR_NIC_ABORT_IN_PROGRESS= -11,  
00556     FTPERR_UNKNOWN              = -100  
00557 } ftperrCode;
00558 /*@=typeuse@*/
00559 
00562 /*@-redecl@*/
00563 /*@observer@*/ const char *const ftpStrerror(int errorNumber)   /*@*/;
00564 /*@=redecl@*/
00565 
00568 /*@unused@*/
00569 /*@dependent@*/ /*@null@*/ void * ufdGetUrlinfo(FD_t fd)
00570         /*@modifies fd @*/;
00571 
00574 /*@-redecl@*/
00575 /*@unused@*/
00576 /*@observer@*/ const char * urlStrerror(const char * url)       /*@*/;
00577 /*@=redecl@*/
00578 
00581 /*@-exportlocal@*/
00582 int ufdCopy(FD_t sfd, FD_t tfd)
00583         /*@globals fileSystem @*/
00584         /*@modifies sfd, tfd, fileSystem @*/;
00585 /*@=exportlocal@*/
00586 
00589 int ufdGetFile( /*@killref@*/ FD_t sfd, FD_t tfd)
00590         /*@globals fileSystem @*/
00591         /*@modifies sfd, tfd, fileSystem @*/;
00592 
00595 /*@unused@*/ int timedRead(FD_t fd, /*@out@*/ void * bufptr, int length)
00596         /*@globals fileSystem @*/
00597         /*@modifies fd, *bufptr, fileSystem @*/;
00598 #define timedRead       ufdio->read
00599 
00600 /*@-exportlocal@*/
00603 /*@observer@*/ /*@unchecked@*/ extern FDIO_t fdio;
00604 
00607 /*@observer@*/ /*@unchecked@*/ extern FDIO_t fpio;
00608 
00611 /*@observer@*/ /*@unchecked@*/ extern FDIO_t ufdio;
00612 
00615 /*@observer@*/ /*@unchecked@*/ extern FDIO_t gzdio;
00616 
00619 /*@observer@*/ /*@unchecked@*/ extern FDIO_t bzdio;
00620 
00623 /*@observer@*/ /*@unchecked@*/ extern FDIO_t fadio;
00624 /*@=exportlocal@*/
00627 /*@unused@*/ static inline int xislower(int c) /*@*/ {
00628     return (c >= 'a' && c <= 'z');
00629 }
00630 /*@unused@*/ static inline int xisupper(int c) /*@*/ {
00631     return (c >= 'A' && c <= 'Z');
00632 }
00633 /*@unused@*/ static inline int xisalpha(int c) /*@*/ {
00634     return (xislower(c) || xisupper(c));
00635 }
00636 /*@unused@*/ static inline int xisdigit(int c) /*@*/ {
00637     return (c >= '0' && c <= '9');
00638 }
00639 /*@unused@*/ static inline int xisalnum(int c) /*@*/ {
00640     return (xisalpha(c) || xisdigit(c));
00641 }
00642 /*@unused@*/ static inline int xisblank(int c) /*@*/ {
00643     return (c == ' ' || c == '\t');
00644 }
00645 /*@unused@*/ static inline int xisspace(int c) /*@*/ {
00646     return (xisblank(c) || c == '\n' || c == '\r' || c == '\f' || c == '\v');
00647 }
00648 
00649 /*@unused@*/ static inline int xtolower(int c) /*@*/ {
00650     return ((xisupper(c)) ? (c | ('a' - 'A')) : c);
00651 }
00652 /*@unused@*/ static inline int xtoupper(int c) /*@*/ {
00653     return ((xislower(c)) ? (c & ~('a' - 'A')) : c);
00654 }
00655 
00659 int xstrcasecmp(const char * s1, const char * s2)               /*@*/;
00660 
00664 int xstrncasecmp(const char *s1, const char * s2, size_t n)     /*@*/;
00665 
00666 #ifdef __cplusplus
00667 }
00668 #endif
00669 
00670 #endif  /* H_RPMIO */

Generated on Sun Feb 2 23:32:05 2003 for rpm by doxygen1.2.18