From owner-svn-src-head@freebsd.org Tue Feb 20 18:21:31 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 47B50F1C5FF; Tue, 20 Feb 2018 18:21:31 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id DE69784AAC; Tue, 20 Feb 2018 18:21:30 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D97975487; Tue, 20 Feb 2018 18:21:30 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w1KILUIJ079716; Tue, 20 Feb 2018 18:21:30 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w1KILUUg079715; Tue, 20 Feb 2018 18:21:30 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201802201821.w1KILUUg079715@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: Conrad Meyer Date: Tue, 20 Feb 2018 18:21:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r329649 - head/stand/liblua X-SVN-Group: head X-SVN-Commit-Author: cem X-SVN-Commit-Paths: head/stand/liblua X-SVN-Commit-Revision: 329649 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Feb 2018 18:21:31 -0000 Author: cem Date: Tue Feb 20 18:21:30 2018 New Revision: 329649 URL: https://svnweb.freebsd.org/changeset/base/329649 Log: Lua lfs.attributes: Provide a more consistent error return In the remaining error case, return a 3-tuple consistent with the other error return case. Document how to invoke lfs.attributes() and detect/decode error return in example comments. Reviewed by: kevans Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D14451 Modified: head/stand/liblua/lfs.c Modified: head/stand/liblua/lfs.c ============================================================================== --- head/stand/liblua/lfs.c Tue Feb 20 18:12:07 2018 (r329648) +++ head/stand/liblua/lfs.c Tue Feb 20 18:21:30 2018 (r329649) @@ -80,13 +80,20 @@ __FBSDID("$FreeBSD$"); * (etc.) * * The other available API is lfs.attributes(), which functions somewhat like - * stat(2) and returns a table of values: + * stat(2) and returns a table of values. Example code: * - * for k, v in pairs(lfs.attributes("/boot")) do + * attrs, errormsg, errorcode = lfs.attributes("/boot") + * if attrs == nil then + * print(errormsg) + * return errorcode + * end + * + * for k, v in pairs(attrs) do * print(k .. ":\t" .. v) * end + * return 0 * - * Prints: + * Prints (on success): * gid: 0 * change: 140737488342640 * mode: directory @@ -277,7 +284,9 @@ lua_attributes(lua_State *L) path = luaL_checkstring(L, 1); if (path == NULL) { lua_pushnil(L); - return 1; + lua_pushfstring(L, "cannot convert first argument to string"); + lua_pushinteger(L, EINVAL); + return 3; } rc = stat(path, &sb);