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