rpm  4.5
rpmio.h
Go to the documentation of this file.
1 #ifndef H_RPMIO
2 #define H_RPMIO
3 
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 
21 typedef /*@abstract@*/ struct pgpDig_s * pgpDig;
22 
25 typedef /*@abstract@*/ struct pgpDigParams_s * pgpDigParams;
26 
34 #if !defined(__LCLINT__) && defined(__GLIBC__) && \
35  (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2))
36 #define USE_COOKIE_SEEK_POINTER 1
37 typedef _IO_off64_t _libio_off_t;
38 typedef _libio_off_t * _libio_pos_t;
39 #else
40 typedef off_t _libio_off_t;
41 typedef off_t _libio_pos_t;
42 #endif
43 
47 typedef /*@abstract@*/ /*@refcounted@*/ struct _FD_s * FD_t;
48 
51 typedef /*@observer@*/ struct FDIO_s * FDIO_t;
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
61 
64 typedef ssize_t (*fdio_read_function_t) (void *cookie, char *buf, size_t nbytes)
65  /*@globals errno, fileSystem @*/
66  /*@modifies *cookie, errno, fileSystem @*/
67  /*@requires maxSet(buf) >= (nbytes - 1) @*/
68  /*@ensures maxRead(buf) == result @*/ ;
69 
72 typedef ssize_t (*fdio_write_function_t) (void *cookie, const char *buf, size_t nbytes)
73  /*@globals errno, fileSystem @*/
74  /*@modifies *cookie, errno, fileSystem @*/;
75 
78 typedef int (*fdio_seek_function_t) (void *cookie, _libio_pos_t pos, int whence)
79  /*@globals errno, fileSystem @*/
80  /*@modifies *cookie, errno, fileSystem @*/;
81 
84 typedef int (*fdio_close_function_t) (void *cookie)
85  /*@globals errno, fileSystem, systemState @*/
86  /*@modifies *cookie, errno, fileSystem, systemState @*/;
87 
90 typedef FD_t (*fdio_fopen_function_t) (const char * path, const char * fmode)
91  /*@globals errno, fileSystem @*/
92  /*@modifies errno, fileSystem @*/;
93 
96 typedef FD_t (*fdio_fdopen_function_t) (void * cookie, const char * fmode)
97  /*@globals errno, fileSystem @*/
98  /*@modifies errno, fileSystem @*/;
99 
105 struct FDIO_s {
112 };
113 
114 
119 
123 /*@observer@*/ const char * Fstrerror(/*@null@*/ FD_t fd)
124  /*@*/;
125 
129 /*@-incondefs@*/
130 size_t Fread(/*@out@*/ void * buf, size_t size, size_t nmemb, FD_t fd)
131  /*@globals fileSystem @*/
132  /*@modifies fd, *buf, fileSystem @*/
133  /*@requires maxSet(buf) >= (nmemb - 1) @*/
134  /*@ensures maxRead(buf) == result @*/;
135 /*@=incondefs@*/
136 
140 /*@-incondefs@*/
141 size_t Fwrite(const void * buf, size_t size, size_t nmemb, FD_t fd)
142  /*@globals fileSystem @*/
143  /*@modifies fd, fileSystem @*/
144  /*@requires maxRead(buf) >= nmemb @*/;
145 /*@=incondefs@*/
146 
150 int Fseek(FD_t fd, _libio_off_t offset, int whence)
151  /*@globals fileSystem @*/
152  /*@modifies fileSystem @*/;
153 
157 int Fclose( /*@killref@*/ FD_t fd)
158  /*@globals fileSystem, internalState @*/
159  /*@modifies fd, fileSystem, internalState @*/;
160 
163 /*@null@*/ FD_t Fdopen(FD_t ofd, const char * fmode)
164  /*@globals fileSystem, internalState @*/
165  /*@modifies ofd, fileSystem, internalState @*/;
166 
170 /*@null@*/ FD_t Fopen(/*@null@*/ const char * path,
171  /*@null@*/ const char * fmode)
172  /*@globals h_errno, fileSystem, internalState @*/
173  /*@modifies fileSystem, internalState @*/;
174 
175 
179 int Fflush(/*@null@*/ FD_t fd)
180  /*@globals fileSystem @*/
181  /*@modifies fd, fileSystem @*/;
182 
186 int Ferror(/*@null@*/ FD_t fd)
187  /*@*/;
188 
192 int Fileno(FD_t fd)
193  /*@globals fileSystem @*/
194  /*@modifies fileSystem@*/;
195 
199 /*@unused@*/
200 int Fcntl(FD_t fd, int op, void *lip)
201  /*@globals errno, fileSystem @*/
202  /*@modifies fd, *lip, errno, fileSystem @*/;
203 
210 
214 int Mkdir(const char * path, mode_t mode)
215  /*@globals errno, h_errno, fileSystem, internalState @*/
216  /*@modifies errno, fileSystem, internalState @*/;
217 
221 int Chdir(const char * path)
222  /*@globals errno, h_errno, fileSystem, internalState @*/
223  /*@modifies errno, fileSystem, internalState @*/;
224 
228 int Rmdir(const char * path)
229  /*@globals errno, h_errno, fileSystem, internalState @*/
230  /*@modifies errno, fileSystem, internalState @*/;
231 
232 /*@unchecked@*/ /*@observer@*/ /*@null@*/
233 extern const char * _chroot_prefix;
234 
239 int Chroot(const char * path)
240  /*@globals _chroot_prefix, errno, fileSystem, internalState @*/
241  /*@modifies _chroot_prefix, errno, fileSystem, internalState @*/;
242 
247 int Open(const char * path, int flags, mode_t mode)
248  /*@globals errno, fileSystem, internalState @*/
249  /*@modifies errno, fileSystem, internalState @*/;
250 
254 int Rename(const char * oldpath, const char * newpath)
255  /*@globals errno, h_errno, fileSystem, internalState @*/
256  /*@modifies errno, fileSystem, internalState @*/;
257 
261 int Link(const char * oldpath, const char * newpath)
262  /*@globals errno, fileSystem, internalState @*/
263  /*@modifies errno, fileSystem, internalState @*/;
264 
268 int Unlink(const char * path)
269  /*@globals errno, h_errno, fileSystem, internalState @*/
270  /*@modifies errno, fileSystem, internalState @*/;
271 
275 int Stat(const char * path, /*@out@*/ struct stat * st)
276  /*@globals errno, h_errno, fileSystem, internalState @*/
277  /*@modifies *st, errno, fileSystem, internalState @*/;
278 
282 int Lstat(const char * path, /*@out@*/ struct stat * st)
283  /*@globals errno, h_errno, fileSystem, internalState @*/
284  /*@modifies *st, errno, fileSystem, internalState @*/;
285 
290 int Chown(const char * path, uid_t owner, gid_t group)
291  /*@globals errno, fileSystem, internalState @*/
292  /*@modifies errno, fileSystem, internalState @*/;
293 
298 int Lchown(const char * path, uid_t owner, gid_t group)
299  /*@globals errno, fileSystem, internalState @*/
300  /*@modifies errno, fileSystem, internalState @*/;
301 
306 int Chmod(const char * path, mode_t mode)
307  /*@globals errno, fileSystem, internalState @*/
308  /*@modifies errno, fileSystem, internalState @*/;
309 
314 int Mkfifo(const char * path, mode_t mode)
315  /*@globals errno, fileSystem, internalState @*/
316  /*@modifies errno, fileSystem, internalState @*/;
317 
322 int Mknod(const char * path, mode_t mode, dev_t dev)
323  /*@globals errno, fileSystem, internalState @*/
324  /*@modifies errno, fileSystem, internalState @*/;
325 
330 int Utime(const char * path, const struct utimbuf * buf)
331  /*@globals errno, fileSystem, internalState @*/
332  /*@modifies errno, fileSystem, internalState @*/;
333 
338 int Utimes(const char * path, const struct timeval * times)
339  /*@globals errno, fileSystem, internalState @*/
340  /*@modifies errno, fileSystem, internalState @*/;
341 
346 int Symlink(const char * oldpath, const char * newpath)
347  /*@globals errno, fileSystem, internalState @*/
348  /*@modifies errno, fileSystem, internalState @*/;
349 
354 /*@-incondefs@*/
355 int Readlink(const char * path, /*@out@*/ char * buf, size_t bufsiz)
356  /*@globals errno, h_errno, fileSystem, internalState @*/
357  /*@modifies *buf, errno, fileSystem, internalState @*/
358  /*@requires maxSet(buf) >= (bufsiz - 1) @*/
359  /*@ensures maxRead(buf) <= bufsiz @*/;
360 /*@=incondefs@*/
361 
366 int Access(const char * path, int amode)
367  /*@globals errno, fileSystem @*/
368  /*@modifies errno, fileSystem @*/;
369 
373 int Glob_pattern_p (const char *pattern, int quote)
374  /*@*/;
375 
379 int Glob_error(const char * epath, int eerrno)
380  /*@*/;
381 
385 int Glob(const char * pattern, int flags,
386  int errfunc(const char * epath, int eerrno),
387  /*@out@*/ glob_t * pglob)
388  /*@globals fileSystem @*/
389  /*@modifies *pglob, fileSystem @*/;
390 
394 void Globfree( /*@only@*/ glob_t * pglob)
395  /*@globals fileSystem @*/
396  /*@modifies *pglob, fileSystem @*/;
397 
398 
402 /*@null@*/
403 DIR * Opendir(const char * path)
404  /*@globals errno, h_errno, fileSystem, internalState @*/
405  /*@modifies errno, fileSystem, internalState @*/;
406 
410 /*@dependent@*/ /*@null@*/
411 struct dirent * Readdir(DIR * dir)
412  /*@globals errno, fileSystem @*/
413  /*@modifies *dir, errno, fileSystem @*/;
414 
418 int Closedir(/*@only@*/ DIR * dir)
419  /*@globals errno, fileSystem @*/
420  /*@modifies *dir, errno, fileSystem @*/;
421 
425 char * Realpath(const char * path, /*@out@*/ /*@null@*/ char * resolved_path)
426  /*@globals errno, fileSystem, internalState @*/
427  /*@modifies *resolved_path, errno, fileSystem, internalState @*/;
428 
433 off_t Lseek(int fdno, off_t offset, int whence)
434  /*@globals errno, fileSystem @*/
435  /*@modifies errno, fileSystem @*/;
436 
444 
447 off_t fdSize(FD_t fd)
448  /*@globals fileSystem @*/
449  /*@modifies fd, fileSystem@*/;
450 
453 /*@null@*/ FD_t fdDup(int fdno)
454  /*@globals fileSystem, internalState @*/
455  /*@modifies fileSystem, internalState @*/;
456 
457 /*@-exportlocal@*/
460 /*@-incondefs@*/
461 ssize_t fdRead(void * cookie, /*@out@*/ char * buf, size_t count)
462  /*@globals errno, fileSystem, internalState @*/
463  /*@modifies *cookie, *buf, errno, fileSystem, internalState @*/
464  /*@requires maxSet(buf) >= (count - 1) @*/
465  /*@ensures maxRead(buf) == result @*/ ;
466 #define fdRead(_fd, _buf, _count) fdio->read((_fd), (_buf), (_count))
467 /*@=incondefs@*/
468 
471 ssize_t fdWrite(void * cookie, const char * buf, size_t count)
472  /*@globals errno, fileSystem, internalState @*/
473  /*@modifies *cookie, errno, fileSystem, internalState @*/;
474 #define fdWrite(_fd, _buf, _count) fdio->write((_fd), (_buf), (_count))
475 
478 int fdClose( /*@only@*/ void * cookie)
479  /*@globals errno, fileSystem, systemState, internalState @*/
480  /*@modifies *cookie, errno, fileSystem, systemState, internalState @*/;
481 #define fdClose(_fd) fdio->close(_fd)
482 
485 /*@null@*/ FD_t fdOpen(const char *path, int flags, mode_t mode)
486  /*@globals errno, fileSystem, internalState @*/
487  /*@modifies errno, fileSystem, internalState @*/;
488 #define fdOpen(_path, _flags, _mode) fdio->_open((_path), (_flags), (_mode))
489 
492 /*@unused@*/
493 /*@only@*/ /*@null@*/
494 FD_t fdLink (/*@only@*/ void * cookie, const char * msg)
495  /*@globals fileSystem @*/
496  /*@modifies *cookie, fileSystem @*/;
497 /*@unused@*/
498 /*@only@*/ /*@null@*/
499 FD_t XfdLink (/*@only@*/ void * cookie, const char * msg, const char * fn, unsigned ln)
500  /*@globals fileSystem @*/
501  /*@modifies *cookie, fileSystem @*/;
502 #define fdLink(_fd, _msg) XfdLink(_fd, _msg, __FILE__, __LINE__)
503 
506 /*@unused@*/
507 /*@only@*/ /*@null@*/
508 FD_t fdFree(/*@only@*/ FD_t fd, const char * msg)
509  /*@globals fileSystem @*/
510  /*@modifies fd, fileSystem @*/;
511 /*@unused@*/
512 /*@only@*/ /*@null@*/
513 FD_t XfdFree(/*@only@*/ FD_t fd, const char * msg, const char * fn, unsigned ln)
514  /*@globals fileSystem @*/
515  /*@modifies fd, fileSystem @*/;
516 #define fdFree(_fd, _msg) XfdFree(_fd, _msg, __FILE__, __LINE__)
517 
520 /*@unused@*/
521 /*@only@*/ /*@null@*/
522 FD_t fdNew (const char * msg)
523  /*@globals fileSystem @*/
524  /*@modifies fileSystem @*/;
525 /*@unused@*/
526 /*@only@*/ /*@null@*/
527 FD_t XfdNew (const char * msg, const char * fn, unsigned ln)
528  /*@globals fileSystem @*/
529  /*@modifies fileSystem @*/;
530 #define fdNew(_msg) XfdNew(_msg, __FILE__, __LINE__)
531 
534 int fdWritable(FD_t fd, int secs)
535  /*@globals errno, fileSystem @*/
536  /*@modifies fd, errno, fileSystem @*/;
537 
540 int fdReadable(FD_t fd, int secs)
541  /*@globals errno @*/
542  /*@modifies fd, errno @*/;
543 /*@=exportlocal@*/
544 
553 int rpmioMkpath(const char * path, mode_t mode, uid_t uid, gid_t gid)
554  /*@globals h_errno, fileSystem, internalState @*/
555  /*@modifies fileSystem, internalState @*/;
556 
564 int rpmioAccess(const char *FN, /*@null@*/ const char * path, int mode)
565  /*@globals fileSystem, internalState @*/
566  /*@modifies fileSystem, internalState @*/;
567 
573 extern char * (*Getpass) (const char * prompt)
574  /*@*/;
575 char * _GetPass (const char * prompt)
576  /*@*/;
577 char * _RequestPass (const char * prompt)
578  /*@*/;
579 
583 /*@-typeuse@*/
584 typedef enum ftperrCode_e {
607 } ftperrCode;
608 /*@=typeuse@*/
609 
612 /*@-redecl@*/
613 /*@observer@*/ const char * ftpStrerror(int errorNumber)
614  /*@*/;
615 /*@=redecl@*/
616 
619 /*@unused@*/
620 /*@dependent@*/ /*@null@*/ void * ufdGetUrlinfo(FD_t fd)
621  /*@modifies fd @*/;
622 
625 /*@-redecl@*/
626 /*@unused@*/
627 /*@observer@*/ const char * urlStrerror(const char * url)
628  /*@globals h_errno, internalState @*/
629  /*@modifies internalState @*/;
630 /*@=redecl@*/
631 
634 /*@-exportlocal@*/
635 int ufdCopy(FD_t sfd, FD_t tfd)
636  /*@globals fileSystem @*/
637  /*@modifies sfd, tfd, fileSystem @*/;
638 /*@=exportlocal@*/
639 
642 int ufdGetFile( /*@killref@*/ FD_t sfd, FD_t tfd)
643  /*@globals fileSystem, internalState @*/
644  /*@modifies sfd, tfd, fileSystem, internalState @*/;
645 
648 /*@unused@*/ int timedRead(FD_t fd, /*@out@*/ void * bufptr, int length)
649  /*@globals fileSystem @*/
650  /*@modifies fd, *bufptr, fileSystem @*/;
651 #define timedRead (ufdio->read)
652 
653 /*@-exportlocal@*/
656 /*@observer@*/ /*@unchecked@*/ extern FDIO_t fdio;
657 
660 /*@observer@*/ /*@unchecked@*/ extern FDIO_t fpio;
661 
664 /*@observer@*/ /*@unchecked@*/ extern FDIO_t ufdio;
665 
668 /*@observer@*/ /*@unchecked@*/ extern FDIO_t gzdio;
669 
672 /*@observer@*/ /*@unchecked@*/ extern FDIO_t bzdio;
673 
676 /*@observer@*/ /*@unchecked@*/ extern FDIO_t lzdio;
677 
678 /*@=exportlocal@*/
681 /*@unused@*/ static inline int xislower(int c) /*@*/ {
682  return (c >= 'a' && c <= 'z');
683 }
684 /*@unused@*/ static inline int xisupper(int c) /*@*/ {
685  return (c >= 'A' && c <= 'Z');
686 }
687 /*@unused@*/ static inline int xisalpha(int c) /*@*/ {
688  return (xislower(c) || xisupper(c));
689 }
690 /*@unused@*/ static inline int xisdigit(int c) /*@*/ {
691  return (c >= '0' && c <= '9');
692 }
693 /*@unused@*/ static inline int xisalnum(int c) /*@*/ {
694  return (xisalpha(c) || xisdigit(c));
695 }
696 /*@unused@*/ static inline int xisblank(int c) /*@*/ {
697  return (c == ' ' || c == '\t');
698 }
699 /*@unused@*/ static inline int xisspace(int c) /*@*/ {
700  return (xisblank(c) || c == '\n' || c == '\r' || c == '\f' || c == '\v');
701 }
702 /*@unused@*/ static inline int xiscntrl(int c) /*@*/ {
703  return (c < ' ');
704 }
705 /*@unused@*/ static inline int xisascii(int c) /*@*/ {
706  return ((c & 0x80) != 0x80);
707 }
708 /*@unused@*/ static inline int xisprint(int c) /*@*/ {
709  return (c >= ' ' && xisascii(c));
710 }
711 /*@unused@*/ static inline int xisgraph(int c) /*@*/ {
712  return (c > ' ' && xisascii(c));
713 }
714 /*@unused@*/ static inline int xispunct(int c) /*@*/ {
715  return (xisgraph(c) && !xisalnum(c));
716 }
717 
718 /*@unused@*/ static inline int xtolower(int c) /*@*/ {
719  return ((xisupper(c)) ? (c | ('a' - 'A')) : c);
720 }
721 /*@unused@*/ static inline int xtoupper(int c) /*@*/ {
722  return ((xislower(c)) ? (c & ~('a' - 'A')) : c);
723 }
724 
728 int xstrcasecmp(const char * s1, const char * s2) /*@*/;
729 
733 int xstrncasecmp(const char *s1, const char * s2, size_t n) /*@*/;
734 
738 /*@only@*/ /*@null@*/
739 const char * xstrtolocale(/*@only@*/ const char *str)
740  /*@modifies *str @*/;
741 
742 #if !defined(SWIG)
743 
748 /*@unused@*/ static inline /*@null@*/
749 void * _free(/*@only@*/ /*@null@*/ /*@out@*/ const void * p)
750  /*@modifies p @*/
751 {
752  if (p != NULL) free((void *)p);
753  return NULL;
754 }
755 #endif
756 
757 #ifdef __cplusplus
758 }
759 #endif
760 
761 #endif /* H_RPMIO */