1dfc1153Chris Williamson/*
2dfc1153Chris Williamson * CDDL HEADER START
3dfc1153Chris Williamson *
4dfc1153Chris Williamson * This file and its contents are supplied under the terms of the
5dfc1153Chris Williamson * Common Development and Distribution License ("CDDL"), version 1.0.
6dfc1153Chris Williamson * You may only use this file in accordance with the terms of version
7dfc1153Chris Williamson * 1.0 of the CDDL.
8dfc1153Chris Williamson *
9dfc1153Chris Williamson * A full copy of the text of the CDDL should have accompanied this
10dfc1153Chris Williamson * source.  A copy of the CDDL is also available via the Internet at
11dfc1153Chris Williamson * http://www.illumos.org/license/CDDL.
12dfc1153Chris Williamson *
13dfc1153Chris Williamson * CDDL HEADER END
14dfc1153Chris Williamson */
15dfc1153Chris Williamson
16dfc1153Chris Williamson/*
172840dceChris Williamson * Copyright (c) 2016, 2017 by Delphix. All rights reserved.
18dfc1153Chris Williamson */
19dfc1153Chris Williamson
20dfc1153Chris Williamson#include <sys/zcp_global.h>
21dfc1153Chris Williamson
22dfc1153Chris Williamson#include "lua.h"
23dfc1153Chris Williamson#include "lauxlib.h"
24dfc1153Chris Williamson
25dfc1153Chris Williamsontypedef struct zcp_errno_global {
26dfc1153Chris Williamson	const char *zeg_name;
27dfc1153Chris Williamson	int zeg_errno;
28dfc1153Chris Williamson} zcp_errno_global_t;
29dfc1153Chris Williamson
30dfc1153Chris Williamsonstatic const zcp_errno_global_t errno_globals[] = {
31dfc1153Chris Williamson	{"EPERM", EPERM},
32dfc1153Chris Williamson	{"ENOENT", ENOENT},
33dfc1153Chris Williamson	{"ESRCH", ESRCH},
34dfc1153Chris Williamson	{"EINTR", EINTR},
35dfc1153Chris Williamson	{"EIO", EIO},
36dfc1153Chris Williamson	{"ENXIO", ENXIO},
37dfc1153Chris Williamson	{"E2BIG", E2BIG},
38dfc1153Chris Williamson	{"ENOEXEC", ENOEXEC},
39dfc1153Chris Williamson	{"EBADF", EBADF},
40dfc1153Chris Williamson	{"ECHILD", ECHILD},
41dfc1153Chris Williamson	{"EAGAIN", EAGAIN},
42dfc1153Chris Williamson	{"ENOMEM", ENOMEM},
43dfc1153Chris Williamson	{"EACCES", EACCES},
44dfc1153Chris Williamson	{"EFAULT", EFAULT},
45dfc1153Chris Williamson	{"ENOTBLK", ENOTBLK},
46dfc1153Chris Williamson	{"EBUSY", EBUSY},
47dfc1153Chris Williamson	{"EEXIST", EEXIST},
48dfc1153Chris Williamson	{"EXDEV", EXDEV},
49dfc1153Chris Williamson	{"ENODEV", ENODEV},
50dfc1153Chris Williamson	{"ENOTDIR", ENOTDIR},
51dfc1153Chris Williamson	{"EISDIR", EISDIR},
52dfc1153Chris Williamson	{"EINVAL", EINVAL},
53dfc1153Chris Williamson	{"ENFILE", ENFILE},
54dfc1153Chris Williamson	{"EMFILE", EMFILE},
55dfc1153Chris Williamson	{"ENOTTY", ENOTTY},
56dfc1153Chris Williamson	{"ETXTBSY", ETXTBSY},
57dfc1153Chris Williamson	{"EFBIG", EFBIG},
58dfc1153Chris Williamson	{"ENOSPC", ENOSPC},
59dfc1153Chris Williamson	{"ESPIPE", ESPIPE},
60dfc1153Chris Williamson	{"EROFS", EROFS},
61dfc1153Chris Williamson	{"EMLINK", EMLINK},
62dfc1153Chris Williamson	{"EPIPE", EPIPE},
63dfc1153Chris Williamson	{"EDOM", EDOM},
64dfc1153Chris Williamson	{"ERANGE", ERANGE},
652840dceChris Williamson	{"EDEADLK", EDEADLK},
662840dceChris Williamson	{"ENOLCK", ENOLCK},
672840dceChris Williamson	{"ECANCELED", ECANCELED},
682840dceChris Williamson	{"ENOTSUP", ENOTSUP},
69dfc1153Chris Williamson	{"EDQUOT", EDQUOT},
702840dceChris Williamson	{"ENAMETOOLONG", ENAMETOOLONG},
71dd328bfToomas Soome	{NULL, 0}
72dfc1153Chris Williamson};
73dfc1153Chris Williamson
74dfc1153Chris Williamsonstatic void
75dfc1153Chris Williamsonzcp_load_errno_globals(lua_State *state)
76dfc1153Chris Williamson{
77dfc1153Chris Williamson	const zcp_errno_global_t *global = errno_globals;
78dfc1153Chris Williamson	while (global->zeg_name != NULL) {
79dfc1153Chris Williamson		lua_pushnumber(state, (lua_Number)global->zeg_errno);
80dfc1153Chris Williamson		lua_setglobal(state, global->zeg_name);
81dfc1153Chris Williamson		global++;
82dfc1153Chris Williamson	}
83dfc1153Chris Williamson}
84dfc1153Chris Williamson
85dfc1153Chris Williamsonvoid
86dfc1153Chris Williamsonzcp_load_globals(lua_State *state)
87dfc1153Chris Williamson{
88dfc1153Chris Williamson	zcp_load_errno_globals(state);
89dfc1153Chris Williamson}