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);
70 while (iob->blen > 0 &&
xisspace((
int)iob->b[iob->blen-1]))
73 fprintf(stderr,
"<-- %s(%p) %p[%u:%u]\n", __FUNCTION__, iob, iob->b, (
unsigned)iob->blen, (
unsigned)iob->allocated);
79 size_t ns = strlen(s);
85 if ((iob->blen + ns) > iob->allocated) {
90 tail = iob->b + iob->blen;
98 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);
106 fprintf(stderr,
"<-- %s(%p) %p[%u:%u]\n", __FUNCTION__, iob, iob->b, (
unsigned)iob->blen, (
unsigned)iob->allocated);
116 fprintf(stderr,
"<-- %s(%p) %p[%u:%u]\n===============\n%s\n===============\n", __FUNCTION__, iob, iob->b, (
unsigned)iob->blen, (
unsigned)iob->allocated, iob->b);
118 return (
char *) iob->b;
125 fprintf(stderr,
"<-- %s(%p) %p[%u:%u]\n", __FUNCTION__, iob, iob->b, (
unsigned)iob->blen, (
unsigned)iob->allocated);
126 return (iob != NULL ? iob->blen : 0);
131 static size_t blenmax = (128 * BUFSIZ);
139 fd =
Fopen(fn,
"r.ufdio");
140 if (fd == NULL ||
Ferror(fd)) {
145 if ((xx =
Fstat(fd, &sb)) < 0 || sb.st_size == 0)
146 sb.st_size = blenmax;
147 #if defined(__linux__)
150 if (sb.st_size == 0 && !strncmp(fn,
"/proc/",
sizeof(
"/proc/")-1)) {
155 xx = read(
Fileno(fd), b, blen);
156 blen = (size_t) (xx >= 0 ? xx : 0);
164 blen =
Fread(b,
sizeof(*b), blen, fd);
170 if (blen < (
size_t)sb.st_size)
175 if (fd != NULL) (void)
Fclose(fd);
177 if (rc == 0 && iobp != NULL) {
182 iob->allocated = blen;
rpmiob rpmiobRTrim(rpmiob iob)
Trim trailing white space.
rpmuint8_t * rpmiobBuf(rpmiob iob)
Return I/O buffer.
const char const char size_t len
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)