commit - 43a2d19da87aec49a3fddd3bf14d4e63d17520b2
commit + 19d747f7bf553c46c0385d960db0d4f6d5f4543a
blob - 8e741204236a2eac2d5340b57fde5b4e4a7d1eb6
blob + b96fa54031b91ee3b26894533b25f6b0da0f177a
--- got/Makefile
+++ got/Makefile
CPPFLAGS = -I${.CURDIR}/../include -I${.CURDIR}/../lib
LDADD = -lutil -lz
DPADD = ${LIBZ} ${LIBUTIL}
-DEBUG = -O0 -g
+CC = gcc
+DEBUG = -O0 -pg
+CPPFLAGS += -DPROFILE
CFLAGS += -Werror -Wall -Wstrict-prototypes -Wunused-variable
# For now, default to installing binary in ~/bin
blob - be95ec2118d5261062ef994e8f8d22a4a399606b
blob + 3ae4fc609a39598209ccaf1ba6d24074b0d5661a
--- got/got.c
+++ got/got.c
argc -= optind;
argv += optind;
+#ifndef PROFILE
if (pledge("stdio rpath wpath cpath flock", NULL) == -1)
err(1, "pledge");
-
+#endif
if (argc == 1) {
char *cwd, *base, *dotgit;
repo_path = argv[0];
struct got_object *obj;
char *repo_path = NULL;
+#ifndef PROFILE
if (pledge("stdio rpath wpath cpath", NULL) == -1)
err(1, "pledge");
-
+#endif
if (argc == 1) {
repo_path = getcwd(NULL, 0);
if (repo_path == NULL)
blob - 066d18218edd647aad7e65766f3fa60dbfd0c592
blob + 9285ed5f1b90a4c3e4017658c8f83fb2dd3e8f2b
--- lib/got_zbuf_lib.h
+++ lib/got_zbuf_lib.h
char *outbuf;
size_t outlen;
int flags;
-#define GOT_ZSTREAM_F_HAVE_MORE 0x01
+#define GOT_ZSTREAM_F_HAVE_MORE 0x01
+#define GOT_ZSTREAM_F_OWN_OUTBUF 0x02
};
-#define GOT_ZSTREAM_BUFSIZE 8192
+#define GOT_ZSTREAM_BUFSIZE 8192
-const struct got_error *got_inflate_init(struct got_zstream_buf *, size_t);
+const struct got_error *got_inflate_init(struct got_zstream_buf *, uint8_t *,
+ size_t);
const struct got_error *got_inflate_read(struct got_zstream_buf *, FILE *,
size_t *);
void got_inflate_end(struct got_zstream_buf *);
blob - 6ad23fc3f806d3cc21e993ee240d754f25fb1429
blob + 8a150ed6a4a8ab40a0192e6d13163ea368733167
--- lib/object.c
+++ lib/object.c
if (buf == NULL)
return got_error(GOT_ERR_NO_MEM);
- err = got_inflate_init(&zb, zbsize);
+ err = got_inflate_init(&zb, NULL, zbsize);
if (err)
return err;
return err;
}
- err = got_inflate_init(&(*blob)->zb, blocksize);
+ err = got_inflate_init(&(*blob)->zb, NULL, blocksize);
if (err != NULL) {
fclose((*blob)->f);
free(*blob);
blob - 4d83cf85804bb62caf73741c8b7aabcc09a4aa44
blob + cf71b54b29e4cfa1754df50ca0de519f2a9df125
--- lib/zbuf.c
+++ lib/zbuf.c
#include "got_zbuf_lib.h"
const struct got_error *
-got_inflate_init(struct got_zstream_buf *zb, size_t bufsize)
+got_inflate_init(struct got_zstream_buf *zb, uint8_t *outbuf, size_t bufsize)
{
const struct got_error *err = NULL;
goto done;
}
- zb->outbuf = calloc(1, zb->outlen);
- if (zb->outbuf == NULL) {
- err = got_error(GOT_ERR_NO_MEM);
- goto done;
- }
+ if (outbuf == NULL) {
+ zb->outbuf = calloc(1, zb->outlen);
+ if (zb->outbuf == NULL) {
+ err = got_error(GOT_ERR_NO_MEM);
+ goto done;
+ }
+ zb->flags |= GOT_ZSTREAM_F_OWN_OUTBUF;
+ } else
+ zb->outbuf = outbuf;
done:
if (err)
got_inflate_end(struct got_zstream_buf *zb)
{
free(zb->inbuf);
- free(zb->outbuf);
+ if (zb->flags & GOT_ZSTREAM_F_OWN_OUTBUF)
+ free(zb->outbuf);
inflateEnd(&zb->z);
}
struct got_zstream_buf zb;
void *newbuf;
- err = got_inflate_init(&zb, GOT_ZSTREAM_BUFSIZE);
+ *outbuf = calloc(1, GOT_ZSTREAM_BUFSIZE);
+ if (*outbuf == NULL)
+ return got_error(GOT_ERR_NO_MEM);
+ err = got_inflate_init(&zb, *outbuf, GOT_ZSTREAM_BUFSIZE);
if (err)
return err;
- *outbuf = NULL;
*outlen = 0;
do {
err = got_inflate_read(&zb, f, &avail);
if (err)
return err;
- if (avail > 0) {
- newbuf = reallocarray(*outbuf, 1, *outlen + avail);
+ *outlen += avail;
+ if (zb.flags & GOT_ZSTREAM_F_HAVE_MORE) {
+ newbuf = reallocarray(*outbuf, 1,
+ *outlen + GOT_ZSTREAM_BUFSIZE);
if (newbuf == NULL) {
free(*outbuf);
*outbuf = NULL;
err = got_error(GOT_ERR_NO_MEM);
goto done;
}
- memcpy(newbuf + *outlen, zb.outbuf, avail);
*outbuf = newbuf;
- *outlen += avail;
+ zb.outbuf = newbuf + *outlen;
+ zb.outlen = GOT_ZSTREAM_BUFSIZE;
}
} while (zb.flags & GOT_ZSTREAM_F_HAVE_MORE);
size_t avail;
struct got_zstream_buf zb;
- err = got_inflate_init(&zb, GOT_ZSTREAM_BUFSIZE);
+ err = got_inflate_init(&zb, NULL, GOT_ZSTREAM_BUFSIZE);
if (err)
goto done;