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 typedef int fdio_stat_function_t (const char * path, struct stat * st);
00119 typedef int fdio_lstat_function_t (const char * path, struct stat * st);
00120 typedef int fdio_access_function_t (const char * path, int amode);
00126 struct FDIO_s {
00127 fdio_read_function_t * read;
00128 fdio_write_function_t * write;
00129 fdio_seek_function_t * seek;
00130 fdio_close_function_t * close;
00131
00132 fdio_ref_function_t * _fdref;
00133 fdio_deref_function_t * _fdderef;
00134 fdio_new_function_t * _fdnew;
00135 fdio_fileno_function_t * _fileno;
00136
00137 fdio_open_function_t * _open;
00138 fdio_fopen_function_t * _fopen;
00139 fdio_ffileno_function_t * _ffileno;
00140 fdio_fflush_function_t * _fflush;
00141
00142 fdio_mkdir_function_t * _mkdir;
00143 fdio_chdir_function_t * _chdir;
00144 fdio_rmdir_function_t * _rmdir;
00145 fdio_rename_function_t * _rename;
00146 fdio_unlink_function_t * _unlink;
00147 };
00148
00149
00154
00158 const char * Fstrerror(FD_t fd);
00159
00163 size_t Fread ( void * buf, size_t size, size_t nmemb, FD_t fd);
00164
00168 size_t Fwrite (const void *buf, size_t size, size_t nmemb, FD_t fd);
00169
00170
00174 int Fseek (FD_t fd, _libio_off_t offset, int whence);
00175
00179 int Fclose ( FD_t fd);
00180
00183 FD_t Fdopen (FD_t fd, const char * fmode);
00184
00188 FD_t Fopen (const char * path, const char * fmode);
00189
00190
00194 int Fflush (FD_t fd);
00195
00199 int Ferror (FD_t fd);
00200
00204 int Fileno (FD_t fd);
00205
00206
00210 int Fcntl (FD_t fd, int op, void *lip);
00211
00215 ssize_t Pread(FD_t fd, void * buf, size_t count, _libio_off_t offset);
00216
00220 ssize_t Pwrite(FD_t fd, const void * buf, size_t count, _libio_off_t offset);
00227
00231 int Mkdir (const char * path, mode_t mode);
00232
00236 int Chdir (const char * path);
00237
00241 int Rmdir (const char * path);
00242
00246 int Rename (const char * oldpath, const char * newpath);
00247
00251 int Link (const char * oldpath, const char * newpath);
00252
00256 int Unlink (const char * path);
00257
00261 int Readlink(const char * path, char * buf, size_t bufsiz);
00262
00263
00267 int Stat (const char * path, struct stat * st);
00268
00272 int Lstat (const char * path, struct stat * st);
00273
00277 int Access (const char * path, int amode);
00278
00279
00283 int Glob (const char * pattern, int flags,
00284 int errfunc(const char * epath, int eerrno), glob_t * pglob);
00285
00289 void Globfree( glob_t * pglob);
00290
00291
00295 DIR * Opendir (const char * name);
00296
00300 struct dirent * Readdir (DIR * dir);
00301
00305 int Closedir(DIR * dir);
00313
00316 off_t fdSize (FD_t fd);
00317
00320 FD_t fdDup(int fdno);
00321 #ifdef UNUSED
00322 FILE *fdFdopen( void * cookie, const char * mode);
00323 #endif
00324
00325
00326
00329
00330 int fdFileno(void * cookie);
00331
00332
00333
00336 FD_t fdOpen(const char *path, int flags, mode_t mode);
00337
00340 ssize_t fdRead(void * cookie, char * buf, size_t count);
00341
00344 ssize_t fdWrite(void * cookie, const char * buf, size_t count);
00345
00348 int fdClose( void * cookie);
00349
00350
00351 #define fdLink(_fd, _msg) fdio->_fdref(_fd, _msg, __FILE__, __LINE__)
00352 #define fdFree(_fd, _msg) fdio->_fdderef(_fd, _msg, __FILE__, __LINE__)
00353 #define fdNew(_msg) fdio->_fdnew(_msg, __FILE__, __LINE__)
00354
00355
00358 int fdWritable(FD_t fd, int secs);
00359
00362 int fdReadable(FD_t fd, int secs);
00363
00367 typedef enum ftperrCode_e {
00368 FTPERR_BAD_SERVER_RESPONSE = -1,
00369 FTPERR_SERVER_IO_ERROR = -2,
00370 FTPERR_SERVER_TIMEOUT = -3,
00371 FTPERR_BAD_HOST_ADDR = -4,
00372 FTPERR_BAD_HOSTNAME = -5,
00373 FTPERR_FAILED_CONNECT = -6,
00374 FTPERR_FILE_IO_ERROR = -7,
00375 FTPERR_PASSIVE_ERROR = -8,
00376 FTPERR_FAILED_DATA_CONNECT = -9,
00377 FTPERR_FILE_NOT_FOUND = -10,
00378 FTPERR_NIC_ABORT_IN_PROGRESS= -11,
00379 FTPERR_UNKNOWN = -100
00380 } ftperrCode;
00381
00384 const char *const ftpStrerror(int errorNumber);
00385
00388 void * ufdGetUrlinfo(FD_t fd);
00389
00392 const char * urlStrerror(const char * url);
00393
00396 int ufdCopy(FD_t sfd, FD_t tfd);
00397
00400 int ufdGetFile( FD_t sfd, FD_t tfd);
00401
00404 int timedRead(FD_t fd, void * bufptr, int length);
00405 #define timedRead ufdio->read
00406
00407
00410 extern FDIO_t fdio;
00411
00414 extern FDIO_t fpio;
00415
00418 extern FDIO_t ufdio;
00419
00422 extern FDIO_t gzdio;
00423
00426 extern FDIO_t bzdio;
00427
00430 extern FDIO_t fadio;
00436 int xstrcasecmp(const char *s1, const char * s2) ;
00437
00441 int xstrncasecmp(const char *s1, const char * s2, size_t n) ;
00442
00443 #ifdef __cplusplus
00444 }
00445 #endif
00446
00447 #endif