1*506f3640SKyle Evans /*- 2*506f3640SKyle Evans * Copyright (c) 2019 Kyle Evans <kevans@FreeBSD.org> 3*506f3640SKyle Evans * 4*506f3640SKyle Evans * Redistribution and use in source and binary forms, with or without 5*506f3640SKyle Evans * modification, are permitted provided that the following conditions 6*506f3640SKyle Evans * are met: 7*506f3640SKyle Evans * 1. Redistributions of source code must retain the above copyright 8*506f3640SKyle Evans * notice, this list of conditions and the following disclaimer. 9*506f3640SKyle Evans * 2. Redistributions in binary form must reproduce the above copyright 10*506f3640SKyle Evans * notice, this list of conditions and the following disclaimer in the 11*506f3640SKyle Evans * documentation and/or other materials provided with the distribution. 12*506f3640SKyle Evans * 13*506f3640SKyle Evans * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14*506f3640SKyle Evans * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15*506f3640SKyle Evans * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16*506f3640SKyle Evans * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17*506f3640SKyle Evans * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18*506f3640SKyle Evans * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19*506f3640SKyle Evans * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20*506f3640SKyle Evans * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21*506f3640SKyle Evans * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22*506f3640SKyle Evans * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23*506f3640SKyle Evans * SUCH DAMAGE. 24*506f3640SKyle Evans * 25*506f3640SKyle Evans */ 26*506f3640SKyle Evans 27*506f3640SKyle Evans #include <sys/cdefs.h> 28*506f3640SKyle Evans __FBSDID("$FreeBSD$"); 29*506f3640SKyle Evans 30*506f3640SKyle Evans #include <unistd.h> 31*506f3640SKyle Evans 32*506f3640SKyle Evans #include <lua.h> 33*506f3640SKyle Evans #include "lauxlib.h" 34*506f3640SKyle Evans #include "lposix.h" 35*506f3640SKyle Evans 36*506f3640SKyle Evans /* 37*506f3640SKyle Evans * Minimal implementation of luaposix needed for internal FreeBSD bits. 38*506f3640SKyle Evans */ 39*506f3640SKyle Evans 40*506f3640SKyle Evans static int 41*506f3640SKyle Evans lua_getpid(lua_State *L) 42*506f3640SKyle Evans { 43*506f3640SKyle Evans int n; 44*506f3640SKyle Evans 45*506f3640SKyle Evans n = lua_gettop(L); 46*506f3640SKyle Evans luaL_argcheck(L, n == 0, 1, "too many arguments"); 47*506f3640SKyle Evans lua_pushinteger(L, getpid()); 48*506f3640SKyle Evans return 1; 49*506f3640SKyle Evans } 50*506f3640SKyle Evans 51*506f3640SKyle Evans #define REG_SIMPLE(n) { #n, lua_ ## n } 52*506f3640SKyle Evans static const struct luaL_Reg unistdlib[] = { 53*506f3640SKyle Evans REG_SIMPLE(getpid), 54*506f3640SKyle Evans { NULL, NULL }, 55*506f3640SKyle Evans }; 56*506f3640SKyle Evans #undef REG_SIMPLE 57*506f3640SKyle Evans 58*506f3640SKyle Evans int 59*506f3640SKyle Evans luaopen_posix_unistd(lua_State *L) 60*506f3640SKyle Evans { 61*506f3640SKyle Evans luaL_newlib(L, unistdlib); 62*506f3640SKyle Evans return 1; 63*506f3640SKyle Evans } 64