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 #ifdef  NOTYET
    00022 typedef /*@abstract@*/ struct pgpDig_s * pgpDig;
    00023 #endif
    00024
    00033 #if !defined(__LCLINT__) && defined(__GLIBC__) && \
    00034         (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2))
    00035 #define USE_COOKIE_SEEK_POINTER 1
    00036 typedef _IO_off64_t     _libio_off_t;
    00037 typedef _libio_off_t *  _libio_pos_t;
    00038 #else
    00039 typedef off_t           _libio_off_t;
    00040 typedef off_t           _libio_pos_t;
    00041 #endif
    00042
    00046 typedef /*@abstract@*/ /*@refcounted@*/ struct _FD_s * FD_t;
    00047
    00050 typedef /*@observer@*/ struct FDIO_s * FDIO_t;
    00051
    00052 #ifdef __cplusplus
    00053 extern "C" {
    00054 #endif
    00055
    00060
    00063 typedef ssize_t (*fdio_read_function_t) (void *cookie, char *buf, size_t nbytes)
    00064         /*@globals fileSystem @*/
    00065         /*@modifies *cookie, fileSystem @*/;
    00066
    00069 typedef ssize_t (*fdio_write_function_t) (void *cookie, const char *buf, size_t nbytes)
    00070         /*@globals fileSystem @*/
    00071         /*@modifies *cookie, fileSystem @*/;
    00072
    00075 typedef int (*fdio_seek_function_t) (void *cookie, _libio_pos_t pos, int whence)
    00076         /*@globals fileSystem @*/
    00077         /*@modifies *cookie, fileSystem @*/;
    00078
    00081 typedef int (*fdio_close_function_t) (void *cookie)
    00082         /*@globals fileSystem @*/
    00083         /*@modifies *cookie, fileSystem @*/;
    00084
    00085
    00088 typedef /*@only@*/ /*@null@*/ FD_t (*fdio_ref_function_t) ( /*@only@*/ void * cookie,
    00089                 const char * msg, const char * file, unsigned line)
    00090         /*@globals fileSystem @*/
    00091         /*@modifies fileSystem @*/;
    00092
    00095 typedef /*@only@*/ /*@null@*/ FD_t (*fdio_deref_function_t) ( /*@only@*/ FD_t fd,
    00096                 const char * msg, const char * file, unsigned line)
    00097         /*@globals fileSystem @*/
    00098         /*@modifies fd, fileSystem @*/;
    00099
    00100
    00103 typedef /*@only@*/ /*@null@*/ FD_t (*fdio_new_function_t) (const char * msg,
    00104                 const char * file, unsigned line)
    00105         /*@globals fileSystem @*/
    00106         /*@modifies fileSystem @*/;
    00107
    00108
    00111 typedef int (*fdio_fileno_function_t) (void * cookie)
    00112         /*@globals fileSystem @*/
    00113         /*@modifies *cookie, fileSystem @*/;
    00114
    00115
    00118 typedef FD_t (*fdio_open_function_t) (const char * path, int flags, mode_t mode)
    00119         /*@globals fileSystem @*/
    00120         /*@modifies fileSystem @*/;
    00121
    00124 typedef FD_t (*fdio_fopen_function_t) (const char * path, const char * fmode)
    00125         /*@globals fileSystem @*/
    00126         /*@modifies fileSystem @*/;
    00127
    00130 typedef void * (*fdio_ffileno_function_t) (FD_t fd)
    00131         /*@globals fileSystem @*/
    00132         /*@modifies fileSystem @*/;
    00133
    00136 typedef int (*fdio_fflush_function_t) (FD_t fd)
    00137         /*@globals fileSystem @*/
    00138         /*@modifies fileSystem @*/;
    00146
    00149 typedef int (*fdio_mkdir_function_t) (const char * path, mode_t mode)
    00150         /*@globals fileSystem @*/
    00151         /*@modifies fileSystem @*/;
    00152
    00155 typedef int (*fdio_chdir_function_t) (const char * path)
    00156         /*@globals fileSystem @*/
    00157         /*@modifies fileSystem @*/;
    00158
    00161 typedef int (*fdio_rmdir_function_t) (const char * path)
    00162         /*@globals fileSystem @*/
    00163         /*@modifies fileSystem @*/;
    00164
    00167 typedef int (*fdio_rename_function_t) (const char * oldpath, const char * newpath)
    00168         /*@globals fileSystem @*/
    00169         /*@modifies fileSystem @*/;
    00170
    00173 typedef int (*fdio_unlink_function_t) (const char * path)
    00174         /*@globals fileSystem @*/
    00175         /*@modifies fileSystem @*/;
    00176 /*@-typeuse@*/
    00177
    00180 typedef int (*fdio_stat_function_t) (const char * path, /*@out@*/ struct stat * st)
    00181         /*@globals fileSystem @*/
    00182         /*@modifies *st, fileSystem @*/;
    00183
    00186 typedef int (*fdio_lstat_function_t) (const char * path, /*@out@*/ struct stat * st)
    00187         /*@globals fileSystem @*/
    00188         /*@modifies *st, fileSystem @*/;
    00189
    00192 typedef int (*fdio_access_function_t) (const char * path, int amode)
    00193         /*@globals fileSystem @*/
    00194         /*@modifies fileSystem @*/;
    00195 /*@=typeuse@*/
    00201 struct FDIO_s {
    00202   fdio_read_function_t          read;
    00203   fdio_write_function_t         write;
    00204   fdio_seek_function_t          seek;
    00205   fdio_close_function_t         close;
    00206
    00207   fdio_ref_function_t           _fdref;
    00208   fdio_deref_function_t         _fdderef;
    00209   fdio_new_function_t           _fdnew;
    00210   fdio_fileno_function_t        _fileno;
    00211
    00212   fdio_open_function_t          _open;
    00213   fdio_fopen_function_t         _fopen;
    00214   fdio_ffileno_function_t       _ffileno;
    00215   fdio_fflush_function_t        _fflush;
    00216
    00217   fdio_mkdir_function_t         _mkdir;
    00218   fdio_chdir_function_t         _chdir;
    00219   fdio_rmdir_function_t         _rmdir;
    00220   fdio_rename_function_t        _rename;
    00221   fdio_unlink_function_t        _unlink;
    00222 };
    00223
    00224
    00229
    00233 /*@-redecl@*/
    00234 /*@observer@*/ const char * Fstrerror(/*@null@*/ FD_t fd)
    00235         /*@*/;
    00236 /*@=redecl@*/
    00237
    00241 size_t Fread(/*@out@*/ void * buf, size_t size, size_t nmemb, FD_t fd)
    00242         /*@globals fileSystem @*/
    00243         /*@modifies fd, *buf, fileSystem @*/;
    00244
    00248 size_t Fwrite(const void * buf, size_t size, size_t nmemb, FD_t fd)
    00249         /*@globals fileSystem @*/
    00250         /*@modifies fd, fileSystem @*/;
    00251
    00255 int Fseek(FD_t fd, _libio_off_t offset, int whence)
    00256         /*@globals fileSystem @*/
    00257         /*@modifies fileSystem @*/;
    00258
    00262 int Fclose( /*@killref@*/ FD_t fd)
    00263         /*@globals fileSystem @*/
    00264         /*@modifies fd, fileSystem @*/;
    00265
    00268 /*@null@*/ FD_t Fdopen(FD_t ofd, const char * fmode)
    00269         /*@globals fileSystem @*/
    00270         /*@modifies ofd, fileSystem @*/;
    00271
    00275 /*@null@*/ FD_t Fopen(/*@null@*/ const char * path,
    00276                         /*@null@*/ const char * fmode)
    00277         /*@globals fileSystem @*/
    00278         /*@modifies fileSystem @*/;
    00279
    00280
    00284 int Fflush(/*@null@*/ FD_t fd)
    00285         /*@globals fileSystem @*/
    00286         /*@modifies fd, fileSystem @*/;
    00287
    00291 int Ferror(/*@null@*/ FD_t fd)
    00292         /*@*/;
    00293
    00297 int Fileno(FD_t fd)
    00298         /*@globals fileSystem @*/
    00299         /*@modifies fileSystem@*/;
    00300
    00304 int Fcntl(FD_t fd, int op, void *lip)
    00305         /*@globals fileSystem @*/
    00306         /*@modifies fd, *lip, fileSystem @*/;
    00307
    00314
    00318 int Mkdir(const char * path, mode_t mode)
    00319         /*@globals fileSystem @*/
    00320         /*@modifies fileSystem @*/;
    00321
    00325 int Chdir(const char * path)
    00326         /*@globals fileSystem @*/
    00327         /*@modifies fileSystem @*/;
    00328
    00332 int Rmdir(const char * path)
    00333         /*@globals fileSystem @*/
    00334         /*@modifies fileSystem @*/;
    00335
    00339 int Rename(const char * oldpath, const char * newpath)
    00340         /*@globals fileSystem @*/
    00341         /*@modifies fileSystem @*/;
    00342
    00346 int Link(const char * oldpath, const char * newpath)
    00347         /*@globals fileSystem @*/
    00348         /*@modifies fileSystem @*/;
    00349
    00353 int Unlink(const char * path)
    00354         /*@globals fileSystem @*/
    00355         /*@modifies fileSystem @*/;
    00356
    00360 int Readlink(const char * path, /*@out@*/ char * buf, size_t bufsiz)
    00361         /*@globals fileSystem @*/
    00362         /*@modifies *buf, fileSystem @*/;
    00363
    00367 int Stat(const char * path, /*@out@*/ struct stat * st)
    00368         /*@globals fileSystem @*/
    00369         /*@modifies *st, fileSystem @*/;
    00370
    00374 int Lstat(const char * path, /*@out@*/ struct stat * st)
    00375         /*@globals fileSystem @*/
    00376         /*@modifies *st, fileSystem @*/;
    00377
    00381 int Access(const char * path, int amode)
    00382         /*@globals fileSystem @*/
    00383         /*@modifies fileSystem @*/;
    00384
    00385
    00389 int Glob(const char * pattern, int flags,
    00390                 int errfunc(const char * epath, int eerrno),
    00391                 /*@out@*/ glob_t * pglob)
    00392         /*@globals fileSystem @*/
    00393         /*@modifies *pglob, fileSystem @*/;
    00394
    00398 void Globfree( /*@only@*/ glob_t * pglob)
    00399         /*@globals fileSystem @*/
    00400         /*@modifies *pglob, fileSystem @*/;
    00401
    00402
    00406 /*@null@*/
    00407 DIR * Opendir(const char * path)
    00408         /*@globals fileSystem @*/
    00409         /*@modifies fileSystem @*/;
    00410
    00414 /*@null@*/ struct dirent * Readdir(DIR * dir)
    00415         /*@globals fileSystem @*/
    00416         /*@modifies *dir, fileSystem @*/;
    00417
    00421 int     Closedir(/*@only@*/ DIR * dir)
    00422         /*@globals fileSystem @*/
    00423         /*@modifies *dir, fileSystem @*/;
    00424
    00432
    00435 off_t   fdSize(FD_t fd)
    00436         /*@globals fileSystem @*/
    00437         /*@modifies fd, fileSystem@*/;
    00438
    00441 /*@null@*/ FD_t fdDup(int fdno)
    00442         /*@globals fileSystem @*/
    00443         /*@modifies fileSystem@*/;
    00444
    00445 #ifdef UNUSED
    00446 /*@null@*/ FILE *fdFdopen( /*@only@*/ void * cookie, const char * mode);
    00447 #endif
    00448
    00449 /* XXX Legacy interfaces needed by gnorpm, rpmfind et al */
    00450
    00451 /*@-exportlocal@*/
    00454 #ifndef H_RPMIO_INTERNAL        /* XXX avoid gcc warning */
    00455 /*@unused@*/ int fdFileno(void * cookie)
    00456         /*@*/;
    00457 #define fdFileno(_fd)           fdio->_fileno(_fd)
    00458 #endif
    00459
    00462 /*@null@*/ FD_t fdOpen(const char *path, int flags, mode_t mode)
    00463         /*@globals fileSystem @*/
    00464         /*@modifies fileSystem @*/;
    00465 #define fdOpen(_path, _flags, _mode)    fdio->_open((_path), (_flags), (_mode))
    00466
    00469 ssize_t fdRead(void * cookie, /*@out@*/ char * buf, size_t count)
    00470         /*@globals fileSystem @*/
    00471         /*@modifies *cookie, *buf, fileSystem @*/;
    00472 #define fdRead(_fd, _buf, _count)       fdio->read((_fd), (_buf), (_count))
    00473
    00476 ssize_t fdWrite(void * cookie, const char * buf, size_t count)
    00477         /*@globals fileSystem @*/
    00478         /*@modifies *cookie, fileSystem @*/;
    00479 #define fdWrite(_fd, _buf, _count)      fdio->write((_fd), (_buf), (_count))
    00480
    00483 int fdClose( /*@only@*/ void * cookie)
    00484         /*@globals fileSystem @*/
    00485         /*@modifies *cookie, fileSystem @*/;
    00486 #define fdCLose(_fd)            fdio->close(_fd)
    00487
    00490 /*@unused@*/
    00491 /*@only@*/ /*@null@*/
    00492 FD_t fdLink (/*@only@*/ void * cookie, const char * msg)
    00493         /*@globals fileSystem @*/
    00494         /*@modifies *cookie, fileSystem @*/;
    00495 #define fdLink(_fd, _msg)       fdio->_fdref(_fd, _msg, __FILE__, __LINE__)
    00496
    00499 /*@unused@*/
    00500 /*@only@*/ /*@null@*/
    00501 FD_t fdFree(/*@only@*/ FD_t fd, const char * msg)
    00502         /*@globals fileSystem @*/
    00503         /*@modifies fd, fileSystem @*/;
    00504 #define fdFree(_fd, _msg)       fdio->_fdderef(_fd, _msg, __FILE__, __LINE__)
    00505
    00508 /*@unused@*/
    00509 /*@only@*/ /*@null@*/
    00510 FD_t fdNew (const char * msg)
    00511         /*@globals fileSystem @*/
    00512         /*@modifies fileSystem @*/;
    00513 #define fdNew(_msg)             fdio->_fdnew(_msg, __FILE__, __LINE__)
    00514
    00517 int fdWritable(FD_t fd, int secs)
    00518         /*@globals errno, fileSystem @*/
    00519         /*@modifies fd, errno, fileSystem @*/;
    00520
    00523 int fdReadable(FD_t fd, int secs)
    00524         /*@globals errno @*/
    00525         /*@modifies fd, errno @*/;
    00526 /*@=exportlocal@*/
    00527
    00531 /*@-typeuse@*/
    00532 typedef enum ftperrCode_e {
    00533     FTPERR_BAD_SERVER_RESPONSE  = -1,
    00534     FTPERR_SERVER_IO_ERROR      = -2,
    00535     FTPERR_SERVER_TIMEOUT       = -3,
    00536     FTPERR_BAD_HOST_ADDR        = -4,
    00537     FTPERR_BAD_HOSTNAME         = -5,
    00538     FTPERR_FAILED_CONNECT       = -6,
    00539     FTPERR_FILE_IO_ERROR        = -7,
    00540     FTPERR_PASSIVE_ERROR        = -8,
    00541     FTPERR_FAILED_DATA_CONNECT  = -9,
    00542     FTPERR_FILE_NOT_FOUND       = -10,
    00543     FTPERR_NIC_ABORT_IN_PROGRESS= -11,
    00544     FTPERR_UNKNOWN              = -100
    00545 } ftperrCode;
    00546 /*@=typeuse@*/
    00547
    00550 /*@-redecl@*/
    00551 /*@observer@*/ const char *const ftpStrerror(int errorNumber)   /*@*/;
    00552 /*@=redecl@*/
    00553
    00556 /*@unused@*/
    00557 /*@dependent@*/ /*@null@*/ void * ufdGetUrlinfo(FD_t fd)
    00558         /*@modifies fd @*/;
    00559
    00562 /*@-redecl@*/
    00563 /*@unused@*/
    00564 /*@observer@*/ const char * urlStrerror(const char * url)       /*@*/;
    00565 /*@=redecl@*/
    00566
    00569 /*@-exportlocal@*/
    00570 int ufdCopy(FD_t sfd, FD_t tfd)
    00571         /*@globals fileSystem @*/
    00572         /*@modifies sfd, tfd, fileSystem @*/;
    00573 /*@=exportlocal@*/
    00574
    00577 int ufdGetFile( /*@killref@*/ FD_t sfd, FD_t tfd)
    00578         /*@globals fileSystem @*/
    00579         /*@modifies sfd, tfd, fileSystem @*/;
    00580
    00583 /*@unused@*/ int timedRead(FD_t fd, /*@out@*/ void * bufptr, int length)
    00584         /*@globals fileSystem @*/
    00585         /*@modifies fd, *bufptr, fileSystem @*/;
    00586 #define timedRead       ufdio->read
    00587
    00588 /*@-exportlocal@*/
    00591 /*@observer@*/ /*@unchecked@*/ extern FDIO_t fdio;
    00592
    00595 /*@observer@*/ /*@unchecked@*/ extern FDIO_t fpio;
    00596
    00599 /*@observer@*/ /*@unchecked@*/ extern FDIO_t ufdio;
    00600
    00603 /*@observer@*/ /*@unchecked@*/ extern FDIO_t gzdio;
    00604
    00607 /*@observer@*/ /*@unchecked@*/ extern FDIO_t bzdio;
    00608
    00611 /*@observer@*/ /*@unchecked@*/ extern FDIO_t fadio;
    00612 /*@=exportlocal@*/
    00615 /*@unused@*/ static inline int xislower(int c) /*@*/ {
    00616     return (c >= 'a' && c <= 'z');
    00617 }
    00618 /*@unused@*/ static inline int xisupper(int c) /*@*/ {
    00619     return (c >= 'A' && c <= 'Z');
    00620 }
    00621 /*@unused@*/ static inline int xisalpha(int c) /*@*/ {
    00622     return (xislower(c) || xisupper(c));
    00623 }
    00624 /*@unused@*/ static inline int xisdigit(int c) /*@*/ {
    00625     return (c >= '0' && c <= '9');
    00626 }
    00627 /*@unused@*/ static inline int xisalnum(int c) /*@*/ {
    00628     return (xisalpha(c) || xisdigit(c));
    00629 }
    00630 /*@unused@*/ static inline int xisblank(int c) /*@*/ {
    00631     return (c == ' ' || c == '\t');
    00632 }
    00633 /*@unused@*/ static inline int xisspace(int c) /*@*/ {
    00634     return (xisblank(c) || c == '\n' || c == '\r' || c == '\f' || c == '\v');
    00635 }
    00636
    00637 /*@unused@*/ static inline int xtolower(int c) /*@*/ {
    00638     return ((xisupper(c)) ? (c | ('a' - 'A')) : c);
    00639 }
    00640 /*@unused@*/ static inline int xtoupper(int c) /*@*/ {
    00641     return ((xislower(c)) ? (c & ~('a' - 'A')) : c);
    00642 }
    00643
    00647 int xstrcasecmp(const char * s1, const char * s2)               /*@*/;
    00648
    00652 int xstrncasecmp(const char *s1, const char * s2, size_t n)     /*@*/;
    00653
    00654 #ifdef __cplusplus
    00655 }
    00656 #endif
    00657
    00658 #endif  /* H_RPMIO */