Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

rpmio/rpmio.h

Go to the documentation of this file.
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 /*@abstract@*/ /*@refcounted@*/ struct _FD_s * FD_t;
00038 
00041 typedef /*@observer@*/ 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 /*@only@*/ /*@null@*/ FD_t fdio_ref_function_t ( /*@only@*/ void * cookie,
00072                 const char * msg, const char * file, unsigned line);
00073 
00076 typedef /*@only@*/ /*@null@*/ FD_t fdio_deref_function_t ( /*@only@*/ FD_t fd,
00077                 const char * msg, const char * file, unsigned line);
00078 
00079 
00082 typedef /*@only@*/ /*@null@*/ 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 /*@-typeuse@*/
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 /*@=typeuse@*/
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 /*@-redecl@*/
00161 /*@observer@*/ const char * Fstrerror(/*@null@*/ FD_t fd)
00162         /*@*/;
00163 /*@=redecl@*/
00164 
00168 size_t Fread(/*@out@*/ void * buf, size_t size, size_t nmemb, FD_t fd)
00169         /*@modifies fd, *buf, fileSystem @*/;
00170 
00174 size_t Fwrite(const void * buf, size_t size, size_t nmemb, FD_t fd)
00175         /*@modifies fd, fileSystem @*/;
00176 
00180 int Fseek(FD_t fd, _libio_off_t offset, int whence)
00181         /*@modifies fileSystem @*/;
00182 
00186 int Fclose( /*@killref@*/ FD_t fd)
00187         /*@modifies fd, fileSystem @*/;
00188 
00191 /*@null@*/ FD_t Fdopen(FD_t fd, const char * fmode)
00192         /*@modifies fd, fileSystem @*/;
00193 
00197 /*@null@*/ FD_t Fopen(/*@null@*/ const char * path,
00198                         /*@null@*/ const char * fmode)
00199         /*@modifies fileSystem @*/;
00200 
00201 
00205 int Fflush(/*@null@*/ FD_t fd)
00206         /*@modifies fd, fileSystem @*/;
00207 
00211 int Ferror(/*@null@*/ FD_t fd)
00212         /*@*/;
00213 
00217 int Fileno(FD_t fd)
00218         /*@*/;
00219 
00223 int Fcntl(FD_t fd, int op, void *lip)
00224         /*@modifies fd, *lip, fileSystem @*/;
00225 
00229 ssize_t Pread(FD_t fd, void * buf, size_t count, _libio_off_t offset)
00230         /*@modifies fd, *buf, fileSystem @*/;
00231 
00235 ssize_t Pwrite(FD_t fd, const void * buf, size_t count, _libio_off_t offset)
00236         /*@modifies fd, fileSystem @*/;
00237 
00244 
00248 int Mkdir(const char * path, mode_t mode)
00249         /*@modifies fileSystem @*/;
00250 
00254 int Chdir(const char * path)
00255         /*@modifies fileSystem @*/;
00256 
00260 int Rmdir(const char * path)
00261         /*@modifies fileSystem @*/;
00262 
00266 int Rename(const char * oldpath, const char * newpath)
00267         /*@modifies fileSystem @*/;
00268 
00272 int Link(const char * oldpath, const char * newpath)
00273         /*@modifies fileSystem @*/;
00274 
00278 int Unlink(const char * path)
00279         /*@modifies fileSystem @*/;
00280 
00284 int Readlink(const char * path, /*@out@*/ char * buf, size_t bufsiz)
00285         /*@modifies *buf, fileSystem @*/;
00286 
00290 int Stat(const char * path, /*@out@*/ struct stat * st)
00291         /*@modifies *st, fileSystem @*/;
00292 
00296 int Lstat(const char * path, /*@out@*/ struct stat * st)
00297         /*@modifies *st, fileSystem @*/;
00298 
00302 int Access(const char * path, int amode)
00303         /*@modifies fileSystem @*/;
00304 
00305 
00309 int Glob(const char * pattern, int flags,
00310                 int errfunc(const char * epath, int eerrno),
00311                 /*@out@*/ glob_t * pglob)
00312         /*@modifies *pglob, fileSystem @*/;
00313 
00317 void Globfree( /*@only@*/ glob_t * pglob)
00318         /*@modifies *pglob, fileSystem @*/;
00319 
00320 
00324 /*@null@*/ DIR * Opendir(const char * name)
00325         /*@modifies fileSystem @*/;
00326 
00330 /*@null@*/ struct dirent * Readdir(DIR * dir)
00331         /*@modifies *dir, fileSystem @*/;
00332 
00336 int     Closedir(/*@only@*/ DIR * dir)
00337         /*@modifies *dir, fileSystem @*/;
00338 
00346 
00349 off_t   fdSize(FD_t fd)
00350         /*@modifies fd, fileSystem@*/;
00351 
00354 /*@null@*/ FD_t fdDup(int fdno)
00355         /*@modifies fileSystem@*/;
00356 
00357 #ifdef UNUSED
00358 /*@null@*/ FILE *fdFdopen( /*@only@*/ void * cookie, const char * mode);
00359 #endif
00360 
00361 /* XXX Legacy interfaces needed by gnorpm, rpmfind et al */
00362 
00363 /*@-exportlocal@*/
00366 /*@unused@*/ int fdFileno(void * cookie)
00367         /*@*/;
00368 #define fdFileno(_fd)           fdio->_fileno(_fd)
00369 
00372 /*@null@*/ FD_t fdOpen(const char *path, int flags, mode_t mode)
00373         /*@modifies fileSystem @*/;
00374 #define fdOpen(_path, _flags, _mode)    fdio->_open((_path), (_flags), (_mode))
00375 
00378 ssize_t fdRead(void * cookie, /*@out@*/ char * buf, size_t count)
00379         /*@modifies *cookie, *buf, fileSystem @*/;
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         /*@modifies *cookie, fileSystem @*/;
00386 #define fdWrite(_fd, _buf, _count)      fdio->write((_fd), (_buf), (_count))
00387 
00390 int fdClose( /*@only@*/ void * cookie)
00391         /*@modifies *cookie, fileSystem @*/;
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         /*@modifies fd @*/;
00406 
00409 int fdReadable(FD_t fd, int secs)
00410         /*@modifies fd @*/;
00411 /*@=exportlocal@*/
00412 
00416 /*@-typeuse@*/
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 /*@=typeuse@*/
00432 
00435 /*@-redecl@*/
00436 /*@observer@*/ const char *const ftpStrerror(int errorNumber)   /*@*/;
00437 /*@=redecl@*/
00438 
00441 /*@unused@*/
00442 /*@dependent@*/ /*@null@*/ void * ufdGetUrlinfo(FD_t fd)
00443         /*@modifies fd @*/;
00444 
00447 /*@-redecl@*/
00448 /*@unused@*/
00449 /*@observer@*/ const char * urlStrerror(const char * url)       /*@*/;
00450 /*@=redecl@*/
00451 
00454 /*@-exportlocal@*/
00455 int ufdCopy(FD_t sfd, FD_t tfd)
00456         /*@modifies sfd, tfd, fileSystem @*/;
00457 /*@=exportlocal@*/
00458 
00461 int ufdGetFile( /*@killref@*/ FD_t sfd, FD_t tfd)
00462         /*@modifies sfd, tfd, fileSystem @*/;
00463 
00466 /*@unused@*/ int timedRead(FD_t fd, /*@out@*/ void * bufptr, int length)
00467         /*@modifies fd, *bufptr, fileSystem @*/;
00468 #define timedRead       ufdio->read
00469 
00470 
00471 /*@-exportlocal@*/
00474 /*@observer@*/ extern FDIO_t fdio;
00475 
00478 /*@observer@*/ extern FDIO_t fpio;
00479 
00482 /*@observer@*/ extern FDIO_t ufdio;
00483 
00486 /*@observer@*/ extern FDIO_t gzdio;
00487 
00490 /*@observer@*/ extern FDIO_t bzdio;
00491 
00494 /*@observer@*/ extern FDIO_t fadio;
00495 /*@=exportlocal@*/
00498 /*@unused@*/ static inline int xislower(int c) /*@*/ {
00499     return (c >= 'a' && c <= 'z');
00500 }
00501 /*@unused@*/ static inline int xisupper(int c) /*@*/ {
00502     return (c >= 'A' && c <= 'Z');
00503 }
00504 /*@unused@*/ static inline int xisalpha(int c) /*@*/ {
00505     return (xislower(c) || xisupper(c));
00506 }
00507 /*@unused@*/ static inline int xisdigit(int c) /*@*/ {
00508     return (c >= '0' && c <= '9');
00509 }
00510 /*@unused@*/ static inline int xisalnum(int c) /*@*/ {
00511     return (xisalpha(c) || xisdigit(c));
00512 }
00513 /*@unused@*/ static inline int xisblank(int c) /*@*/ {
00514     return (c == ' ' || c == '\t');
00515 }
00516 /*@unused@*/ static inline int xisspace(int c) /*@*/ {
00517     return (xisblank(c) || c == '\n' || c == '\r' || c == '\f' || c == '\v');
00518 }
00519 
00520 /*@unused@*/ static inline int xtolower(int c) /*@*/ {
00521     return ((xisupper(c)) ? (c | ('a' - 'A')) : c);
00522 }
00523 /*@unused@*/ 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  /* H_RPMIO */

Generated on Wed Mar 13 15:34:51 2002 for rpm by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002