5 #define _RPMIOB_INTERNAL 21 fprintf(stderr,
"--> %s(%p) %p[%u:%u]\n", __FUNCTION__, iob, iob->b, (
unsigned)iob->blen, (
unsigned)iob->allocated);
22 iob->b =
_free(iob->b);
36 if (_rpmiobPool == NULL) {
48 fprintf(stderr,
"--> %s(%p) %p[%u:%u]\n", __FUNCTION__, iob, iob->b, (
unsigned)iob->blen, (
unsigned)iob->allocated);
63 fprintf(stderr,
"<-- %s(%p) %p[%u:%u]\n", __FUNCTION__, iob, iob->b, (
unsigned)iob->blen, (
unsigned)iob->allocated);
71 while (iob->blen > 0 &&
xisspace((
int)iob->b[iob->blen-1]))
74 fprintf(stderr,
"<-- %s(%p) %p[%u:%u]\n", __FUNCTION__, iob, iob->b, (
unsigned)iob->blen, (
unsigned)iob->allocated);
80 size_t ns = strlen(s);
86 if ((iob->blen + ns) > iob->allocated) {
91 tail = iob->b + iob->blen;
99 fprintf(stderr,
"<-- %s(%p,%p,%u) %p[%u:%u] \"%s\"\n", __FUNCTION__, iob, s, (
unsigned)nl, iob->b, (
unsigned)iob->blen, (
unsigned)iob->allocated, s);
107 fprintf(stderr,
"<-- %s(%p) %p[%u:%u]\n", __FUNCTION__, iob, iob->b, (
unsigned)iob->blen, (
unsigned)iob->allocated);
117 fprintf(stderr,
"<-- %s(%p) %p[%u:%u]\n===============\n%s\n===============\n", __FUNCTION__, iob, iob->b, (
unsigned)iob->blen, (
unsigned)iob->allocated, iob->b);
119 return (
char *) iob->b;
126 fprintf(stderr,
"<-- %s(%p) %p[%u:%u]\n", __FUNCTION__, iob, iob->b, (
unsigned)iob->blen, (
unsigned)iob->allocated);
127 return (iob != NULL ? iob->blen : 0);
132 static size_t blenmax = (128 * BUFSIZ);
140 fd =
Fopen(fn,
"r.ufdio");
141 if (fd == NULL ||
Ferror(fd)) {
146 if ((xx =
Fstat(fd, &sb)) < 0 || sb.st_size == 0)
147 sb.st_size = blenmax;
148 #if defined(__linux__) 151 if (sb.st_size == 0 && !strncmp(fn,
"/proc/",
sizeof(
"/proc/")-1)) {
156 xx = read(
Fileno(fd), b, blen);
157 blen = (size_t) (xx >= 0 ? xx : 0);
165 blen =
Fread(b,
sizeof(*b), blen, fd);
171 if (blen < (
size_t)sb.st_size)
176 if (fd != NULL) (void)
Fclose(fd);
184 iob->allocated = blen;
rpmiob rpmiobRTrim(rpmiob iob)
Trim trailing white space.
rpmuint8_t * rpmiobBuf(rpmiob iob)
Return I/O buffer.
static void rpmiobFini(void *_iob)
size_t rpmiobLen(rpmiob iob)
Return I/O buffer len.
FD_t Fopen(const char *path, const char *_fmode)
fopen(3) clone.
rpmiob rpmiobAppend(rpmiob iob, const char *s, size_t nl)
Append string to I/O buffer.
int rpmiobSlurp(const char *fn, rpmiob *iobp)
int Fstat(FD_t fd, struct stat *st)
fstat(2) clone.
void * xcalloc(size_t nmemb, size_t size)
rpmioItem rpmioGetPool(rpmioPool pool, size_t size)
Get unused item from pool, or alloc a new item.
unsigned char rpmuint8_t
Private int typedefs to avoid C99 portability issues.
static int xisspace(int c)
The FD_t File Handle data structure.
size_t Fread(void *buf, size_t size, size_t nmemb, FD_t fd)
fread(3) clone.
rpmiob rpmiobLink(rpmiob iob)
Reference a I/O buffer instance.
int Fclose(FD_t fd)
fclose(3) clone.
rpmiob rpmiobNew(size_t len)
Create an I/O buffer.
int Ferror(FD_t fd)
ferror(3) clone.
char * rpmiobStr(rpmiob iob)
Return I/O buffer (as string).
rpmioPool rpmioNewPool(const char *name, size_t size, int limit, int flags, char *(*dbg)(void *item), void(*init)(void *item), void(*fini)(void *item))
Create a memory pool.
char * stpcpy(char *dest, const char *src)
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
rpmiob rpmiobEmpty(rpmiob iob)
Empty an I/O buffer.
int Fileno(FD_t fd)
fileno(3) clone.
static rpmiob rpmiobGetPool(rpmioPool pool)