00001 #ifndef H_RPMIO
00002 #define H_RPMIO
00003
00009 #include <sys/types.h>
00010 #include <sys/stat.h>
00011 #include <dirent.h>
00012 #include <glob.h>
00013 #include <stdio.h>
00014 #include <stdlib.h>
00015 #include <unistd.h>
00016
00025 #if !defined(__LCLINT__) && defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ == 2
00026 #define USE_COOKIE_SEEK_POINTER 1
00027 typedef _IO_off64_t _libio_off_t;
00028 typedef _libio_off_t * _libio_pos_t;
00029 #else
00030 typedef off_t _libio_off_t;
00031 typedef off_t _libio_pos_t;
00032 #endif
00033
00037 typedef struct _FD_s * FD_t;
00038
00041 typedef struct FDIO_s * FDIO_t;
00042
00043 #ifdef __cplusplus
00044 extern "C" {
00045 #endif
00046
00051
00054 typedef ssize_t fdio_read_function_t (void *cookie, char *buf, size_t nbytes);
00055
00058 typedef ssize_t fdio_write_function_t (void *cookie, const char *buf, size_t nbytes);
00059
00062 typedef int fdio_seek_function_t (void *cookie, _libio_pos_t pos, int whence);
00063
00066 typedef int fdio_close_function_t (void *cookie);
00067
00068
00071 typedef FD_t fdio_ref_function_t ( void * cookie,
00072 const char * msg, const char * file, unsigned line);
00073
00076 typedef FD_t fdio_deref_function_t ( FD_t fd,
00077 const char * msg, const char * file, unsigned line);
00078
00079
00082 typedef FD_t fdio_new_function_t (const char * msg,
00083 const char * file, unsigned line);
00084
00085
00088 typedef int fdio_fileno_function_t (void * cookie);
00089
00090
00093 typedef FD_t fdio_open_function_t (const char * path, int flags, mode_t mode);
00094
00097 typedef FD_t fdio_fopen_function_t (const char * path, const char * fmode);
00098
00101 typedef void * fdio_ffileno_function_t (FD_t fd);
00102
00105 typedef int fdio_fflush_function_t (FD_t fd);
00113 typedef int fdio_mkdir_function_t (const char * path, mode_t mode);
00114 typedef int fdio_chdir_function_t (const char * path);
00115 typedef int fdio_rmdir_function_t (const char * path);
00116 typedef int fdio_rename_function_t (const char * oldpath, const char * newpath);
00117 typedef int fdio_unlink_function_t (const char * path);
00118
00119 typedef int fdio_stat_function_t (const char * path, struct stat * st);
00120 typedef int fdio_lstat_function_t (const char * path, struct stat * st);
00121 typedef int fdio_access_function_t (const char * path, int amode);
00122
00128 struct FDIO_s {
00129 fdio_read_function_t * read;
00130 fdio_write_function_t * write;
00131 fdio_seek_function_t * seek;
00132 fdio_close_function_t * close;
00133
00134 fdio_ref_function_t * _fdref;
00135 fdio_deref_function_t * _fdderef;
00136 fdio_new_function_t * _fdnew;
00137 fdio_fileno_function_t * _fileno;
00138
00139 fdio_open_function_t * _open;
00140 fdio_fopen_function_t * _fopen;
00141 fdio_ffileno_function_t * _ffileno;
00142 fdio_fflush_function_t * _fflush;
00143
00144 fdio_mkdir_function_t * _mkdir;
00145 fdio_chdir_function_t * _chdir;
00146 fdio_rmdir_function_t * _rmdir;
00147 fdio_rename_function_t * _rename;
00148 fdio_unlink_function_t * _unlink;
00149 };
00150
00151
00156
00160
00161 const char * Fstrerror( FD_t fd)
00162 ;
00163
00164
00168 size_t Fread( void * buf, size_t size, size_t nmemb, FD_t fd)
00169 ;
00170
00174 size_t Fwrite(const void * buf, size_t size, size_t nmemb, FD_t fd)
00175 ;
00176
00180 int Fseek(FD_t fd, _libio_off_t offset, int whence)
00181 ;
00182
00186 int Fclose( FD_t fd)
00187 ;
00188
00191 FD_t Fdopen(FD_t fd, const char * fmode)
00192 ;
00193
00197 FD_t Fopen( const char * path,
00198 const char * fmode)
00199 ;
00200
00201
00205 int Fflush( FD_t fd)
00206 ;
00207
00211 int Ferror( FD_t fd)
00212 ;
00213
00217 int Fileno(FD_t fd)
00218 ;
00219
00223 int Fcntl(FD_t fd, int op, void *lip)
00224 ;
00225
00229 ssize_t Pread(FD_t fd, void * buf, size_t count, _libio_off_t offset)
00230 ;
00231
00235 ssize_t Pwrite(FD_t fd, const void * buf, size_t count, _libio_off_t offset)
00236 ;
00237
00244
00248 int Mkdir(const char * path, mode_t mode)
00249 ;
00250
00254 int Chdir(const char * path)
00255 ;
00256
00260 int Rmdir(const char * path)
00261 ;
00262
00266 int Rename(const char * oldpath, const char * newpath)
00267 ;
00268
00272 int Link(const char * oldpath, const char * newpath)
00273 ;
00274
00278 int Unlink(const char * path)
00279 ;
00280
00284 int Readlink(const char * path, char * buf, size_t bufsiz)
00285 ;
00286
00290 int Stat(const char * path, struct stat * st)
00291 ;
00292
00296 int Lstat(const char * path, struct stat * st)
00297 ;
00298
00302 int Access(const char * path, int amode)
00303 ;
00304
00305
00309 int Glob(const char * pattern, int flags,
00310 int errfunc(const char * epath, int eerrno),
00311 glob_t * pglob)
00312 ;
00313
00317 void Globfree( glob_t * pglob)
00318 ;
00319
00320
00324 DIR * Opendir(const char * name)
00325 ;
00326
00330 struct dirent * Readdir(DIR * dir)
00331 ;
00332
00336 int Closedir( DIR * dir)
00337 ;
00338
00346
00349 off_t fdSize(FD_t fd)
00350 ;
00351
00354 FD_t fdDup(int fdno)
00355 ;
00356
00357 #ifdef UNUSED
00358 FILE *fdFdopen( void * cookie, const char * mode);
00359 #endif
00360
00361
00362
00363
00366 int fdFileno(void * cookie)
00367 ;
00368 #define fdFileno(_fd) fdio->_fileno(_fd)
00369
00372 FD_t fdOpen(const char *path, int flags, mode_t mode)
00373 ;
00374 #define fdOpen(_path, _flags, _mode) fdio->_open((_path), (_flags), (_mode))
00375
00378 ssize_t fdRead(void * cookie, char * buf, size_t count)
00379 ;
00380 #define fdRead(_fd, _buf, _count) fdio->read((_fd), (_buf), (_count))
00381
00384 ssize_t fdWrite(void * cookie, const char * buf, size_t count)
00385 ;
00386 #define fdWrite(_fd, _buf, _count) fdio->write((_fd), (_buf), (_count))
00387
00390 int fdClose( void * cookie)
00391 ;
00392 #define fdCLose(_fd) fdio->close(_fd)
00393
00398 #define fdLink(_fd, _msg) fdio->_fdref(_fd, _msg, __FILE__, __LINE__)
00399 #define fdFree(_fd, _msg) fdio->_fdderef(_fd, _msg, __FILE__, __LINE__)
00400 #define fdNew(_msg) fdio->_fdnew(_msg, __FILE__, __LINE__)
00401
00404 int fdWritable(FD_t fd, int secs)
00405 ;
00406
00409 int fdReadable(FD_t fd, int secs)
00410 ;
00411
00412
00416
00417 typedef enum ftperrCode_e {
00418 FTPERR_BAD_SERVER_RESPONSE = -1,
00419 FTPERR_SERVER_IO_ERROR = -2,
00420 FTPERR_SERVER_TIMEOUT = -3,
00421 FTPERR_BAD_HOST_ADDR = -4,
00422 FTPERR_BAD_HOSTNAME = -5,
00423 FTPERR_FAILED_CONNECT = -6,
00424 FTPERR_FILE_IO_ERROR = -7,
00425 FTPERR_PASSIVE_ERROR = -8,
00426 FTPERR_FAILED_DATA_CONNECT = -9,
00427 FTPERR_FILE_NOT_FOUND = -10,
00428 FTPERR_NIC_ABORT_IN_PROGRESS= -11,
00429 FTPERR_UNKNOWN = -100
00430 } ftperrCode;
00431
00432
00435
00436 const char *const ftpStrerror(int errorNumber) ;
00437
00438
00441
00442 void * ufdGetUrlinfo(FD_t fd)
00443 ;
00444
00447
00448
00449 const char * urlStrerror(const char * url) ;
00450
00451
00454
00455 int ufdCopy(FD_t sfd, FD_t tfd)
00456 ;
00457
00458
00461 int ufdGetFile( FD_t sfd, FD_t tfd)
00462 ;
00463
00466 int timedRead(FD_t fd, void * bufptr, int length)
00467 ;
00468 #define timedRead ufdio->read
00469
00470
00471
00474 extern FDIO_t fdio;
00475
00478 extern FDIO_t fpio;
00479
00482 extern FDIO_t ufdio;
00483
00486 extern FDIO_t gzdio;
00487
00490 extern FDIO_t bzdio;
00491
00494 extern FDIO_t fadio;
00495
00498 static inline int xislower(int c) {
00499 return (c >= 'a' && c <= 'z');
00500 }
00501 static inline int xisupper(int c) {
00502 return (c >= 'A' && c <= 'Z');
00503 }
00504 static inline int xisalpha(int c) {
00505 return (xislower(c) || xisupper(c));
00506 }
00507 static inline int xisdigit(int c) {
00508 return (c >= '0' && c <= '9');
00509 }
00510 static inline int xisalnum(int c) {
00511 return (xisalpha(c) || xisdigit(c));
00512 }
00513 static inline int xisblank(int c) {
00514 return (c == ' ' || c == '\t');
00515 }
00516 static inline int xisspace(int c) {
00517 return (xisblank(c) || c == '\n' || c == '\r' || c == '\f' || c == '\v');
00518 }
00519
00520 static inline int xtolower(int c) {
00521 return ((xisupper(c)) ? (c | ('a' - 'A')) : c);
00522 }
00523 static inline int xtoupper(int c) {
00524 return ((xislower(c)) ? (c & ~('a' - 'A')) : c);
00525 }
00526
00530 int xstrcasecmp(const char * s1, const char * s2) ;
00531
00535 int xstrncasecmp(const char *s1, const char * s2, size_t n) ;
00536
00537 #ifdef __cplusplus
00538 }
00539 #endif
00540
00541 #endif