mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 11:37:35 +00:00
625aa365f1
The earlier iterations did too much guesswork when it came to things like stderr logging and syscall origin verification. This change will make things more conformant to existing practices. The __pledge_mode extension now can be configured in a better way. There's also a new `-q` flag added to pledge.com, e.g. o//tool/build/pledge.com -qv. ls Is a good way to disable warnings about `tty` access attempts.
79 lines
3.1 KiB
Lua
79 lines
3.1 KiB
Lua
-- Copyright 2022 Justine Alexandra Roberts Tunney
|
|
--
|
|
-- Permission to use, copy, modify, and/or distribute this software for
|
|
-- any purpose with or without fee is hereby granted, provided that the
|
|
-- above copyright notice and this permission notice appear in all copies.
|
|
--
|
|
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
|
-- WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
|
-- WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
|
-- AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
|
-- DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
|
-- PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
-- TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
-- PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
assert(unix.pledge("stdio"))
|
|
|
|
assert("/usr/lib" == path.dirname("/usr/lib/foo.bar"))
|
|
assert("/usr" == path.dirname("/usr/lib"))
|
|
assert("usr" == path.dirname("usr/lib"))
|
|
assert("/" == path.dirname("/usr//"))
|
|
assert("/" == path.dirname("/usr/"))
|
|
assert("." == path.dirname("usr"))
|
|
assert("/" == path.dirname("/"))
|
|
assert("." == path.dirname("."))
|
|
assert("." == path.dirname(".."))
|
|
assert("." == path.dirname(""))
|
|
assert("." == path.dirname(nil))
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
assert("lib" == path.basename("/usr/lib"))
|
|
assert("lib" == path.basename("usr/lib"))
|
|
assert("usr" == path.basename("/usr/"))
|
|
assert("usr" == path.basename("/usr"))
|
|
assert("/" == path.basename("/"))
|
|
assert("." == path.basename("."))
|
|
assert(".." == path.basename(".."))
|
|
assert("." == path.basename(""))
|
|
assert("foo" == path.basename("foo/"))
|
|
assert("foo" == path.basename("foo//"))
|
|
assert("/" == path.basename("///"))
|
|
assert("0" == path.basename(0))
|
|
assert("." == path.basename(nil))
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
assert("a" == path.join("a"))
|
|
assert("a/b/c" == path.join("a", "b", "c"))
|
|
assert("/c" == path.join("a", "b", "/c"))
|
|
assert("/b/c" == path.join("a", "/b", "c"))
|
|
assert("/c" == path.join("a", "/b", "/c"))
|
|
assert("./." == path.join(".", "."))
|
|
assert("./.." == path.join(".", ".."))
|
|
assert("../." == path.join("..", "."))
|
|
assert("./a" == path.join(".", "a"))
|
|
assert("c//c" == path.join("c//", "c"))
|
|
assert("a/." == path.join("a", "."))
|
|
assert("a/b" == path.join("a", "b"))
|
|
assert("a/b" == path.join("a/", "b"))
|
|
assert("a/b/" == path.join("a", "b/"))
|
|
assert("/b" == path.join("a", "/b"))
|
|
assert("./b" == path.join(".", "b"))
|
|
assert("a" * 3000 .."/123/".. "b" * 3000 .. "/123" == path.join("a" * 3000, 123, "b" * 3000, 123))
|
|
assert("1/2/3" == path.join(1, 2, 3))
|
|
assert(nil == path.join(nil))
|
|
assert(nil == path.join(nil, nil))
|
|
assert("a" == path.join("a", nil))
|
|
assert("a" == path.join(nil, "a"))
|
|
assert("a/a" == path.join("a", nil, "a"))
|
|
assert("a/a" == path.join("a/", nil, "a"))
|
|
assert("" == path.join(""))
|
|
assert("" == path.join("", ""))
|
|
assert("b" == path.join("", "b"))
|
|
assert("a" == path.join("", "a"))
|
|
assert("a/" == path.join("a", ""))
|
|
assert("a/b" == path.join("a", "", "b"))
|
|
assert("a/b" == path.join("a", "", "", "b"))
|
|
assert("a/b/" == path.join("a", "", "", "b", ""))
|