00001 #ifndef H_RPMIO
00002 #define H_RPMIO
00003
00009 #include <sys/types.h>
00010 #include <sys/stat.h>
00011 #include <dirent.h>
00012
00013 #include "glob.h"
00014
00015 #include <stdio.h>
00016 #include <stdlib.h>
00017 #include <unistd.h>
00018
00026 #if !defined(__LCLINT__) && defined(__GLIBC__) && \
00027 (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2))
00028 #define USE_COOKIE_SEEK_POINTER 1
00029 typedef _IO_off64_t _libio_off_t;
00030 typedef _libio_off_t * _libio_pos_t;
00031 #else
00032 typedef off_t _libio_off_t;
00033 typedef off_t _libio_pos_t;
00034 #endif
00035
00039 typedef struct _FD_s * FD_t;
00040
00043 typedef struct FDIO_s * FDIO_t;
00044
00045 #ifdef __cplusplus
00046 extern "C" {
00047 #endif
00048
00053
00056 typedef ssize_t (*fdio_read_function_t) (void *cookie, char *buf, size_t nbytes)
00057
00058
00059
00060 ;
00061
00064 typedef ssize_t (*fdio_write_function_t) (void *cookie, const char *buf, size_t nbytes)
00065
00066 ;
00067
00070 typedef int (*fdio_seek_function_t) (void *cookie, _libio_pos_t pos, int whence)
00071
00072 ;
00073
00076 typedef int (*fdio_close_function_t) (void *cookie)
00077
00078 ;
00079
00080
00083 typedef FD_t (*fdio_ref_function_t) ( void * cookie,
00084 const char * msg, const char * file, unsigned line)
00085
00086 ;
00087
00090 typedef FD_t (*fdio_deref_function_t) ( FD_t fd,
00091 const char * msg, const char * file, unsigned line)
00092
00093 ;
00094
00095
00098 typedef FD_t (*fdio_new_function_t) (const char * msg,
00099 const char * file, unsigned line)
00100
00101 ;
00102
00103
00106 typedef int (*fdio_fileno_function_t) (void * cookie)
00107
00108 ;
00109
00110
00113 typedef FD_t (*fdio_open_function_t) (const char * path, int flags, mode_t mode)
00114
00115 ;
00116
00119 typedef FD_t (*fdio_fopen_function_t) (const char * path, const char * fmode)
00120
00121 ;
00122
00125 typedef void * (*fdio_ffileno_function_t) (FD_t fd)
00126
00127 ;
00128
00131 typedef int (*fdio_fflush_function_t) (FD_t fd)
00132
00133 ;
00141
00144 typedef int (*fdio_mkdir_function_t) (const char * path, mode_t mode)
00145
00146 ;
00147
00150 typedef int (*fdio_chdir_function_t) (const char * path)
00151
00152 ;
00153
00156 typedef int (*fdio_rmdir_function_t) (const char * path)
00157
00158 ;
00159
00162 typedef int (*fdio_rename_function_t) (const char * oldpath, const char * newpath)
00163
00164 ;
00165
00168 typedef int (*fdio_unlink_function_t) (const char * path)
00169
00170 ;
00171
00172
00175 typedef int (*fdio_stat_function_t) (const char * path, struct stat * st)
00176
00177 ;
00178
00181 typedef int (*fdio_lstat_function_t) (const char * path, struct stat * st)
00182
00183 ;
00184
00187 typedef int (*fdio_access_function_t) (const char * path, int amode)
00188
00189 ;
00190
00196 struct FDIO_s {
00197 fdio_read_function_t read;
00198 fdio_write_function_t write;
00199 fdio_seek_function_t seek;
00200 fdio_close_function_t close;
00201
00202 fdio_ref_function_t _fdref;
00203 fdio_deref_function_t _fdderef;
00204 fdio_new_function_t _fdnew;
00205 fdio_fileno_function_t _fileno;
00206
00207 fdio_open_function_t _open;
00208 fdio_fopen_function_t _fopen;
00209 fdio_ffileno_function_t _ffileno;
00210 fdio_fflush_function_t _fflush;
00211
00212 fdio_mkdir_function_t _mkdir;
00213 fdio_chdir_function_t _chdir;
00214 fdio_rmdir_function_t _rmdir;
00215 fdio_rename_function_t _rename;
00216 fdio_unlink_function_t _unlink;
00217 };
00218
00219
00224
00228 const char * Fstrerror( FD_t fd)
00229 ;
00230
00234
00235 size_t Fread( void * buf, size_t size, size_t nmemb, FD_t fd)
00236
00237
00238
00239 ;
00240
00241
00245
00246 size_t Fwrite(const void * buf, size_t size, size_t nmemb, FD_t fd)
00247
00248
00249 ;
00250
00251
00255 int Fseek(FD_t fd, _libio_off_t offset, int whence)
00256
00257 ;
00258
00262 int Fclose( FD_t fd)
00263
00264 ;
00265
00268 FD_t Fdopen(FD_t ofd, const char * fmode)
00269
00270 ;
00271
00275 FD_t Fopen( const char * path,
00276 const char * fmode)
00277
00278 ;
00279
00280
00284 int Fflush( FD_t fd)
00285
00286 ;
00287
00291 int Ferror( FD_t fd)
00292 ;
00293
00297 int Fileno(FD_t fd)
00298
00299 ;
00300
00304
00305 int Fcntl(FD_t fd, int op, void *lip)
00306
00307 ;
00308
00315
00319 int Mkdir(const char * path, mode_t mode)
00320
00321 ;
00322
00326 int Chdir(const char * path)
00327
00328 ;
00329
00333 int Rmdir(const char * path)
00334
00335 ;
00336
00337
00338 extern const char * _chroot_prefix;
00339
00344 int Chroot(const char * path)
00345
00346 ;
00347
00352 int Open(const char * path, int flags, mode_t mode)
00353
00354 ;
00355
00359 int Rename(const char * oldpath, const char * newpath)
00360
00361 ;
00362
00366 int Link(const char * oldpath, const char * newpath)
00367
00368 ;
00369
00373 int Unlink(const char * path)
00374
00375 ;
00376
00380 int Stat(const char * path, struct stat * st)
00381
00382 ;
00383
00387 int Lstat(const char * path, struct stat * st)
00388
00389 ;
00390
00395 int Chown(const char * path, uid_t owner, gid_t group)
00396
00397 ;
00398
00403 int Lchown(const char * path, uid_t owner, gid_t group)
00404
00405 ;
00406
00411 int Chmod(const char * path, mode_t mode)
00412
00413 ;
00414
00419 int Mkfifo(const char * path, mode_t mode)
00420
00421 ;
00422
00427 int Mknod(const char * path, mode_t mode, dev_t dev)
00428
00429 ;
00430
00435 struct utimbuf;
00436 int Utime(const char * path, const struct utimbuf * buf)
00437
00438 ;
00439
00444 int Utimes(const char * path, const struct timeval * times)
00445
00446 ;
00447
00452 int Symlink(const char * oldpath, const char * newpath)
00453
00454 ;
00455
00460
00461 int Readlink(const char * path, char * buf, size_t bufsiz)
00462
00463
00464
00465 ;
00466
00467
00472 int Access(const char * path, int amode)
00473
00474 ;
00475
00476 #if defined(__linux__)
00477
00480 int Mount(const char *source, const char *target,
00481 const char *filesystemtype, unsigned long mountflags,
00482 const void *data)
00483
00484 ;
00485
00489 int Umount(const char *target)
00490
00491 ;
00492
00496 int Umount2(const char *target, int flags)
00497
00498 ;
00499 #endif
00500
00504 int Glob_pattern_p (const char *pattern, int quote)
00505 ;
00506
00510 int Glob_error(const char * epath, int eerrno)
00511 ;
00512
00516 int Glob(const char * pattern, int flags,
00517 int errfunc(const char * epath, int eerrno),
00518 glob_t * pglob)
00519
00520 ;
00521
00525 void Globfree( glob_t * pglob)
00526
00527 ;
00528
00529
00533
00534 DIR * Opendir(const char * path)
00535
00536 ;
00537
00541
00542 struct dirent * Readdir(DIR * dir)
00543
00544 ;
00545
00549 int Closedir( DIR * dir)
00550
00551 ;
00552
00557 off_t Lseek(int fdno, off_t offset, int whence)
00558
00559 ;
00560
00568
00571 off_t fdSize(FD_t fd)
00572
00573 ;
00574
00577 FD_t fdDup(int fdno)
00578
00579 ;
00580
00581 #ifdef UNUSED
00582 FILE *fdFdopen( void * cookie, const char * mode);
00583 #endif
00584
00585
00586
00587
00590 #ifndef H_RPMIO_INTERNAL
00591 int fdFileno(void * cookie)
00592 ;
00593 #define fdFileno(_fd) fdio->_fileno(_fd)
00594 #endif
00595
00598 FD_t fdOpen(const char *path, int flags, mode_t mode)
00599
00600 ;
00601 #define fdOpen(_path, _flags, _mode) fdio->_open((_path), (_flags), (_mode))
00602
00605
00606 ssize_t fdRead(void * cookie, char * buf, size_t count)
00607
00608
00609
00610 ;
00611 #define fdRead(_fd, _buf, _count) fdio->read((_fd), (_buf), (_count))
00612
00613
00616 ssize_t fdWrite(void * cookie, const char * buf, size_t count)
00617
00618 ;
00619 #define fdWrite(_fd, _buf, _count) fdio->write((_fd), (_buf), (_count))
00620
00623 int fdClose( void * cookie)
00624
00625 ;
00626 #define fdClose(_fd) fdio->close(_fd)
00627
00630
00631
00632 FD_t fdLink ( void * cookie, const char * msg)
00633
00634 ;
00635 #define fdLink(_fd, _msg) fdio->_fdref(_fd, _msg, __FILE__, __LINE__)
00636
00639
00640
00641 FD_t fdFree( FD_t fd, const char * msg)
00642
00643 ;
00644 #define fdFree(_fd, _msg) fdio->_fdderef(_fd, _msg, __FILE__, __LINE__)
00645
00648
00649
00650 FD_t fdNew (const char * msg)
00651
00652 ;
00653 #define fdNew(_msg) fdio->_fdnew(_msg, __FILE__, __LINE__)
00654
00657 int fdWritable(FD_t fd, int secs)
00658
00659 ;
00660
00663 int fdReadable(FD_t fd, int secs)
00664
00665 ;
00666
00667
00676 int rpmioMkpath(const char * path, mode_t mode, uid_t uid, gid_t gid)
00677
00678 ;
00679
00687 int rpmioAccess(const char *FN, const char * path, int mode)
00688
00689 ;
00690
00696 extern char * (*Getpass) (const char * prompt)
00697 ;
00698 char * _GetPass (const char * prompt)
00699 ;
00700 char * _RequestPass (const char * prompt)
00701 ;
00702
00706
00707 typedef enum ftperrCode_e {
00708 FTPERR_NE_ERROR = -1,
00709 FTPERR_NE_LOOKUP = -2,
00710 FTPERR_NE_AUTH = -3,
00711 FTPERR_NE_PROXYAUTH = -4,
00712 FTPERR_NE_CONNECT = -5,
00713 FTPERR_NE_TIMEOUT = -6,
00714 FTPERR_NE_FAILED = -7,
00715 FTPERR_NE_RETRY = -8,
00716 FTPERR_NE_REDIRECT = -9,
00718 FTPERR_BAD_SERVER_RESPONSE = -81,
00719 FTPERR_SERVER_IO_ERROR = -82,
00720 FTPERR_SERVER_TIMEOUT = -83,
00721 FTPERR_BAD_HOST_ADDR = -84,
00722 FTPERR_BAD_HOSTNAME = -85,
00723 FTPERR_FAILED_CONNECT = -86,
00724 FTPERR_FILE_IO_ERROR = -87,
00725 FTPERR_PASSIVE_ERROR = -88,
00726 FTPERR_FAILED_DATA_CONNECT = -89,
00727 FTPERR_FILE_NOT_FOUND = -90,
00728 FTPERR_NIC_ABORT_IN_PROGRESS= -91,
00729 FTPERR_UNKNOWN = -100
00730 } ftperrCode;
00731
00732
00735
00736 const char * ftpStrerror(int errorNumber)
00737 ;
00738
00739
00742
00743 void * ufdGetUrlinfo(FD_t fd)
00744 ;
00745
00748
00749
00750 const char * urlStrerror(const char * url)
00751
00752 ;
00753
00754
00757
00758 int ufdCopy(FD_t sfd, FD_t tfd)
00759
00760 ;
00761
00762
00765 int ufdGetFile( FD_t sfd, FD_t tfd)
00766
00767 ;
00768
00769
00772 extern FDIO_t fdio;
00773
00776 extern FDIO_t fpio;
00777
00780 extern FDIO_t ufdio;
00781
00784 extern FDIO_t gzdio;
00785
00788 extern FDIO_t bzdio;
00789
00792 extern FDIO_t lzdio;
00793
00796 extern FDIO_t xzdio;
00797
00800 extern FDIO_t fadio;
00801
00804 static inline int xislower(int c) {
00805 return (c >= (int)'a' && c <= (int)'z');
00806 }
00807 static inline int xisupper(int c) {
00808 return (c >= (int)'A' && c <= (int)'Z');
00809 }
00810 static inline int xisalpha(int c) {
00811 return (xislower(c) || xisupper(c));
00812 }
00813 static inline int xisdigit(int c) {
00814 return (c >= (int)'0' && c <= (int)'9');
00815 }
00816 static inline int xisalnum(int c) {
00817 return (xisalpha(c) || xisdigit(c));
00818 }
00819 static inline int xisblank(int c) {
00820 return (c == (int)' ' || c == (int)'\t');
00821 }
00822 static inline int xisspace(int c) {
00823 return (xisblank(c) || c == (int)'\n' || c == (int)'\r' || c == (int)'\f' || c == (int)'\v');
00824 }
00825 static inline int xiscntrl(int c) {
00826 return (c < (int)' ');
00827 }
00828 static inline int xisascii(int c) {
00829 return ((c & 0x80) != 0x80);
00830 }
00831 static inline int xisprint(int c) {
00832 return (c >= (int)' ' && xisascii(c));
00833 }
00834 static inline int xisgraph(int c) {
00835 return (c > (int)' ' && xisascii(c));
00836 }
00837 static inline int xispunct(int c) {
00838 return (xisgraph(c) && !xisalnum(c));
00839 }
00840
00841 static inline int xtolower(int c) {
00842 return ((xisupper(c)) ? (c | ('a' - 'A')) : c);
00843 }
00844 static inline int xtoupper(int c) {
00845 return ((xislower(c)) ? (c & ~('a' - 'A')) : c);
00846 }
00847
00851 int xstrcasecmp(const char * s1, const char * s2) ;
00852
00856 int xstrncasecmp(const char *s1, const char * s2, size_t n) ;
00857
00861
00862 const char * xstrtolocale( const char *str)
00863 ;
00864
00865 #if !defined(SWIG)
00866
00871 #if defined(WITH_DMALLOC)
00872 #define _free(p) ((p) != NULL ? free((void *)(p)) : (void)0, NULL)
00873 #else
00874 static inline
00875 void * _free( const void * p)
00876
00877 {
00878 if (p != NULL) free((void *)p);
00879 return NULL;
00880 }
00881 #endif
00882 #endif
00883
00887 void rpmioClean(void)
00888
00889 ;
00890
00891 #ifdef __cplusplus
00892 }
00893 #endif
00894
00895 #endif