Skip to content

Commit

Permalink
Split orch.h out
Browse files Browse the repository at this point in the history
Better define the bits that are private to the lib, private to the C driver,
and common to both.

Signed-off-by: Kyle Evans <[email protected]>
  • Loading branch information
kevans91 committed Jan 23, 2024
1 parent 803dbdc commit 17b4eba
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 27 deletions.
29 changes: 6 additions & 23 deletions include/orch.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,15 @@
#define __unused __attribute__((unused))
#endif

struct orch_process {
int cmdsock;
pid_t pid;
int status;
int termctl;
bool raw;
bool released;
bool eof;
bool buffered;
};

/* orch.c */
int orch_spawn(int, const char *[], struct orch_process *);

/* orch_interp.c */
int orch_interp(const char *, const char *, int, const char * const []);

/* orch_lua.c */
int luaopen_orch_core(lua_State *);

/* orch_compat.c */
#ifdef __linux__
size_t strlcpy(char * __restrict dst, const char * __restrict src, size_t dsize);
size_t strlcat(char * __restrict dst, const char * __restrict src, size_t dsize);
size_t strlcpy(char * __restrict, const char * __restrict, size_t);
size_t strlcat(char * __restrict, const char * __restrict, size_t);
#endif
#if defined(__linux__) || defined(__APPLE__) || defined(__OpenBSD__) || \
defined(__NetBSD__)
int tcsetsid(int tty, int sess);
int tcsetsid(int, int);
#endif

/* orch_lua.c */
int luaopen_orch_core(lua_State *);
27 changes: 27 additions & 0 deletions lib/orch_lib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*-
* Copyright (c) 2024 Kyle Evans <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#pragma once

#include <sys/types.h>

#include <stdbool.h>

#include <lua.h>

struct orch_process {
int cmdsock;
pid_t pid;
int status;
int termctl;
bool raw;
bool released;
bool eof;
bool buffered;
};

/* orch_spawn.c */
int orch_spawn(int, const char *[], struct orch_process *);
1 change: 1 addition & 0 deletions lib/orch_lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <unistd.h>

#include "orch.h"
#include "orch_lib.h"

#include <lauxlib.h>

Expand Down
14 changes: 10 additions & 4 deletions lib/orch_spawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <unistd.h>

#include "orch.h"
#include "orch_lib.h"

#ifdef __OpenBSD__
#define POSIX_OPENPT_FLAGS (O_RDWR | O_NOCTTY)
Expand All @@ -24,12 +25,17 @@

extern char **environ;

static void orch_exec(int argc, const char *argv[], int cmdsock);
/* Parent */
static int orch_newpt(void);

/* Child */
static pid_t orch_newsess(void);
static void orch_usept(pid_t sess, int termctl);
static void orch_wait(int cmdsock);
static void orch_release(int cmdsock);
static void orch_usept(pid_t, int);
static void orch_exec(int, const char *[], int);

/* Both */
static void orch_release(int);
static void orch_wait(int);

int
orch_spawn(int argc, const char *argv[], struct orch_process *p)
Expand Down
1 change: 1 addition & 0 deletions src/orch.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <unistd.h>

#include "orch.h"
#include "orch_bin.h"

#ifndef __dead2
#define __dead2 __attribute__((noreturn))
Expand Down
12 changes: 12 additions & 0 deletions src/orch_bin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*-
* Copyright (c) 2024 Kyle Evans <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#pragma once

#include <lua.h>

/* orch_interp.c */
int orch_interp(const char *, const char *, int, const char * const []);
1 change: 1 addition & 0 deletions src/orch_interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <string.h>

#include "orch.h"
#include "orch_bin.h"

#include <lauxlib.h>
#include <lualib.h>
Expand Down

0 comments on commit 17b4eba

Please sign in to comment.