rpm  5.2.1
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 #include <stdio.h>
13 #include <stdlib.h>
14 #include <unistd.h>
15 
16 #include <rpmiotypes.h>
17 #include <rpmzlog.h>
18 
26 #if !defined(__LCLINT__) && !defined(__UCLIBC__) && defined(__GLIBC__) && \
27  (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2))
28 #define USE_COOKIE_SEEK_POINTER 1
29 typedef _IO_off64_t _libio_off_t;
30 typedef _libio_off_t * _libio_pos_t;
31 #else
32 typedef off_t _libio_off_t;
33 typedef off_t _libio_pos_t;
34 #endif
35 
39 typedef /*@abstract@*/ /*@refcounted@*/ struct _FD_s * FD_t;
40 
43 typedef /*@observer@*/ struct FDIO_s * FDIO_t;
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
53 
56 typedef ssize_t (*fdio_read_function_t) (void *cookie, char *buf, size_t nbytes)
57  /*@globals errno, fileSystem @*/
58  /*@modifies *cookie, errno, fileSystem @*/
59  /*@requires maxSet(buf) >= (nbytes - 1) @*/
60  /*@ensures maxRead(buf) == result @*/ ;
61 
64 typedef ssize_t (*fdio_write_function_t) (void *cookie, const char *buf, size_t nbytes)
65  /*@globals errno, fileSystem @*/
66  /*@modifies *cookie, errno, fileSystem @*/;
67 
70 typedef int (*fdio_seek_function_t) (void *cookie, _libio_pos_t pos, int whence)
71  /*@globals errno, fileSystem @*/
72  /*@modifies *cookie, errno, fileSystem @*/;
73 
76 typedef int (*fdio_close_function_t) (void *cookie)
77  /*@globals errno, fileSystem, systemState @*/
78  /*@modifies *cookie, errno, fileSystem, systemState @*/;
79 
82 typedef FD_t (*fdio_fopen_function_t) (const char * path, const char * fmode)
83  /*@globals errno, fileSystem @*/
84  /*@modifies errno, fileSystem @*/;
85 
88 typedef FD_t (*fdio_fdopen_function_t) (void * cookie, const char * fmode)
89  /*@globals errno, fileSystem @*/
90  /*@modifies errno, fileSystem @*/;
91 
94 typedef int (*fdio_flush_function_t) (void * cookie)
95  /*@globals errno, fileSystem @*/
96  /*@modifies errno, fileSystem @*/;
97 
103 struct FDIO_s {
108 /*@null@*/
110 /*@null@*/
112 /*@null@*/
114 };
115 
116 
121 
125 /*@observer@*/ const char * Fstrerror(/*@null@*/ FD_t fd)
126  /*@*/;
127 
131 /*@-incondefs@*/
132 size_t Fread(/*@out@*/ void * buf, size_t size, size_t nmemb, FD_t fd)
133  /*@globals fileSystem @*/
134  /*@modifies fd, *buf, fileSystem @*/
135  /*@requires maxSet(buf) >= (nmemb - 1) @*/;
136 /*@=incondefs@*/
137 
141 /*@-incondefs@*/
142 size_t Fwrite(const void * buf, size_t size, size_t nmemb, FD_t fd)
143  /*@globals fileSystem @*/
144  /*@modifies fd, fileSystem @*/
145  /*@requires maxRead(buf) >= nmemb @*/;
146 /*@=incondefs@*/
147 
151 int Fseek(FD_t fd, _libio_off_t offset, int whence)
152  /*@globals fileSystem @*/
153  /*@modifies fileSystem @*/;
154 
158 int Fclose( /*@killref@*/ FD_t fd)
159  /*@globals fileSystem, internalState @*/
160  /*@modifies fd, fileSystem, internalState @*/;
161 
164 /*@null@*/ FD_t Fdopen(FD_t ofd, const char * fmode)
165  /*@globals fileSystem, internalState @*/
166  /*@modifies ofd, fileSystem, internalState @*/;
167 
171 /*@null@*/ FD_t Fopen(/*@null@*/ const char * path,
172  /*@null@*/ const char * fmode)
173  /*@globals h_errno, fileSystem, internalState @*/
174  /*@modifies fileSystem, internalState @*/;
175 
176 
180 int Fflush(/*@null@*/ FD_t fd)
181  /*@globals fileSystem @*/
182  /*@modifies fd, fileSystem @*/;
183 
187 int Ferror(/*@null@*/ FD_t fd)
188  /*@*/;
189 
193 int Fileno(FD_t fd)
194  /*@globals fileSystem @*/
195  /*@modifies fileSystem@*/;
196 
200 /*@unused@*/
201 int Fcntl(FD_t fd, int op, void *lip)
202  /*@globals errno, fileSystem @*/
203  /*@modifies fd, *lip, errno, fileSystem @*/;
204 
211 
215 int Mkdir(const char * path, mode_t mode)
216  /*@globals errno, h_errno, fileSystem, internalState @*/
217  /*@modifies errno, fileSystem, internalState @*/;
218 
222 int Chdir(const char * path)
223  /*@globals errno, h_errno, fileSystem, internalState @*/
224  /*@modifies errno, fileSystem, internalState @*/;
225 
229 int Rmdir(const char * path)
230  /*@globals errno, h_errno, fileSystem, internalState @*/
231  /*@modifies errno, fileSystem, internalState @*/;
232 
233 /*@unchecked@*/ /*@observer@*/ /*@null@*/
234 extern const char * _chroot_prefix;
235 
240 int Chroot(const char * path)
241  /*@globals _chroot_prefix, errno, fileSystem, internalState @*/
242  /*@modifies _chroot_prefix, errno, fileSystem, internalState @*/;
243 
248 int Open(const char * path, int flags, mode_t mode)
249  /*@globals errno, fileSystem, internalState @*/
250  /*@modifies errno, fileSystem, internalState @*/;
251 
255 int Rename(const char * oldpath, const char * newpath)
256  /*@globals errno, h_errno, fileSystem, internalState @*/
257  /*@modifies errno, fileSystem, internalState @*/;
258 
262 int Link(const char * oldpath, const char * newpath)
263  /*@globals errno, fileSystem, internalState @*/
264  /*@modifies errno, fileSystem, internalState @*/;
265 
269 int Unlink(const char * path)
270  /*@globals errno, h_errno, fileSystem, internalState @*/
271  /*@modifies errno, fileSystem, internalState @*/;
272 
276 int Stat(const char * path, /*@out@*/ struct stat * st)
277  /*@globals errno, h_errno, fileSystem, internalState @*/
278  /*@modifies *st, errno, fileSystem, internalState @*/;
279 
283 int Lstat(const char * path, /*@out@*/ struct stat * st)
284  /*@globals errno, h_errno, fileSystem, internalState @*/
285  /*@modifies *st, errno, fileSystem, internalState @*/;
286 
290 int Fstat(FD_t fd, /*@out@*/ struct stat * st)
291  /*@globals errno, fileSystem, internalState @*/
292  /*@modifies *st, errno, fileSystem, internalState @*/;
293 
298 int Chown(const char * path, uid_t owner, gid_t group)
299  /*@globals errno, fileSystem, internalState @*/
300  /*@modifies errno, fileSystem, internalState @*/;
301 
306 int Fchown(FD_t fd, uid_t owner, gid_t group)
307  /*@globals errno, fileSystem, internalState @*/
308  /*@modifies errno, fileSystem, internalState @*/;
309 
314 int Lchown(const char * path, uid_t owner, gid_t group)
315  /*@globals errno, fileSystem, internalState @*/
316  /*@modifies errno, fileSystem, internalState @*/;
317 
322 int Chmod(const char * path, mode_t mode)
323  /*@globals errno, fileSystem, internalState @*/
324  /*@modifies errno, fileSystem, internalState @*/;
325 
330 int Fchmod(FD_t fd, mode_t mode)
331  /*@globals errno, fileSystem, internalState @*/
332  /*@modifies errno, fileSystem, internalState @*/;
333 
338 int Mkfifo(const char * path, mode_t mode)
339  /*@globals errno, fileSystem, internalState @*/
340  /*@modifies errno, fileSystem, internalState @*/;
341 
346 int Mknod(const char * path, mode_t mode, dev_t dev)
347  /*@globals errno, fileSystem, internalState @*/
348  /*@modifies errno, fileSystem, internalState @*/;
349 
354 struct utimbuf;
355 int Utime(const char * path, const struct utimbuf * buf)
356  /*@globals errno, fileSystem, internalState @*/
357  /*@modifies errno, fileSystem, internalState @*/;
358 
363 int Utimes(const char * path, const struct timeval * times)
364  /*@globals errno, fileSystem, internalState @*/
365  /*@modifies errno, fileSystem, internalState @*/;
366 
371 int Symlink(const char * oldpath, const char * newpath)
372  /*@globals errno, fileSystem, internalState @*/
373  /*@modifies errno, fileSystem, internalState @*/;
374 
379 /*@-incondefs@*/
380 int Readlink(const char * path, /*@out@*/ char * buf, size_t bufsiz)
381  /*@globals errno, h_errno, fileSystem, internalState @*/
382  /*@modifies *buf, errno, fileSystem, internalState @*/;
383 /*@=incondefs@*/
384 
389 int Access(const char * path, int amode)
390  /*@globals errno, fileSystem @*/
391  /*@modifies errno, fileSystem @*/;
392 
393 #if defined(__linux__)
394 
397 int Mount(const char *source, const char *target,
398  const char *filesystemtype, unsigned long mountflags,
399  const void *data)
400  /*@globals errno, fileSystem @*/
401  /*@modifies errno, fileSystem @*/;
402 
406 int Umount(const char *target)
407  /*@globals errno, fileSystem @*/
408  /*@modifies errno, fileSystem @*/;
409 
413 int Umount2(const char *target, int flags)
414  /*@globals errno, fileSystem @*/
415  /*@modifies errno, fileSystem @*/;
416 #endif
417 
421 int Glob_pattern_p (const char *pattern, int quote)
422  /*@*/;
423 
427 int Glob_error(const char * epath, int eerrno)
428  /*@*/;
429 
433 int Glob(const char * pattern, int flags,
434  int errfunc(const char * epath, int eerrno),
435  /*@out@*/ void * _pglob)
436  /*@globals fileSystem @*/
437  /*@modifies *_pglob, fileSystem @*/;
438 
442 void Globfree( /*@only@*/ void * _pglob)
443  /*@globals fileSystem @*/
444  /*@modifies *_pglob, fileSystem @*/;
445 
446 
450 /*@null@*/
451 DIR * Opendir(const char * path)
452  /*@globals errno, h_errno, fileSystem, internalState @*/
453  /*@modifies errno, fileSystem, internalState @*/;
454 
458 /*@dependent@*/ /*@null@*/
459 struct dirent * Readdir(DIR * dir)
460  /*@globals errno, fileSystem @*/
461  /*@modifies *dir, errno, fileSystem @*/;
462 
466 int Closedir(/*@only@*/ DIR * dir)
467  /*@globals errno, fileSystem @*/
468  /*@modifies *dir, errno, fileSystem @*/;
469 
473 /*@-globuse@*/
474 /*@null@*/
475 char * Realpath(const char * path, /*@out@*/ /*@null@*/ char * resolved_path)
476  /*@globals errno, fileSystem, internalState @*/
477  /*@modifies resolved_path, errno, fileSystem, internalState @*/;
478 /*@=globuse@*/
479 
484 off_t Lseek(int fdno, off_t offset, int whence)
485  /*@globals errno, fileSystem @*/
486  /*@modifies errno, fileSystem @*/;
487 
495 
498 /*@null@*/ FD_t fdDup(int fdno)
499  /*@globals fileSystem, internalState @*/
500  /*@modifies fileSystem, internalState @*/;
501 
502 /*@-exportlocal@*/
505 ssize_t fdRead(void * cookie, /*@out@*/ char * buf, size_t count)
506  /*@globals errno, fileSystem, internalState @*/
507  /*@modifies *cookie, *buf, errno, fileSystem, internalState @*/;
508 #define fdRead(_fd, _buf, _count) fdio->read((_fd), (_buf), (_count))
509 
512 ssize_t fdWrite(void * cookie, const char * buf, size_t count)
513  /*@globals errno, fileSystem, internalState @*/
514  /*@modifies *cookie, errno, fileSystem, internalState @*/;
515 #define fdWrite(_fd, _buf, _count) fdio->write((_fd), (_buf), (_count))
516 
519 int fdClose( /*@only@*/ void * cookie)
520  /*@globals errno, fileSystem, systemState, internalState @*/
521  /*@modifies *cookie, errno, fileSystem, systemState, internalState @*/;
522 #define fdClose(_fd) fdio->close(_fd)
523 
526 /*@null@*/ FD_t fdOpen(const char *path, int flags, mode_t mode)
527  /*@globals errno, fileSystem, internalState @*/
528  /*@modifies errno, fileSystem, internalState @*/;
529 #define fdOpen(_path, _flags, _mode) fdio->_open((_path), (_flags), (_mode))
530 
533 /*@unused@*/
534 /*@newref@*/ /*@null@*/
535 FD_t fdLink (void * cookie, const char * msg)
536  /*@globals fileSystem @*/
537  /*@modifies *cookie, fileSystem @*/;
538 #define fdLink(_fd, _msg) \
539  ((FD_t)rpmioLinkPoolItem((rpmioItem)(_fd), _msg, __FILE__, __LINE__))
540 
543 /*@unused@*/ /*@null@*/
544 FD_t fdFree(/*@killref@*/ FD_t fd, const char * msg)
545  /*@globals fileSystem @*/
546  /*@modifies fd, fileSystem @*/;
547 #define fdFree(_fd, _msg) \
548  ((FD_t)rpmioFreePoolItem((rpmioItem)(_fd), _msg, __FILE__, __LINE__))
549 
552 /*@unused@*/
553 /*@newref@*/ /*@null@*/
554 FD_t fdNew (const char * msg)
555  /*@globals fileSystem @*/
556  /*@modifies fileSystem @*/;
557 /*@newref@*/ /*@null@*/
558 FD_t XfdNew (const char * msg, const char * fn, unsigned ln)
559  /*@globals fileSystem @*/
560  /*@modifies fileSystem @*/;
561 #define fdNew(_msg) XfdNew(_msg, __FILE__, __LINE__)
562 
565 int fdWritable(FD_t fd, int secs)
566  /*@globals errno, fileSystem @*/
567  /*@modifies fd, errno, fileSystem @*/;
568 
571 int fdReadable(FD_t fd, int secs)
572  /*@globals errno @*/
573  /*@modifies fd, errno @*/;
574 /*@=exportlocal@*/
575 
584 int rpmioMkpath(const char * path, mode_t mode, uid_t uid, gid_t gid)
585  /*@globals h_errno, fileSystem, internalState @*/
586  /*@modifies fileSystem, internalState @*/;
587 
595 int rpmioAccess(const char *FN, /*@null@*/ const char * path, int mode)
596  /*@globals fileSystem, internalState @*/
597  /*@modifies fileSystem, internalState @*/;
598 
604 extern char * (*Getpass) (const char * prompt)
605  /*@*/;
606 char * _GetPass (const char * prompt)
607  /*@*/;
608 char * _RequestPass (const char * prompt)
609  /*@*/;
610 
614 /*@-typeuse@*/
615 typedef enum ftperrCode_e {
638 } ftperrCode;
639 /*@=typeuse@*/
640 
643 /*@-redecl@*/
644 /*@observer@*/
645 const char * ftpStrerror(int errorNumber)
646  /*@*/;
647 /*@=redecl@*/
648 
651 /*@unused@*/
652 /*@dependent@*/ /*@null@*/
653 void * ufdGetUrlinfo(FD_t fd)
654  /*@globals fileSystem @*/
655  /*@modifies fd, fileSystem @*/;
656 
659 /*@-redecl@*/
660 /*@unused@*/
661 /*@observer@*/
662 const char * urlStrerror(const char * url)
663  /*@globals h_errno, internalState @*/
664  /*@modifies internalState @*/;
665 /*@=redecl@*/
666 
669 /*@-exportlocal@*/
670 int ufdCopy(FD_t sfd, FD_t tfd)
671  /*@globals fileSystem @*/
672  /*@modifies sfd, tfd, fileSystem @*/;
673 /*@=exportlocal@*/
674 
677 int ufdGetFile( /*@killref@*/ FD_t sfd, FD_t tfd)
678  /*@globals fileSystem, internalState @*/
679  /*@modifies sfd, tfd, fileSystem, internalState @*/;
680 
681 /*@-exportlocal@*/
684 /*@observer@*/ /*@unchecked@*/ extern FDIO_t fdio;
685 
688 /*@observer@*/ /*@unchecked@*/ extern FDIO_t fpio;
689 
692 /*@observer@*/ /*@unchecked@*/ extern FDIO_t ufdio;
693 
696 /*@observer@*/ /*@unchecked@*/ extern FDIO_t gzdio;
697 
700 /*@observer@*/ /*@unchecked@*/ extern FDIO_t bzdio;
701 
704 /*@observer@*/ /*@unchecked@*/ extern FDIO_t lzdio;
705 
708 /*@observer@*/ /*@unchecked@*/ extern FDIO_t xzdio;
709 
710 /*@=exportlocal@*/
713 /*@unchecked@*/ /*@only@*/ /*@null@*/
714 extern rpmioPool _fdPool;
715 
719 void rpmioClean(void)
720  /*@globals _fdPool, fileSystem, internalState @*/
721  /*@modifies _fdPool, fileSystem, internalState @*/;
722 
728 /*@null@*/
729 rpmioPool rpmioFreePool(/*@only@*//*@null@*/ rpmioPool pool)
730  /*@globals fileSystem, internalState @*/
731  /*@modifies pool, fileSystem, internalState @*/;
732 
744 rpmioPool rpmioNewPool(/*@observer@*/ const char * name,
745  size_t size, int limit, int flags,
746  /*@null@*/ const char * (*dbg) (void *item),
747  /*@null@*/ void (*init) (void *item),
748  /*@null@*/ void (*fini) (void *item))
749  /*@globals fileSystem @*/
750  /*@modifies fileSystem @*/;
751 
760 /*@null@*/
761 rpmioItem rpmioUnlinkPoolItem(/*@killref@*/ /*@null@*/ rpmioItem item,
762  const char * msg, const char * fn, unsigned ln)
763  /*@globals fileSystem @*/
764  /*@modifies item, fileSystem @*/;
765 
774 /*@newref@*/ /*@null@*/
775 rpmioItem rpmioLinkPoolItem(/*@returned@*/ /*@null@*/ rpmioItem item,
776  const char * msg, const char * fn, unsigned ln)
777  /*@globals fileSystem @*/
778  /*@modifies item, fileSystem @*/;
779 
788 /*@null@*/
789 void * rpmioFreePoolItem(/*@killref@*/ /*@null@*/ rpmioItem item,
790  const char * msg, const char * fn, unsigned ln)
791  /*@globals fileSystem @*/
792  /*@modifies item, fileSystem @*/;
793 
800 rpmioItem rpmioGetPool(/*@kept@*/ /*@null@*/ rpmioPool pool, size_t size)
801  /*@globals fileSystem @*/
802  /*@modifies pool, fileSystem @*/;
803 
809 /*@null@*/
811  /*@globals fileSystem @*/
812  /*@modifies item, fileSystem @*/;
813 
814 #ifdef __cplusplus
815 }
816 #endif
817 
818 #endif /* H_RPMIO */