rpm
4.5
|
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 00090 typedef FD_t (*fdio_fopen_function_t) (const char * path, const char * fmode) 00091 /*@globals errno, fileSystem @*/ 00092 /*@modifies errno, fileSystem @*/; 00093 00096 typedef FD_t (*fdio_fdopen_function_t) (void * cookie, const char * fmode) 00097 /*@globals errno, fileSystem @*/ 00098 /*@modifies errno, fileSystem @*/; 00099 00105 struct FDIO_s { 00106 fdio_read_function_t read; 00107 fdio_write_function_t write; 00108 fdio_seek_function_t seek; 00109 fdio_close_function_t close; 00110 fdio_fopen_function_t _fopen; 00111 fdio_fdopen_function_t _fdopen; 00112 }; 00113 00114 00119 00123 /*@observer@*/ const char * Fstrerror(/*@null@*/ FD_t fd) 00124 /*@*/; 00125 00129 /*@-incondefs@*/ 00130 size_t Fread(/*@out@*/ void * buf, size_t size, size_t nmemb, FD_t fd) 00131 /*@globals fileSystem @*/ 00132 /*@modifies fd, *buf, fileSystem @*/ 00133 /*@requires maxSet(buf) >= (nmemb - 1) @*/ 00134 /*@ensures maxRead(buf) == result @*/; 00135 /*@=incondefs@*/ 00136 00140 /*@-incondefs@*/ 00141 size_t Fwrite(const void * buf, size_t size, size_t nmemb, FD_t fd) 00142 /*@globals fileSystem @*/ 00143 /*@modifies fd, fileSystem @*/ 00144 /*@requires maxRead(buf) >= nmemb @*/; 00145 /*@=incondefs@*/ 00146 00150 int Fseek(FD_t fd, _libio_off_t offset, int whence) 00151 /*@globals fileSystem @*/ 00152 /*@modifies fileSystem @*/; 00153 00157 int Fclose( /*@killref@*/ FD_t fd) 00158 /*@globals fileSystem, internalState @*/ 00159 /*@modifies fd, fileSystem, internalState @*/; 00160 00163 /*@null@*/ FD_t Fdopen(FD_t ofd, const char * fmode) 00164 /*@globals fileSystem, internalState @*/ 00165 /*@modifies ofd, fileSystem, internalState @*/; 00166 00170 /*@null@*/ FD_t Fopen(/*@null@*/ const char * path, 00171 /*@null@*/ const char * fmode) 00172 /*@globals h_errno, fileSystem, internalState @*/ 00173 /*@modifies fileSystem, internalState @*/; 00174 00175 00179 int Fflush(/*@null@*/ FD_t fd) 00180 /*@globals fileSystem @*/ 00181 /*@modifies fd, fileSystem @*/; 00182 00186 int Ferror(/*@null@*/ FD_t fd) 00187 /*@*/; 00188 00192 int Fileno(FD_t fd) 00193 /*@globals fileSystem @*/ 00194 /*@modifies fileSystem@*/; 00195 00199 /*@unused@*/ 00200 int Fcntl(FD_t fd, int op, void *lip) 00201 /*@globals errno, fileSystem @*/ 00202 /*@modifies fd, *lip, errno, fileSystem @*/; 00203 00210 00214 int Mkdir(const char * path, mode_t mode) 00215 /*@globals errno, h_errno, fileSystem, internalState @*/ 00216 /*@modifies errno, fileSystem, internalState @*/; 00217 00221 int Chdir(const char * path) 00222 /*@globals errno, h_errno, fileSystem, internalState @*/ 00223 /*@modifies errno, fileSystem, internalState @*/; 00224 00228 int Rmdir(const char * path) 00229 /*@globals errno, h_errno, fileSystem, internalState @*/ 00230 /*@modifies errno, fileSystem, internalState @*/; 00231 00232 /*@unchecked@*/ /*@observer@*/ /*@null@*/ 00233 extern const char * _chroot_prefix; 00234 00239 int Chroot(const char * path) 00240 /*@globals _chroot_prefix, errno, fileSystem, internalState @*/ 00241 /*@modifies _chroot_prefix, errno, fileSystem, internalState @*/; 00242 00247 int Open(const char * path, int flags, mode_t mode) 00248 /*@globals errno, fileSystem, internalState @*/ 00249 /*@modifies errno, fileSystem, internalState @*/; 00250 00254 int Rename(const char * oldpath, const char * newpath) 00255 /*@globals errno, h_errno, fileSystem, internalState @*/ 00256 /*@modifies errno, fileSystem, internalState @*/; 00257 00261 int Link(const char * oldpath, const char * newpath) 00262 /*@globals errno, fileSystem, internalState @*/ 00263 /*@modifies errno, fileSystem, internalState @*/; 00264 00268 int Unlink(const char * path) 00269 /*@globals errno, h_errno, fileSystem, internalState @*/ 00270 /*@modifies errno, fileSystem, internalState @*/; 00271 00275 int Stat(const char * path, /*@out@*/ struct stat * st) 00276 /*@globals errno, h_errno, fileSystem, internalState @*/ 00277 /*@modifies *st, errno, fileSystem, internalState @*/; 00278 00282 int Lstat(const char * path, /*@out@*/ struct stat * st) 00283 /*@globals errno, h_errno, fileSystem, internalState @*/ 00284 /*@modifies *st, errno, fileSystem, internalState @*/; 00285 00290 int Chown(const char * path, uid_t owner, gid_t group) 00291 /*@globals errno, fileSystem, internalState @*/ 00292 /*@modifies errno, fileSystem, internalState @*/; 00293 00298 int Lchown(const char * path, uid_t owner, gid_t group) 00299 /*@globals errno, fileSystem, internalState @*/ 00300 /*@modifies errno, fileSystem, internalState @*/; 00301 00306 int Chmod(const char * path, mode_t mode) 00307 /*@globals errno, fileSystem, internalState @*/ 00308 /*@modifies errno, fileSystem, internalState @*/; 00309 00314 int Mkfifo(const char * path, mode_t mode) 00315 /*@globals errno, fileSystem, internalState @*/ 00316 /*@modifies errno, fileSystem, internalState @*/; 00317 00322 int Mknod(const char * path, mode_t mode, dev_t dev) 00323 /*@globals errno, fileSystem, internalState @*/ 00324 /*@modifies errno, fileSystem, internalState @*/; 00325 00330 int Utime(const char * path, const struct utimbuf * buf) 00331 /*@globals errno, fileSystem, internalState @*/ 00332 /*@modifies errno, fileSystem, internalState @*/; 00333 00338 int Utimes(const char * path, const struct timeval * times) 00339 /*@globals errno, fileSystem, internalState @*/ 00340 /*@modifies errno, fileSystem, internalState @*/; 00341 00346 int Symlink(const char * oldpath, const char * newpath) 00347 /*@globals errno, fileSystem, internalState @*/ 00348 /*@modifies errno, fileSystem, internalState @*/; 00349 00354 /*@-incondefs@*/ 00355 int Readlink(const char * path, /*@out@*/ char * buf, size_t bufsiz) 00356 /*@globals errno, h_errno, fileSystem, internalState @*/ 00357 /*@modifies *buf, errno, fileSystem, internalState @*/ 00358 /*@requires maxSet(buf) >= (bufsiz - 1) @*/ 00359 /*@ensures maxRead(buf) <= bufsiz @*/; 00360 /*@=incondefs@*/ 00361 00366 int Access(const char * path, int amode) 00367 /*@globals errno, fileSystem @*/ 00368 /*@modifies errno, fileSystem @*/; 00369 00373 int Glob_pattern_p (const char *pattern, int quote) 00374 /*@*/; 00375 00379 int Glob_error(const char * epath, int eerrno) 00380 /*@*/; 00381 00385 int Glob(const char * pattern, int flags, 00386 int errfunc(const char * epath, int eerrno), 00387 /*@out@*/ glob_t * pglob) 00388 /*@globals fileSystem @*/ 00389 /*@modifies *pglob, fileSystem @*/; 00390 00394 void Globfree( /*@only@*/ glob_t * pglob) 00395 /*@globals fileSystem @*/ 00396 /*@modifies *pglob, fileSystem @*/; 00397 00398 00402 /*@null@*/ 00403 DIR * Opendir(const char * path) 00404 /*@globals errno, h_errno, fileSystem, internalState @*/ 00405 /*@modifies errno, fileSystem, internalState @*/; 00406 00410 /*@dependent@*/ /*@null@*/ 00411 struct dirent * Readdir(DIR * dir) 00412 /*@globals errno, fileSystem @*/ 00413 /*@modifies *dir, errno, fileSystem @*/; 00414 00418 int Closedir(/*@only@*/ DIR * dir) 00419 /*@globals errno, fileSystem @*/ 00420 /*@modifies *dir, errno, fileSystem @*/; 00421 00425 char * Realpath(const char * path, /*@out@*/ /*@null@*/ char * resolved_path) 00426 /*@globals errno, fileSystem, internalState @*/ 00427 /*@modifies *resolved_path, errno, fileSystem, internalState @*/; 00428 00433 off_t Lseek(int fdno, off_t offset, int whence) 00434 /*@globals errno, fileSystem @*/ 00435 /*@modifies errno, fileSystem @*/; 00436 00444 00447 off_t fdSize(FD_t fd) 00448 /*@globals fileSystem @*/ 00449 /*@modifies fd, fileSystem@*/; 00450 00453 /*@null@*/ FD_t fdDup(int fdno) 00454 /*@globals fileSystem, internalState @*/ 00455 /*@modifies fileSystem, internalState @*/; 00456 00457 /*@-exportlocal@*/ 00460 /*@-incondefs@*/ 00461 ssize_t fdRead(void * cookie, /*@out@*/ char * buf, size_t count) 00462 /*@globals errno, fileSystem, internalState @*/ 00463 /*@modifies *cookie, *buf, errno, fileSystem, internalState @*/ 00464 /*@requires maxSet(buf) >= (count - 1) @*/ 00465 /*@ensures maxRead(buf) == result @*/ ; 00466 #define fdRead(_fd, _buf, _count) fdio->read((_fd), (_buf), (_count)) 00467 /*@=incondefs@*/ 00468 00471 ssize_t fdWrite(void * cookie, const char * buf, size_t count) 00472 /*@globals errno, fileSystem, internalState @*/ 00473 /*@modifies *cookie, errno, fileSystem, internalState @*/; 00474 #define fdWrite(_fd, _buf, _count) fdio->write((_fd), (_buf), (_count)) 00475 00478 int fdClose( /*@only@*/ void * cookie) 00479 /*@globals errno, fileSystem, systemState, internalState @*/ 00480 /*@modifies *cookie, errno, fileSystem, systemState, internalState @*/; 00481 #define fdClose(_fd) fdio->close(_fd) 00482 00485 /*@null@*/ FD_t fdOpen(const char *path, int flags, mode_t mode) 00486 /*@globals errno, fileSystem, internalState @*/ 00487 /*@modifies errno, fileSystem, internalState @*/; 00488 #define fdOpen(_path, _flags, _mode) fdio->_open((_path), (_flags), (_mode)) 00489 00492 /*@unused@*/ 00493 /*@only@*/ /*@null@*/ 00494 FD_t fdLink (/*@only@*/ void * cookie, const char * msg) 00495 /*@globals fileSystem @*/ 00496 /*@modifies *cookie, fileSystem @*/; 00497 /*@unused@*/ 00498 /*@only@*/ /*@null@*/ 00499 FD_t XfdLink (/*@only@*/ void * cookie, const char * msg, const char * fn, unsigned ln) 00500 /*@globals fileSystem @*/ 00501 /*@modifies *cookie, fileSystem @*/; 00502 #define fdLink(_fd, _msg) XfdLink(_fd, _msg, __FILE__, __LINE__) 00503 00506 /*@unused@*/ 00507 /*@only@*/ /*@null@*/ 00508 FD_t fdFree(/*@only@*/ FD_t fd, const char * msg) 00509 /*@globals fileSystem @*/ 00510 /*@modifies fd, fileSystem @*/; 00511 /*@unused@*/ 00512 /*@only@*/ /*@null@*/ 00513 FD_t XfdFree(/*@only@*/ FD_t fd, const char * msg, const char * fn, unsigned ln) 00514 /*@globals fileSystem @*/ 00515 /*@modifies fd, fileSystem @*/; 00516 #define fdFree(_fd, _msg) XfdFree(_fd, _msg, __FILE__, __LINE__) 00517 00520 /*@unused@*/ 00521 /*@only@*/ /*@null@*/ 00522 FD_t fdNew (const char * msg) 00523 /*@globals fileSystem @*/ 00524 /*@modifies fileSystem @*/; 00525 /*@unused@*/ 00526 /*@only@*/ /*@null@*/ 00527 FD_t XfdNew (const char * msg, const char * fn, unsigned ln) 00528 /*@globals fileSystem @*/ 00529 /*@modifies fileSystem @*/; 00530 #define fdNew(_msg) XfdNew(_msg, __FILE__, __LINE__) 00531 00534 int fdWritable(FD_t fd, int secs) 00535 /*@globals errno, fileSystem @*/ 00536 /*@modifies fd, errno, fileSystem @*/; 00537 00540 int fdReadable(FD_t fd, int secs) 00541 /*@globals errno @*/ 00542 /*@modifies fd, errno @*/; 00543 /*@=exportlocal@*/ 00544 00553 int rpmioMkpath(const char * path, mode_t mode, uid_t uid, gid_t gid) 00554 /*@globals h_errno, fileSystem, internalState @*/ 00555 /*@modifies fileSystem, internalState @*/; 00556 00564 int rpmioAccess(const char *FN, /*@null@*/ const char * path, int mode) 00565 /*@globals fileSystem, internalState @*/ 00566 /*@modifies fileSystem, internalState @*/; 00567 00573 extern char * (*Getpass) (const char * prompt) 00574 /*@*/; 00575 char * _GetPass (const char * prompt) 00576 /*@*/; 00577 char * _RequestPass (const char * prompt) 00578 /*@*/; 00579 00583 /*@-typeuse@*/ 00584 typedef enum ftperrCode_e { 00585 FTPERR_NE_ERROR = -1, 00586 FTPERR_NE_LOOKUP = -2, 00587 FTPERR_NE_AUTH = -3, 00588 FTPERR_NE_PROXYAUTH = -4, 00589 FTPERR_NE_CONNECT = -5, 00590 FTPERR_NE_TIMEOUT = -6, 00591 FTPERR_NE_FAILED = -7, 00592 FTPERR_NE_RETRY = -8, 00593 FTPERR_NE_REDIRECT = -9, 00595 FTPERR_BAD_SERVER_RESPONSE = -81, 00596 FTPERR_SERVER_IO_ERROR = -82, 00597 FTPERR_SERVER_TIMEOUT = -83, 00598 FTPERR_BAD_HOST_ADDR = -84, 00599 FTPERR_BAD_HOSTNAME = -85, 00600 FTPERR_FAILED_CONNECT = -86, 00601 FTPERR_FILE_IO_ERROR = -87, 00602 FTPERR_PASSIVE_ERROR = -88, 00603 FTPERR_FAILED_DATA_CONNECT = -89, 00604 FTPERR_FILE_NOT_FOUND = -90, 00605 FTPERR_NIC_ABORT_IN_PROGRESS= -91, 00606 FTPERR_UNKNOWN = -100 00607 } ftperrCode; 00608 /*@=typeuse@*/ 00609 00612 /*@-redecl@*/ 00613 /*@observer@*/ const char * ftpStrerror(int errorNumber) 00614 /*@*/; 00615 /*@=redecl@*/ 00616 00619 /*@unused@*/ 00620 /*@dependent@*/ /*@null@*/ void * ufdGetUrlinfo(FD_t fd) 00621 /*@modifies fd @*/; 00622 00625 /*@-redecl@*/ 00626 /*@unused@*/ 00627 /*@observer@*/ const char * urlStrerror(const char * url) 00628 /*@globals h_errno, internalState @*/ 00629 /*@modifies internalState @*/; 00630 /*@=redecl@*/ 00631 00634 /*@-exportlocal@*/ 00635 int ufdCopy(FD_t sfd, FD_t tfd) 00636 /*@globals fileSystem @*/ 00637 /*@modifies sfd, tfd, fileSystem @*/; 00638 /*@=exportlocal@*/ 00639 00642 int ufdGetFile( /*@killref@*/ FD_t sfd, FD_t tfd) 00643 /*@globals fileSystem, internalState @*/ 00644 /*@modifies sfd, tfd, fileSystem, internalState @*/; 00645 00648 /*@unused@*/ int timedRead(FD_t fd, /*@out@*/ void * bufptr, int length) 00649 /*@globals fileSystem @*/ 00650 /*@modifies fd, *bufptr, fileSystem @*/; 00651 #define timedRead (ufdio->read) 00652 00653 /*@-exportlocal@*/ 00656 /*@observer@*/ /*@unchecked@*/ extern FDIO_t fdio; 00657 00660 /*@observer@*/ /*@unchecked@*/ extern FDIO_t fpio; 00661 00664 /*@observer@*/ /*@unchecked@*/ extern FDIO_t ufdio; 00665 00668 /*@observer@*/ /*@unchecked@*/ extern FDIO_t gzdio; 00669 00672 /*@observer@*/ /*@unchecked@*/ extern FDIO_t bzdio; 00673 00676 /*@observer@*/ /*@unchecked@*/ extern FDIO_t lzdio; 00677 00678 /*@=exportlocal@*/ 00681 /*@unused@*/ static inline int xislower(int c) /*@*/ { 00682 return (c >= 'a' && c <= 'z'); 00683 } 00684 /*@unused@*/ static inline int xisupper(int c) /*@*/ { 00685 return (c >= 'A' && c <= 'Z'); 00686 } 00687 /*@unused@*/ static inline int xisalpha(int c) /*@*/ { 00688 return (xislower(c) || xisupper(c)); 00689 } 00690 /*@unused@*/ static inline int xisdigit(int c) /*@*/ { 00691 return (c >= '0' && c <= '9'); 00692 } 00693 /*@unused@*/ static inline int xisalnum(int c) /*@*/ { 00694 return (xisalpha(c) || xisdigit(c)); 00695 } 00696 /*@unused@*/ static inline int xisblank(int c) /*@*/ { 00697 return (c == ' ' || c == '\t'); 00698 } 00699 /*@unused@*/ static inline int xisspace(int c) /*@*/ { 00700 return (xisblank(c) || c == '\n' || c == '\r' || c == '\f' || c == '\v'); 00701 } 00702 /*@unused@*/ static inline int xiscntrl(int c) /*@*/ { 00703 return (c < ' '); 00704 } 00705 /*@unused@*/ static inline int xisascii(int c) /*@*/ { 00706 return ((c & 0x80) != 0x80); 00707 } 00708 /*@unused@*/ static inline int xisprint(int c) /*@*/ { 00709 return (c >= ' ' && xisascii(c)); 00710 } 00711 /*@unused@*/ static inline int xisgraph(int c) /*@*/ { 00712 return (c > ' ' && xisascii(c)); 00713 } 00714 /*@unused@*/ static inline int xispunct(int c) /*@*/ { 00715 return (xisgraph(c) && !xisalnum(c)); 00716 } 00717 00718 /*@unused@*/ static inline int xtolower(int c) /*@*/ { 00719 return ((xisupper(c)) ? (c | ('a' - 'A')) : c); 00720 } 00721 /*@unused@*/ static inline int xtoupper(int c) /*@*/ { 00722 return ((xislower(c)) ? (c & ~('a' - 'A')) : c); 00723 } 00724 00728 int xstrcasecmp(const char * s1, const char * s2) /*@*/; 00729 00733 int xstrncasecmp(const char *s1, const char * s2, size_t n) /*@*/; 00734 00738 /*@only@*/ /*@null@*/ 00739 const char * xstrtolocale(/*@only@*/ const char *str) 00740 /*@modifies *str @*/; 00741 00742 #if !defined(SWIG) 00743 00748 /*@unused@*/ static inline /*@null@*/ 00749 void * _free(/*@only@*/ /*@null@*/ /*@out@*/ const void * p) 00750 /*@modifies p @*/ 00751 { 00752 if (p != NULL) free((void *)p); 00753 return NULL; 00754 } 00755 #endif 00756 00757 #ifdef __cplusplus 00758 } 00759 #endif 00760 00761 #endif /* H_RPMIO */