commit - 11528a829855823153f2aaa9438bdf400a2995d7
commit + 511a516b74d9f5e498a5dc2de97b0e488df51088
blob - 0044a48fd54842d1cf8fc7bcc9f7c0144bf4be4a
blob + 810f98c5f9db96b76e1d0493976cc452b00b373e
--- got/Makefile
+++ got/Makefile
PROG= got
SRCS= got.c delta.c diff.c diffreg.c error.c fileindex.c object.c \
- path.c pack.c privsep.c reference.c repository.c sha1.c \
- worktree.c zbuf.c
+ opentemp.c path.c pack.c privsep.c reference.c repository.c \
+ sha1.c worktree.c zbuf.c
CPPFLAGS = -I${.CURDIR}/../include -I${.CURDIR}/../lib
LDADD = -lutil -lz
blob - /dev/null
blob + 1820266f93639ec63112a3c7606a8f613e897296 (mode 644)
--- /dev/null
+++ include/got_opentemp.h
+/*
+ * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* Utilities for opening temporary files. */
+
+/* Open a file descriptor to a new temporary file for writing.
+ * The file is not visible in the filesystem. */
+int got_opentempfd(void);
+
+/* Open a new temporary file for writing.
+ * The file is not visible in the filesystem. */
+FILE *got_opentemp(void);
+
+/* Open a new temporary file for writing.
+ * The file is visible in the filesystem. */
+const struct got_error *got_opentemp_named(char **, FILE **, const char *);
blob - 85c538615c4936d03916032ae8518959958e942f
blob + c9ec771e35f0f82b5f4685972ff2bcb68251d934
--- lib/diff.c
+++ lib/diff.c
#include "got_object.h"
#include "got_error.h"
#include "got_diff.h"
+#include "got_opentemp.h"
#include "got_lib_diff.h"
#include "got_lib_path.h"
blob - d1ceebbeaf4f607651a7bc7f2fcec650e1c6b04a
blob + 7fcd5f62f6c3cc3179fed12218f5e122f8ffde3b
--- lib/got_lib_path.h
+++ lib/got_lib_path.h
*/
char *got_path_normalize(const char *);
-/* Open a file descriptor to a new temporary file for writing.
- * The file is not visible in the filesystem. */
-int got_opentempfd(void);
-
-/* Open a new temporary file for writing.
- * The file is not visible in the filesystem. */
-FILE *got_opentemp(void);
-
-/* Open a new temporary file for writing.
- * The file is visible in the filesystem. */
-const struct got_error *got_opentemp_named(char **, FILE **, const char *);
-
/* Count the number of path segments separated by '/'. */
const struct got_error *
got_path_segment_count(int *count, const char *path);
blob - c3822193b294b2380efac47729fd22101b9c0157
blob + 45d21d4d24881d81b51e3afb2be011038e6c143f
--- lib/object.c
+++ lib/object.c
#include "got_error.h"
#include "got_object.h"
#include "got_repository.h"
+#include "got_opentemp.h"
#include "got_lib_sha1.h"
#include "got_lib_delta.h"
blob - 5ae9420580cc4f8445c55cd7f6fdc5d834dacb2f
blob + 6ced42c00804dbc2dce4ae8c33debdd3c8a80563
--- lib/pack.c
+++ lib/pack.c
#include "got_error.h"
#include "got_object.h"
#include "got_repository.h"
+#include "got_opentemp.h"
#include "got_lib_sha1.h"
#include "got_lib_pack.h"
blob - /dev/null
blob + 90af269f16900ad7f3484481718bef2f88c6ed82 (mode 644)
--- /dev/null
+++ lib/opentemp.c
+/*
+ * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <limits.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "got_opentemp.h"
+#include "got_error.h"
+
+int
+got_opentempfd(void)
+{
+ char name[PATH_MAX];
+ int fd;
+
+ if (strlcpy(name, "/tmp/got.XXXXXXXX", sizeof(name)) >= sizeof(name))
+ return -1;
+
+ fd = mkstemp(name);
+ unlink(name);
+ return fd;
+}
+
+FILE *
+got_opentemp(void)
+{
+ int fd;
+ FILE *f;
+
+ fd = got_opentempfd();
+ if (fd < 0)
+ return NULL;
+
+ f = fdopen(fd, "w+");
+ if (f == NULL) {
+ close(fd);
+ return NULL;
+ }
+
+ return f;
+}
+
+const struct got_error *
+got_opentemp_named(char **path, FILE **outfile, const char *basepath)
+{
+ const struct got_error *err = NULL;
+ int fd;
+
+ if (asprintf(path, "%s-XXXXXX", basepath) == -1) {
+ *path = NULL;
+ return got_error_from_errno();
+ }
+
+ fd = mkstemp(*path);
+ if (fd == -1) {
+ err = got_error_from_errno();
+ free(*path);
+ *path = NULL;
+ return err;
+ }
+
+ *outfile = fdopen(fd, "w+");
+ if (*outfile == NULL) {
+ err = got_error_from_errno();
+ free(*path);
+ *path = NULL;
+ }
+
+ return err;
+}
blob - 659eaea0299a501e44b05d9f6f3dfc0e603a0da5
blob + 30be0f88300d852efbfbef730e09f38d66a99b56
--- lib/path.c
+++ lib/path.c
return NULL;
}
-
-int
-got_opentempfd(void)
-{
- char name[PATH_MAX];
- int fd;
-
- if (strlcpy(name, "/tmp/got.XXXXXXXX", sizeof(name)) >= sizeof(name))
- return -1;
-
- fd = mkstemp(name);
- unlink(name);
- return fd;
-}
-
-FILE *
-got_opentemp(void)
-{
- int fd;
- FILE *f;
-
- fd = got_opentempfd();
- if (fd < 0)
- return NULL;
-
- f = fdopen(fd, "w+");
- if (f == NULL) {
- close(fd);
- return NULL;
- }
-
- return f;
-}
-
-const struct got_error *
-got_opentemp_named(char **path, FILE **outfile, const char *basepath)
-{
- const struct got_error *err = NULL;
- int fd;
-
- if (asprintf(path, "%s-XXXXXX", basepath) == -1) {
- *path = NULL;
- return got_error_from_errno();
- }
-
- fd = mkstemp(*path);
- if (fd == -1) {
- err = got_error_from_errno();
- free(*path);
- *path = NULL;
- return err;
- }
-
- *outfile = fdopen(fd, "w+");
- if (*outfile == NULL) {
- err = got_error_from_errno();
- free(*path);
- *path = NULL;
- }
-
- return err;
-}
blob - 4fe01db2011a09de7575dbead225e8a5cdd61e41
blob + 176d82f3d2de6c76d2ed803b1e3c8857aa627a9d
--- lib/worktree.c
+++ lib/worktree.c
#include "got_reference.h"
#include "got_object.h"
#include "got_worktree.h"
+#include "got_opentemp.h"
#include "got_lib_worktree.h"
#include "got_lib_path.h"
blob - 20d651390087f6b818b5116871c4e3c158eefc8c
blob + 3c421aacff588dc89a664f8b861ef2f60a071b52
--- regress/delta/Makefile
+++ regress/delta/Makefile
.PATH:${.CURDIR}/../../lib
PROG = delta_test
-SRCS = delta.c error.c path.c zbuf.c delta_test.c
+SRCS = delta.c error.c opentemp.c path.c zbuf.c delta_test.c
CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
LDADD = -lz
blob - b4272d32123c83c66b97ea8db4c10b5aa9bbb9da
blob + f8b0bfa821086e80656b9e1a57f229ff653befee
--- regress/delta/delta_test.c
+++ regress/delta/delta_test.c
#include <unistd.h>
#include "got_error.h"
+#include "got_opentemp.h"
#include "got_lib_delta.h"
#include "got_lib_path.h"
blob - 605897bc12d293b738391522d9efbee802cb54c8
blob + 18bd5277937e56ca6c47c5538db76068e10d5685
--- regress/repository/Makefile
+++ regress/repository/Makefile
.PATH:${.CURDIR}/../../lib
PROG = repository_test
-SRCS = path.c repository.c error.c reference.c object.c sha1.c diff.c \
- diffreg.c pack.c privsep.c delta.c fileindex.c worktree.c \
- zbuf.c repository_test.c
+SRCS = path.c repository.c error.c reference.c object.c opentemp.c \
+ sha1.c diff.c diffreg.c pack.c privsep.c delta.c fileindex.c \
+ worktree.c zbuf.c repository_test.c
CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
LDADD = -lutil -lz
blob - 67c32399cf6d5ff610bbb6cfae01015915a78850
blob + 6c9a268b1c6ce21ed2cc089da6a3914ec9103d33
--- regress/repository/repository_test.c
+++ regress/repository/repository_test.c
#include "got_reference.h"
#include "got_repository.h"
#include "got_diff.h"
+#include "got_opentemp.h"
#include "got_lib_path.h"
blob - 7d7df3bd9b3f8e19311418e163aa4904b3ab7239
blob + bdce9e6ef00763c45f688ceec5563b895cf56dd6
--- regress/worktree/Makefile
+++ regress/worktree/Makefile
.PATH:${.CURDIR}/../../lib
PROG = worktree_test
-SRCS = worktree.c repository.c object.c path.c error.c reference.c sha1.c \
- pack.c privsep.c delta.c zbuf.c fileindex.c worktree_test.c
+SRCS = worktree.c repository.c object.c opentemp.c path.c error.c \
+ reference.c sha1.c pack.c privsep.c delta.c zbuf.c \
+ fileindex.c worktree_test.c
CPPFLAGS = -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
LDADD = -lutil -lz
blob - eb723d0e2017c280c82d33e528302983a90378ab
blob + a1d1e49fe8037949908f248557e97cfb381a9757
--- regress/worktree/worktree_test.c
+++ regress/worktree/worktree_test.c
#include "got_reference.h"
#include "got_repository.h"
#include "got_worktree.h"
+#include "got_opentemp.h"
#include "got_lib_worktree.h"
#include "got_lib_path.h"
blob - 965c0cd925a617228dc60041904604c3fb359924
blob + 4fd5ba17802dd70e7c1323e8e2676299a6f2573b
--- tog/Makefile
+++ tog/Makefile
PROG= tog
SRCS= tog.c delta.c diff.c diffreg.c error.c fileindex.c object.c \
- path.c pack.c privsep.c reference.c repository.c sha1.c \
- worktree.c zbuf.c
+ opentemp.c path.c pack.c privsep.c reference.c repository.c \
+ sha1.c worktree.c zbuf.c
CPPFLAGS = -I${.CURDIR}/../include -I${.CURDIR}/../lib
LDADD = -lpanel -lcurses -lutil -lz
blob - 1eeab3c01b4b597a967bbbbd27de4658259cedac
blob + db5f5fc1ee2a0a8f2bc288df7d3b5a2b6178638a
--- tog/tog.c
+++ tog/tog.c
#include "got_reference.h"
#include "got_repository.h"
#include "got_diff.h"
+#include "got_opentemp.h"
#ifndef MIN
#define MIN(_a,_b) ((_a) < (_b) ? (_a) : (_b))
WINDOW *window;
PANEL *panel;
} tog_diff_view;
-
-int
-tog_opentempfd(void)
-{
- char name[PATH_MAX];
- int fd;
-
- if (strlcpy(name, "/tmp/tog.XXXXXXXX", sizeof(name)) >= sizeof(name))
- return -1;
-
- fd = mkstemp(name);
- unlink(name);
- return fd;
-}
-
-FILE *
-tog_opentemp(void)
-{
- int fd;
- FILE *f;
- fd = tog_opentempfd();
- if (fd < 0)
- return NULL;
-
- f = fdopen(fd, "w+");
- if (f == NULL) {
- close(fd);
- return NULL;
- }
-
- return f;
-}
-
__dead void
usage_log(void)
{
if (got_object_get_type(obj1) != got_object_get_type(obj2))
return got_error(GOT_ERR_OBJ_TYPE);
- f = tog_opentemp();
+ f = got_opentemp();
if (f == NULL)
return got_error_from_errno();