commit f8d78af1fed1e580b5282fc7dd530e37befe5d93
parent 0d85081f81ae9ca996b33eee9b62023e6a0c30fe
Author: Kyle Milz <kyle@0x30.net>
Date: Sat, 21 Jan 2017 22:39:41 -0700
lib: move getcwd into os specific files
Diffstat:
3 files changed, 16 insertions(+), 19 deletions(-)
diff --git a/lib.c b/lib.c
@@ -16,10 +16,8 @@
#include <stdlib.h> /* exit */
#include <stdio.h> /* fprintf, stderr */
#include <string.h> /* strncpy */
-#include <unistd.h> /* getcwd */
-#include "lib.h" /* citrun_*, struct citrun_{header,node} */
-#include "lib_os.h" /* extend, open_fd */
+#include "lib_os.h" /* lib.h, extend, open_fd */
static int init;
@@ -46,11 +44,8 @@ add_header()
header->major = citrun_major;
header->minor = citrun_minor;
- get_pids(header->pids);
- get_prog_name(header->progname, sizeof(header->progname));
-
- if (getcwd(header->cwd, sizeof(header->cwd)) == NULL)
- strncpy(header->cwd, "", sizeof(header->cwd));
+ /* Fill in os specific information in header. */
+ citrun_os_info(header);
atexit(set_exited);
}
diff --git a/lib_os.h b/lib_os.h
@@ -1,7 +1,7 @@
+#include "lib.h"
/*
* Operating system specific functions.
*/
void *extend(size_t);
-void get_prog_name(char *, size_t);
-void get_pids(unsigned int [3]);
+void citrun_os_info(struct citrun_header *);
void open_fd();
diff --git a/lib_unix.c b/lib_unix.c
@@ -86,16 +86,18 @@ open_fd()
err(1, "mkstemp");
}
+/*
+ * Fills in a few operating system specific fields in struct citrun_header.
+ */
void
-get_pids(unsigned int pids[3])
+citrun_os_info(struct citrun_header *h)
{
- pids[0] = getpid();
- pids[1] = getppid();
- pids[2] = getpgrp();
-}
+ h->pids[0] = getpid();
+ h->pids[1] = getppid();
+ h->pids[2] = getpgrp();
-void
-get_prog_name(char *buf, size_t buf_size)
-{
- strlcpy(buf, getprogname(), buf_size);
+ strlcpy(h->progname, getprogname(), sizeof(h->progname));
+
+ if (getcwd(h->cwd, sizeof(h->cwd)) == NULL)
+ strncpy(h->cwd, "", sizeof(h->cwd));
}