source: trunk/third/rpm/rpmio/rpmio.h @ 17931

Revision 17931, 13.6 KB checked in by ghudson, 23 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r17930, which included commits to RCS files with non-trunk default branches.
Line 
1#ifndef H_RPMIO
2#define H_RPMIO
3
4/** \ingroup rpmio
5 * \file rpmio/rpmio.h
6 *
7 */
8
9#include <sys/types.h>
10#include <sys/stat.h>
11#include <dirent.h>
12/*@-noparams@*/
13#include <glob.h>
14/*@=noparams@*/
15#include <stdio.h>
16#include <stdlib.h>
17#include <unistd.h>
18
19/**
20 */
21#ifdef  NOTYET
22typedef /*@abstract@*/ struct pgpDig_s * pgpDig;
23#endif
24
25/** \ingroup rpmio
26 * Hide libio API lossage.
27 * The libio interface changed after glibc-2.1.3 to pass the seek offset
28 * argument as a pointer rather than as an off_t. The snarl below defines
29 * typedefs to isolate the lossage.
30 * API unchanged.
31 */
32/*@{*/
33#if !defined(__LCLINT__) && defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ == 2
34#define USE_COOKIE_SEEK_POINTER 1
35typedef _IO_off64_t     _libio_off_t;
36typedef _libio_off_t *  _libio_pos_t;
37#else
38typedef off_t           _libio_off_t;
39typedef off_t           _libio_pos_t;
40#endif
41/*@}*/
42
43/** \ingroup rpmio
44 */
45typedef /*@abstract@*/ /*@refcounted@*/ struct _FD_s * FD_t;
46
47/** \ingroup rpmio
48 */
49typedef /*@observer@*/ struct FDIO_s * FDIO_t;
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
55/** \ingroup rpmio
56 * \name RPMIO Vectors.
57 */
58/*@{*/
59
60/**
61 */
62typedef ssize_t (*fdio_read_function_t) (void *cookie, char *buf, size_t nbytes)
63        /*@globals fileSystem @*/
64        /*@modifies *cookie, fileSystem @*/;
65
66/**
67 */
68typedef ssize_t (*fdio_write_function_t) (void *cookie, const char *buf, size_t nbytes)
69        /*@globals fileSystem @*/
70        /*@modifies *cookie, fileSystem @*/;
71
72/**
73 */
74typedef int (*fdio_seek_function_t) (void *cookie, _libio_pos_t pos, int whence)
75        /*@globals fileSystem @*/
76        /*@modifies *cookie, fileSystem @*/;
77
78/**
79 */
80typedef int (*fdio_close_function_t) (void *cookie)
81        /*@globals fileSystem @*/
82        /*@modifies *cookie, fileSystem @*/;
83
84
85/**
86 */
87typedef /*@only@*/ /*@null@*/ FD_t (*fdio_ref_function_t) ( /*@only@*/ void * cookie,
88                const char * msg, const char * file, unsigned line)
89        /*@globals fileSystem @*/
90        /*@modifies fileSystem @*/;
91
92/**
93 */
94typedef /*@only@*/ /*@null@*/ FD_t (*fdio_deref_function_t) ( /*@only@*/ FD_t fd,
95                const char * msg, const char * file, unsigned line)
96        /*@globals fileSystem @*/
97        /*@modifies fd, fileSystem @*/;
98
99
100/**
101 */
102typedef /*@only@*/ /*@null@*/ FD_t (*fdio_new_function_t) (const char * msg,
103                const char * file, unsigned line)
104        /*@globals fileSystem @*/
105        /*@modifies fileSystem @*/;
106
107
108/**
109 */
110typedef int (*fdio_fileno_function_t) (void * cookie)
111        /*@globals fileSystem @*/
112        /*@modifies *cookie, fileSystem @*/;
113
114
115/**
116 */
117typedef FD_t (*fdio_open_function_t) (const char * path, int flags, mode_t mode)
118        /*@globals fileSystem @*/
119        /*@modifies fileSystem @*/;
120
121/**
122 */
123typedef FD_t (*fdio_fopen_function_t) (const char * path, const char * fmode)
124        /*@globals fileSystem @*/
125        /*@modifies fileSystem @*/;
126
127/**
128 */
129typedef void * (*fdio_ffileno_function_t) (FD_t fd)
130        /*@globals fileSystem @*/
131        /*@modifies fileSystem @*/;
132
133/**
134 */
135typedef int (*fdio_fflush_function_t) (FD_t fd)
136        /*@globals fileSystem @*/
137        /*@modifies fileSystem @*/;
138/*@}*/
139
140
141/** \ingroup rpmrpc
142 * \name RPMRPC Vectors.
143 */
144/*@{*/
145
146/**
147 */
148typedef int (*fdio_mkdir_function_t) (const char * path, mode_t mode)
149        /*@globals fileSystem @*/
150        /*@modifies fileSystem @*/;
151
152/**
153 */
154typedef int (*fdio_chdir_function_t) (const char * path)
155        /*@globals fileSystem @*/
156        /*@modifies fileSystem @*/;
157
158/**
159 */
160typedef int (*fdio_rmdir_function_t) (const char * path)
161        /*@globals fileSystem @*/
162        /*@modifies fileSystem @*/;
163
164/**
165 */
166typedef int (*fdio_rename_function_t) (const char * oldpath, const char * newpath)
167        /*@globals fileSystem @*/
168        /*@modifies fileSystem @*/;
169
170/**
171 */
172typedef int (*fdio_unlink_function_t) (const char * path)
173        /*@globals fileSystem @*/
174        /*@modifies fileSystem @*/;
175/*@-typeuse@*/
176
177/**
178 */
179typedef int (*fdio_stat_function_t) (const char * path, /*@out@*/ struct stat * st)
180        /*@globals fileSystem @*/
181        /*@modifies *st, fileSystem @*/;
182
183/**
184 */
185typedef int (*fdio_lstat_function_t) (const char * path, /*@out@*/ struct stat * st)
186        /*@globals fileSystem @*/
187        /*@modifies *st, fileSystem @*/;
188
189/**
190 */
191typedef int (*fdio_access_function_t) (const char * path, int amode)
192        /*@globals fileSystem @*/
193        /*@modifies fileSystem @*/;
194/*@=typeuse@*/
195/*@}*/
196
197
198/** \ingroup rpmio
199 */
200struct FDIO_s {
201  fdio_read_function_t          read;
202  fdio_write_function_t         write;
203  fdio_seek_function_t          seek;
204  fdio_close_function_t         close;
205
206  fdio_ref_function_t           _fdref;
207  fdio_deref_function_t         _fdderef;
208  fdio_new_function_t           _fdnew;
209  fdio_fileno_function_t        _fileno;
210
211  fdio_open_function_t          _open;
212  fdio_fopen_function_t         _fopen;
213  fdio_ffileno_function_t       _ffileno;
214  fdio_fflush_function_t        _fflush;
215
216  fdio_mkdir_function_t         _mkdir;
217  fdio_chdir_function_t         _chdir;
218  fdio_rmdir_function_t         _rmdir;
219  fdio_rename_function_t        _rename;
220  fdio_unlink_function_t        _unlink;
221};
222
223
224/** \ingroup rpmio
225 * \name RPMIO Interface.
226 */
227/*@{*/
228
229/**
230 * strerror(3) clone.
231 */
232/*@-redecl@*/
233/*@observer@*/ const char * Fstrerror(/*@null@*/ FD_t fd)
234        /*@*/;
235/*@=redecl@*/
236
237/**
238 * fread(3) clone.
239 */
240size_t Fread(/*@out@*/ void * buf, size_t size, size_t nmemb, FD_t fd)
241        /*@globals fileSystem @*/
242        /*@modifies fd, *buf, fileSystem @*/;
243
244/**
245 * fwrite(3) clone.
246 */
247size_t Fwrite(const void * buf, size_t size, size_t nmemb, FD_t fd)
248        /*@globals fileSystem @*/
249        /*@modifies fd, fileSystem @*/;
250
251/**
252 * fseek(3) clone.
253 */
254int Fseek(FD_t fd, _libio_off_t offset, int whence)
255        /*@globals fileSystem @*/
256        /*@modifies fileSystem @*/;
257
258/**
259 * fclose(3) clone.
260 */
261int Fclose( /*@killref@*/ FD_t fd)
262        /*@globals fileSystem @*/
263        /*@modifies fd, fileSystem @*/;
264
265/**
266 */
267/*@null@*/ FD_t Fdopen(FD_t ofd, const char * fmode)
268        /*@globals fileSystem @*/
269        /*@modifies ofd, fileSystem @*/;
270
271/**
272 * fopen(3) clone.
273 */
274/*@null@*/ FD_t Fopen(/*@null@*/ const char * path,
275                        /*@null@*/ const char * fmode)
276        /*@globals fileSystem @*/
277        /*@modifies fileSystem @*/;
278
279
280/**
281 * fflush(3) clone.
282 */
283int Fflush(/*@null@*/ FD_t fd)
284        /*@globals fileSystem @*/
285        /*@modifies fd, fileSystem @*/;
286
287/**
288 * ferror(3) clone.
289 */
290int Ferror(/*@null@*/ FD_t fd)
291        /*@*/;
292
293/**
294 * fileno(3) clone.
295 */
296int Fileno(FD_t fd)
297        /*@globals fileSystem @*/
298        /*@modifies fileSystem@*/;
299
300/**
301 * fcntl(2) clone.
302 */
303int Fcntl(FD_t fd, int op, void *lip)
304        /*@globals fileSystem @*/
305        /*@modifies fd, *lip, fileSystem @*/;
306
307/*@}*/
308
309/** \ingroup rpmrpc
310 * \name RPMRPC Interface.
311 */
312/*@{*/
313
314/**
315 * mkdir(2) clone.
316 */
317int Mkdir(const char * path, mode_t mode)
318        /*@globals fileSystem @*/
319        /*@modifies fileSystem @*/;
320
321/**
322 * chdir(2) clone.
323 */
324int Chdir(const char * path)
325        /*@globals fileSystem @*/
326        /*@modifies fileSystem @*/;
327
328/**
329 * rmdir(2) clone.
330 */
331int Rmdir(const char * path)
332        /*@globals fileSystem @*/
333        /*@modifies fileSystem @*/;
334
335/**
336 * rename(2) clone.
337 */
338int Rename(const char * oldpath, const char * newpath)
339        /*@globals fileSystem @*/
340        /*@modifies fileSystem @*/;
341
342/**
343 * link(2) clone.
344 */
345int Link(const char * oldpath, const char * newpath)
346        /*@globals fileSystem @*/
347        /*@modifies fileSystem @*/;
348
349/**
350 * unlink(2) clone.
351 */
352int Unlink(const char * path)
353        /*@globals fileSystem @*/
354        /*@modifies fileSystem @*/;
355
356/**
357 * readlink(2) clone.
358 */
359int Readlink(const char * path, /*@out@*/ char * buf, size_t bufsiz)
360        /*@globals fileSystem @*/
361        /*@modifies *buf, fileSystem @*/;
362
363/**
364 * stat(2) clone.
365 */
366int Stat(const char * path, /*@out@*/ struct stat * st)
367        /*@globals fileSystem @*/
368        /*@modifies *st, fileSystem @*/;
369
370/**
371 * lstat(2) clone.
372 */
373int Lstat(const char * path, /*@out@*/ struct stat * st)
374        /*@globals fileSystem @*/
375        /*@modifies *st, fileSystem @*/;
376
377/**
378 * access(2) clone.
379 */
380int Access(const char * path, int amode)
381        /*@globals fileSystem @*/
382        /*@modifies fileSystem @*/;
383
384
385/**
386 * glob(3) clone.
387 */
388int Glob(const char * pattern, int flags,
389                int errfunc(const char * epath, int eerrno),
390                /*@out@*/ glob_t * pglob)
391        /*@globals fileSystem @*/
392        /*@modifies *pglob, fileSystem @*/;
393
394/**
395 * globfree(3) clone.
396 */
397void Globfree( /*@only@*/ glob_t * pglob)
398        /*@globals fileSystem @*/
399        /*@modifies *pglob, fileSystem @*/;
400
401
402/**
403 * opendir(3) clone.
404 */
405/*@null@*/
406DIR * Opendir(const char * path)
407        /*@globals fileSystem @*/
408        /*@modifies fileSystem @*/;
409
410/**
411 * readdir(3) clone.
412 */
413/*@null@*/ struct dirent * Readdir(DIR * dir)
414        /*@globals fileSystem @*/
415        /*@modifies *dir, fileSystem @*/;
416
417/**
418 * closedir(3) clone.
419 */
420int     Closedir(/*@only@*/ DIR * dir)
421        /*@globals fileSystem @*/
422        /*@modifies *dir, fileSystem @*/;
423
424/*@}*/
425
426
427/** \ingroup rpmio
428 * \name RPMIO Utilities.
429 */
430/*@{*/
431
432/**
433 */
434off_t   fdSize(FD_t fd)
435        /*@globals fileSystem @*/
436        /*@modifies fd, fileSystem@*/;
437
438/**
439 */
440/*@null@*/ FD_t fdDup(int fdno)
441        /*@globals fileSystem @*/
442        /*@modifies fileSystem@*/;
443
444#ifdef UNUSED
445/*@null@*/ FILE *fdFdopen( /*@only@*/ void * cookie, const char * mode);
446#endif
447
448/* XXX Legacy interfaces needed by gnorpm, rpmfind et al */
449
450/*@-exportlocal@*/
451/**
452 */
453#ifndef H_RPMIO_INTERNAL        /* XXX avoid gcc warning */
454/*@unused@*/ int fdFileno(void * cookie)
455        /*@*/;
456#define fdFileno(_fd)           fdio->_fileno(_fd)
457#endif
458
459/**
460 */
461/*@null@*/ FD_t fdOpen(const char *path, int flags, mode_t mode)
462        /*@globals fileSystem @*/
463        /*@modifies fileSystem @*/;
464#define fdOpen(_path, _flags, _mode)    fdio->_open((_path), (_flags), (_mode))
465
466/**
467 */
468ssize_t fdRead(void * cookie, /*@out@*/ char * buf, size_t count)
469        /*@globals fileSystem @*/
470        /*@modifies *cookie, *buf, fileSystem @*/;
471#define fdRead(_fd, _buf, _count)       fdio->read((_fd), (_buf), (_count))
472
473/**
474 */
475ssize_t fdWrite(void * cookie, const char * buf, size_t count)
476        /*@globals fileSystem @*/
477        /*@modifies *cookie, fileSystem @*/;
478#define fdWrite(_fd, _buf, _count)      fdio->write((_fd), (_buf), (_count))
479
480/**
481 */
482int fdClose( /*@only@*/ void * cookie)
483        /*@globals fileSystem @*/
484        /*@modifies *cookie, fileSystem @*/;
485#define fdCLose(_fd)            fdio->close(_fd)
486
487/**
488 */
489/*@unused@*/
490/*@only@*/ /*@null@*/
491FD_t fdLink (/*@only@*/ void * cookie, const char * msg)
492        /*@globals fileSystem @*/
493        /*@modifies *cookie, fileSystem @*/;
494#define fdLink(_fd, _msg)       fdio->_fdref(_fd, _msg, __FILE__, __LINE__)
495
496/**
497 */
498/*@unused@*/
499/*@only@*/ /*@null@*/
500FD_t fdFree(/*@only@*/ FD_t fd, const char * msg)
501        /*@globals fileSystem @*/
502        /*@modifies fd, fileSystem @*/;
503#define fdFree(_fd, _msg)       fdio->_fdderef(_fd, _msg, __FILE__, __LINE__)
504
505/**
506 */
507/*@unused@*/
508/*@only@*/ /*@null@*/
509FD_t fdNew (const char * msg)
510        /*@globals fileSystem @*/
511        /*@modifies fileSystem @*/;
512#define fdNew(_msg)             fdio->_fdnew(_msg, __FILE__, __LINE__)
513
514/**
515 */
516int fdWritable(FD_t fd, int secs)
517        /*@globals errno, fileSystem @*/
518        /*@modifies fd, errno, fileSystem @*/;
519
520/**
521 */
522int fdReadable(FD_t fd, int secs)
523        /*@globals errno @*/
524        /*@modifies fd, errno @*/;
525/*@=exportlocal@*/
526
527/**
528 * FTP and HTTP error codes.
529 */
530/*@-typeuse@*/
531typedef enum ftperrCode_e {
532    FTPERR_BAD_SERVER_RESPONSE  = -1,   /*!< Bad server response */
533    FTPERR_SERVER_IO_ERROR      = -2,   /*!< Server I/O error */
534    FTPERR_SERVER_TIMEOUT       = -3,   /*!< Server timeout */
535    FTPERR_BAD_HOST_ADDR        = -4,   /*!< Unable to lookup server host address */
536    FTPERR_BAD_HOSTNAME         = -5,   /*!< Unable to lookup server host name */
537    FTPERR_FAILED_CONNECT       = -6,   /*!< Failed to connect to server */
538    FTPERR_FILE_IO_ERROR        = -7,   /*!< Failed to establish data connection to server */
539    FTPERR_PASSIVE_ERROR        = -8,   /*!< I/O error to local file */
540    FTPERR_FAILED_DATA_CONNECT  = -9,   /*!< Error setting remote server to passive mode */
541    FTPERR_FILE_NOT_FOUND       = -10,  /*!< File not found on server */
542    FTPERR_NIC_ABORT_IN_PROGRESS= -11,  /*!< Abort in progress */
543    FTPERR_UNKNOWN              = -100  /*!< Unknown or unexpected error */
544} ftperrCode;
545/*@=typeuse@*/
546
547/**
548 */
549/*@-redecl@*/
550/*@observer@*/ const char *const ftpStrerror(int errorNumber)   /*@*/;
551/*@=redecl@*/
552
553/**
554 */
555/*@unused@*/
556/*@dependent@*/ /*@null@*/ void * ufdGetUrlinfo(FD_t fd)
557        /*@modifies fd @*/;
558
559/**
560 */
561/*@-redecl@*/
562/*@unused@*/
563/*@observer@*/ const char * urlStrerror(const char * url)       /*@*/;
564/*@=redecl@*/
565
566/**
567 */
568/*@-exportlocal@*/
569int ufdCopy(FD_t sfd, FD_t tfd)
570        /*@globals fileSystem @*/
571        /*@modifies sfd, tfd, fileSystem @*/;
572/*@=exportlocal@*/
573
574/**
575 */
576int ufdGetFile( /*@killref@*/ FD_t sfd, FD_t tfd)
577        /*@globals fileSystem @*/
578        /*@modifies sfd, tfd, fileSystem @*/;
579
580/**
581 */
582/*@unused@*/ int timedRead(FD_t fd, /*@out@*/ void * bufptr, int length)
583        /*@globals fileSystem @*/
584        /*@modifies fd, *bufptr, fileSystem @*/;
585#define timedRead       ufdio->read
586
587/*@-exportlocal@*/
588/**
589 */
590/*@observer@*/ /*@unchecked@*/ extern FDIO_t fdio;
591
592/**
593 */
594/*@observer@*/ /*@unchecked@*/ extern FDIO_t fpio;
595
596/**
597 */
598/*@observer@*/ /*@unchecked@*/ extern FDIO_t ufdio;
599
600/**
601 */
602/*@observer@*/ /*@unchecked@*/ extern FDIO_t gzdio;
603
604/**
605 */
606/*@observer@*/ /*@unchecked@*/ extern FDIO_t bzdio;
607
608/**
609 */
610/*@observer@*/ /*@unchecked@*/ extern FDIO_t fadio;
611/*@=exportlocal@*/
612/*@}*/
613
614/*@unused@*/ static inline int xislower(int c) /*@*/ {
615    return (c >= 'a' && c <= 'z');
616}
617/*@unused@*/ static inline int xisupper(int c) /*@*/ {
618    return (c >= 'A' && c <= 'Z');
619}
620/*@unused@*/ static inline int xisalpha(int c) /*@*/ {
621    return (xislower(c) || xisupper(c));
622}
623/*@unused@*/ static inline int xisdigit(int c) /*@*/ {
624    return (c >= '0' && c <= '9');
625}
626/*@unused@*/ static inline int xisalnum(int c) /*@*/ {
627    return (xisalpha(c) || xisdigit(c));
628}
629/*@unused@*/ static inline int xisblank(int c) /*@*/ {
630    return (c == ' ' || c == '\t');
631}
632/*@unused@*/ static inline int xisspace(int c) /*@*/ {
633    return (xisblank(c) || c == '\n' || c == '\r' || c == '\f' || c == '\v');
634}
635
636/*@unused@*/ static inline int xtolower(int c) /*@*/ {
637    return ((xisupper(c)) ? (c | ('a' - 'A')) : c);
638}
639/*@unused@*/ static inline int xtoupper(int c) /*@*/ {
640    return ((xislower(c)) ? (c & ~('a' - 'A')) : c);
641}
642
643/** \ingroup rpmio
644 * Locale insensitive strcasecmp(3).
645 */
646int xstrcasecmp(const char * s1, const char * s2)               /*@*/;
647
648/** \ingroup rpmio
649 * Locale insensitive strncasecmp(3).
650 */
651int xstrncasecmp(const char *s1, const char * s2, size_t n)     /*@*/;
652
653#ifdef __cplusplus
654}
655#endif
656
657#endif  /* H_RPMIO */
Note: See TracBrowser for help on using the repository browser.