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
00021 #ifdef NOTYET
00022 typedef struct pgpDig_s * pgpDig;
00023 #endif
00024
00033 #if !defined(__LCLINT__) && defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ == 2
00034 #define USE_COOKIE_SEEK_POINTER 1
00035 typedef _IO_off64_t _libio_off_t;
00036 typedef _libio_off_t * _libio_pos_t;
00037 #else
00038 typedef off_t _libio_off_t;
00039 typedef off_t _libio_pos_t;
00040 #endif
00041
00045 typedef struct _FD_s * FD_t;
00046
00049 typedef struct FDIO_s * FDIO_t;
00050
00051 #ifdef __cplusplus
00052 extern "C" {
00053 #endif
00054
00059
00062 typedef ssize_t (*fdio_read_function_t) (void *cookie, char *buf, size_t nbytes)
00063
00064 ;
00065
00068 typedef ssize_t (*fdio_write_function_t) (void *cookie, const char *buf, size_t nbytes)
00069
00070 ;
00071
00074 typedef int (*fdio_seek_function_t) (void *cookie, _libio_pos_t pos, int whence)
00075
00076 ;
00077
00080 typedef int (*fdio_close_function_t) (void *cookie)
00081
00082 ;
00083
00084
00087 typedef FD_t (*fdio_ref_function_t) ( void * cookie,
00088 const char * msg, const char * file, unsigned line)
00089
00090 ;
00091
00094 typedef FD_t (*fdio_deref_function_t) ( FD_t fd,
00095 const char * msg, const char * file, unsigned line)
00096
00097 ;
00098
00099
00102 typedef FD_t (*fdio_new_function_t) (const char * msg,
00103 const char * file, unsigned line)
00104
00105 ;
00106
00107
00110 typedef int (*fdio_fileno_function_t) (void * cookie)
00111
00112 ;
00113
00114
00117 typedef FD_t (*fdio_open_function_t) (const char * path, int flags, mode_t mode)
00118
00119 ;
00120
00123 typedef FD_t (*fdio_fopen_function_t) (const char * path, const char * fmode)
00124
00125 ;
00126
00129 typedef void * (*fdio_ffileno_function_t) (FD_t fd)
00130
00131 ;
00132
00135 typedef int (*fdio_fflush_function_t) (FD_t fd)
00136
00137 ;
00145
00148 typedef int (*fdio_mkdir_function_t) (const char * path, mode_t mode)
00149
00150 ;
00151
00154 typedef int (*fdio_chdir_function_t) (const char * path)
00155
00156 ;
00157
00160 typedef int (*fdio_rmdir_function_t) (const char * path)
00161
00162 ;
00163
00166 typedef int (*fdio_rename_function_t) (const char * oldpath, const char * newpath)
00167
00168 ;
00169
00172 typedef int (*fdio_unlink_function_t) (const char * path)
00173
00174 ;
00175
00176
00179 typedef int (*fdio_stat_function_t) (const char * path, struct stat * st)
00180
00181 ;
00182
00185 typedef int (*fdio_lstat_function_t) (const char * path, struct stat * st)
00186
00187 ;
00188
00191 typedef int (*fdio_access_function_t) (const char * path, int amode)
00192
00193 ;
00194
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
00233 const char * Fstrerror( FD_t fd)
00234 ;
00235
00236
00240 size_t Fread( void * buf, size_t size, size_t nmemb, FD_t fd)
00241
00242 ;
00243
00247 size_t Fwrite(const void * buf, size_t size, size_t nmemb, FD_t fd)
00248
00249 ;
00250
00254 int Fseek(FD_t fd, _libio_off_t offset, int whence)
00255
00256 ;
00257
00261 int Fclose( FD_t fd)
00262
00263 ;
00264
00267 FD_t Fdopen(FD_t ofd, const char * fmode)
00268
00269 ;
00270
00274 FD_t Fopen( const char * path,
00275 const char * fmode)
00276
00277 ;
00278
00279
00283 int Fflush( FD_t fd)
00284
00285 ;
00286
00290 int Ferror( FD_t fd)
00291 ;
00292
00296 int Fileno(FD_t fd)
00297
00298 ;
00299
00303 int Fcntl(FD_t fd, int op, void *lip)
00304
00305 ;
00306
00313
00317 int Mkdir(const char * path, mode_t mode)
00318
00319 ;
00320
00324 int Chdir(const char * path)
00325
00326 ;
00327
00331 int Rmdir(const char * path)
00332
00333 ;
00334
00338 int Rename(const char * oldpath, const char * newpath)
00339
00340 ;
00341
00345 int Link(const char * oldpath, const char * newpath)
00346
00347 ;
00348
00352 int Unlink(const char * path)
00353
00354 ;
00355
00359 int Readlink(const char * path, char * buf, size_t bufsiz)
00360
00361 ;
00362
00366 int Stat(const char * path, struct stat * st)
00367
00368 ;
00369
00373 int Lstat(const char * path, struct stat * st)
00374
00375 ;
00376
00380 int Access(const char * path, int amode)
00381
00382 ;
00383
00384
00388 int Glob(const char * pattern, int flags,
00389 int errfunc(const char * epath, int eerrno),
00390 glob_t * pglob)
00391
00392 ;
00393
00397 void Globfree( glob_t * pglob)
00398
00399 ;
00400
00401
00405
00406 DIR * Opendir(const char * path)
00407
00408 ;
00409
00413 struct dirent * Readdir(DIR * dir)
00414
00415 ;
00416
00420 int Closedir( DIR * dir)
00421
00422 ;
00423
00431
00434 off_t fdSize(FD_t fd)
00435
00436 ;
00437
00440 FD_t fdDup(int fdno)
00441
00442 ;
00443
00444 #ifdef UNUSED
00445 FILE *fdFdopen( void * cookie, const char * mode);
00446 #endif
00447
00448
00449
00450
00453 #ifndef H_RPMIO_INTERNAL
00454 int fdFileno(void * cookie)
00455 ;
00456 #define fdFileno(_fd) fdio->_fileno(_fd)
00457 #endif
00458
00461 FD_t fdOpen(const char *path, int flags, mode_t mode)
00462
00463 ;
00464 #define fdOpen(_path, _flags, _mode) fdio->_open((_path), (_flags), (_mode))
00465
00468 ssize_t fdRead(void * cookie, char * buf, size_t count)
00469
00470 ;
00471 #define fdRead(_fd, _buf, _count) fdio->read((_fd), (_buf), (_count))
00472
00475 ssize_t fdWrite(void * cookie, const char * buf, size_t count)
00476
00477 ;
00478 #define fdWrite(_fd, _buf, _count) fdio->write((_fd), (_buf), (_count))
00479
00482 int fdClose( void * cookie)
00483
00484 ;
00485 #define fdCLose(_fd) fdio->close(_fd)
00486
00489
00490
00491 FD_t fdLink ( void * cookie, const char * msg)
00492
00493 ;
00494 #define fdLink(_fd, _msg) fdio->_fdref(_fd, _msg, __FILE__, __LINE__)
00495
00498
00499
00500 FD_t fdFree( FD_t fd, const char * msg)
00501
00502 ;
00503 #define fdFree(_fd, _msg) fdio->_fdderef(_fd, _msg, __FILE__, __LINE__)
00504
00507
00508
00509 FD_t fdNew (const char * msg)
00510
00511 ;
00512 #define fdNew(_msg) fdio->_fdnew(_msg, __FILE__, __LINE__)
00513
00516 int fdWritable(FD_t fd, int secs)
00517
00518 ;
00519
00522 int fdReadable(FD_t fd, int secs)
00523
00524 ;
00525
00526
00530
00531 typedef enum ftperrCode_e {
00532 FTPERR_BAD_SERVER_RESPONSE = -1,
00533 FTPERR_SERVER_IO_ERROR = -2,
00534 FTPERR_SERVER_TIMEOUT = -3,
00535 FTPERR_BAD_HOST_ADDR = -4,
00536 FTPERR_BAD_HOSTNAME = -5,
00537 FTPERR_FAILED_CONNECT = -6,
00538 FTPERR_FILE_IO_ERROR = -7,
00539 FTPERR_PASSIVE_ERROR = -8,
00540 FTPERR_FAILED_DATA_CONNECT = -9,
00541 FTPERR_FILE_NOT_FOUND = -10,
00542 FTPERR_NIC_ABORT_IN_PROGRESS= -11,
00543 FTPERR_UNKNOWN = -100
00544 } ftperrCode;
00545
00546
00549
00550 const char *const ftpStrerror(int errorNumber) ;
00551
00552
00555
00556 void * ufdGetUrlinfo(FD_t fd)
00557 ;
00558
00561
00562
00563 const char * urlStrerror(const char * url) ;
00564
00565
00568
00569 int ufdCopy(FD_t sfd, FD_t tfd)
00570
00571 ;
00572
00573
00576 int ufdGetFile( FD_t sfd, FD_t tfd)
00577
00578 ;
00579
00582 int timedRead(FD_t fd, void * bufptr, int length)
00583
00584 ;
00585 #define timedRead ufdio->read
00586
00587
00590 extern FDIO_t fdio;
00591
00594 extern FDIO_t fpio;
00595
00598 extern FDIO_t ufdio;
00599
00602 extern FDIO_t gzdio;
00603
00606 extern FDIO_t bzdio;
00607
00610 extern FDIO_t fadio;
00611
00614 static inline int xislower(int c) {
00615 return (c >= 'a' && c <= 'z');
00616 }
00617 static inline int xisupper(int c) {
00618 return (c >= 'A' && c <= 'Z');
00619 }
00620 static inline int xisalpha(int c) {
00621 return (xislower(c) || xisupper(c));
00622 }
00623 static inline int xisdigit(int c) {
00624 return (c >= '0' && c <= '9');
00625 }
00626 static inline int xisalnum(int c) {
00627 return (xisalpha(c) || xisdigit(c));
00628 }
00629 static inline int xisblank(int c) {
00630 return (c == ' ' || c == '\t');
00631 }
00632 static inline int xisspace(int c) {
00633 return (xisblank(c) || c == '\n' || c == '\r' || c == '\f' || c == '\v');
00634 }
00635
00636 static inline int xtolower(int c) {
00637 return ((xisupper(c)) ? (c | ('a' - 'A')) : c);
00638 }
00639 static inline int xtoupper(int c) {
00640 return ((xislower(c)) ? (c & ~('a' - 'A')) : c);
00641 }
00642
00646 int xstrcasecmp(const char * s1, const char * s2) ;
00647
00651 int xstrncasecmp(const char *s1, const char * s2, size_t n) ;
00652
00653 #ifdef __cplusplus
00654 }
00655 #endif
00656
00657 #endif